-
Notifications
You must be signed in to change notification settings - Fork 0
PlainDate
This is a more simplified, but also flexible version of a Date
which specifically represents
just the date (without the time).
Related to PlainTime
for the time and PlaneDateTime
for a combination of both.
-
ValueObject
<void
>↳
PlainDate
- compare
- createOffset
- createSet
- distance
- equals
- toDate
- toJSON
- toString
- create
- fromList
- listEquals
- now
- parseString
- prefix
- validate
- validateInterval
- validateList
- validatePlainDateable
• Private
new PlainDate(props
)
Name | Type |
---|---|
props |
Required <PlainDateProps > |
valueObjects/composed/PlainDate.ts:24
• Protected
Readonly
_value: void
the actual value of the ValueObject
• Readonly
date: number
valueObjects/composed/PlainDate.ts:21
• Readonly
month: number
valueObjects/composed/PlainDate.ts:20
• Readonly
weekday: number
valueObjects/composed/PlainDate.ts:22
• Readonly
year: number
valueObjects/composed/PlainDate.ts:19
• get
value(): T
the actual value of this ValueObject
T
ValueObject.value
valueObjects/ValueObject.ts:13
▸ compare(other
, density?
): 0
| 1
| -1
compares this date with a given other PlainDate
or 'now'
to compare it with the current date.
- returns
-1
if this date is older than the other one - returns
0
if the dates are equal - returns
1
if this date is more recent than the other one
'2020-05-25'.compare('2020-09-18') => -1
'2020-05-25'.compare('2020-01-01') => 1
'2020-05-25'.compare('2020-05-06', 'YM') => 0 (with density)
Name | Type | Default value | Description |
---|---|---|---|
other |
PlainDate | "now"
|
undefined |
the PlainDate to compare to / 'now' to use the current date |
density |
PlainDateDensity |
'YMD' |
the density the comparison has to have |
0
| 1
| -1
-1 | 0 | 1
indicating which date is more recent
valueObjects/composed/PlainDate.ts:248
▸ createOffset(offset
, options?
): PlainDate
creates a new PlainDate
derived from the existing date, with a given offset
Name | Type |
---|---|
offset |
Partial <PlainDateProps > |
options? |
CreationOptions |
valueObjects/composed/PlainDate.ts:110
▸ createSet(newData
, options?
): PlainDate
creates a new PlainDate
derived from the existing date, where the given newData
partial replaces the old data.
Name | Type |
---|---|
newData |
Partial <PlainDateProps > |
options? |
CreationOptions |
valueObjects/composed/PlainDate.ts:98
▸ distance(toOther
, density?
): number
compares this date with a given other PlainDate
or 'now'
to compare it with the current date
and returns the distance between both.
- distance = other - this
- positive result = other date was later
- negative result = other date was earlier
- always returns the distance in days (independent from the density)
Name | Type | Default value | Description |
---|---|---|---|
toOther |
PlainDate | "now"
|
undefined |
- |
density |
PlainDateDensity |
'YMD' |
the density the comparison has to have |
number
the distance in days
valueObjects/composed/PlainDate.ts:274
▸ equals(obj
, density?
): boolean
compares if the given value is either an equal ValueObject, or an equal value which would create an equal ValueObject
Name | Type | Default value | Description |
---|---|---|---|
obj |
PlainDateable | PlainDate
|
undefined |
to compare of equality |
density |
PlainDateDensity |
'YMD' |
- |
boolean
valueObjects/composed/PlainDate.ts:217
▸ toDate(density?
): Date
Name | Type | Default value |
---|---|---|
density |
PlainDateDensity |
'YMD' |
Date
valueObjects/composed/PlainDate.ts:296
▸ toJSON(): Object
this function is invoked by JSON.stringify()
and converts the inner "_propertyKey"
to "propertyKey"
Object
the value
Name | Type |
---|---|
date |
number |
month |
number |
weekday |
number |
year |
number |
valueObjects/composed/PlainDate.ts:287
▸ toString(): string
string
valueObjects/composed/PlainDate.ts:283
▸ Static
create(value
, options?
): PlainDate
can be either PlainDateProps
:
{
year: number;
month?: number;
date?: number;
}
or YMD_Array
:
[year: number, month?: number, date?: number]
or a string
representation:
"DD.MM.YYYY"
"DD.M.YYYY"
"D.MM.YYYY"
"D.M.YYYY"
"YYYY-MM-DD"
"YYYY-MM-D"
"YYYY-M-DD"
"YYYY-M-D"
Name | Type | Description |
---|---|---|
value |
PlainDateable |
to create the ValueObject of |
options? |
CreationOptions |
constraints the value has to fulfill |
the created ValueObject
valueObjects/composed/PlainDate.ts:64
▸ Static
fromList(values
, options?
): PlainDate
[]
Name | Type | Description |
---|---|---|
values |
undefined | PlainDateable [] |
an array of primitives to map to an array of ValueObjects |
options? |
CreationOptions & ListCreationOptions
|
constraints the values / list has to fulfill |
the array of ValueObjects
valueObjects/composed/PlainDate.ts:73
▸ Static
listEquals<ValueType
>(a
, b
): boolean
compares 2 Lists of ValueObjects / values on equality
Name |
---|
ValueType |
Name | Type | Description |
---|---|---|
a |
ValueObject <ValueType >[] |
the list of ValueObjects to compare with |
b |
ValueObject <ValueType >[] | ValueType [] |
a list of ValueObjects / values for comparison |
boolean
true if the lists are equal
valueObjects/ValueObject.ts:29
▸ Static
now(options?
): PlainDate
creates a PlainDate
from the current date. Similar to new Date()
Name | Type |
---|---|
options? |
CreationOptions & PlainDateNowOptions
|
valueObjects/composed/PlainDate.ts:81
▸ Static
Private
parseString(value
, options?
): PlainDateProps
| YMD_Array
Name | Type |
---|---|
value |
PlainDateable |
options? |
CreationOptions |
PlainDateProps
| YMD_Array
valueObjects/composed/PlainDate.ts:192
▸ Static
Protected
prefix(options
, addition?
): string
constructs a prefix for possible error messages based on the ValueObjects name and an additional string:
- example for NonEmptyString with
name='Person'
:
"Person > NonEmptyString"
Name | Type | Default value | Description |
---|---|---|---|
options |
undefined | CreationOptions
|
undefined |
the CreationOptions where the optional name: string is taken from |
addition |
string |
'' |
An additional name which will be added as "name.addition"
|
string
the name of the ValueObject
valueObjects/ValueObject.ts:77
▸ Static
validate(value
, options?
): Required
<PlainDateProps
>
Throws
various errors if not correct
Name | Type | Description |
---|---|---|
value |
PlainDateable |
to be validated as a valid date with the corresponding constraints (options) |
options? |
CreationOptions |
constraints the value has to fulfill |
Required
<PlainDateProps
>
the value if the validation was successful
valueObjects/composed/PlainDate.ts:137
▸ Static
Protected
validateInterval(value
, options
): void
Name | Type |
---|---|
value |
string | number
|
options |
IntervalCreationOptions |
void
valueObjects/ValueObject.ts:86
▸ Static
Protected
validateList<Primitive
>(list
, options?
): list is Primitive[]
Name |
---|
Primitive |
Name | Type |
---|---|
list |
undefined | Primitive [] |
options? |
CreationOptions & ListCreationOptions
|
list is Primitive[]
valueObjects/ValueObject.ts:101
▸ Static
validatePlainDateable(value
, options?
): PlainDateable
Name | Type | Description |
---|---|---|
value |
PlainDateable |
to be validated as a string, array or object representation of a date |
options? |
CreationOptions |
constraints the value has to fulfill |
the valid date