-
Notifications
You must be signed in to change notification settings - Fork 0
Timestamp
a special version of a PlainDateTime which offers expire calculations
-
↳
Timestamp
- compare
- createOffset
- createSet
- createTimezoneOffset
- distance
- equals
- expiresIn
- getTime
- isExpired
- isSummerTime
- isToday
- toDate
- toJSON
- toString
- create
- fromList
- in
- listEquals
- now
- prefix
- validate
- validateInterval
- validateList
• Protected new Timestamp(props)
| Name | Type |
|---|---|
props |
Required<PlainDateTimeProps> |
valueObjects/composed/PlainDateTime.ts:79
• Protected Readonly _value: void
the actual value of the ValueObject
• Readonly date: number
valueObjects/composed/PlainDateTime.ts:33
• Readonly hours: number
valueObjects/composed/PlainDateTime.ts:36
• Readonly milliseconds: number
valueObjects/composed/PlainDateTime.ts:39
• Readonly minutes: number
valueObjects/composed/PlainDateTime.ts:37
• Readonly month: number
valueObjects/composed/PlainDateTime.ts:32
• Readonly seconds: number
valueObjects/composed/PlainDateTime.ts:38
• Readonly weekday: number
valueObjects/composed/PlainDateTime.ts:34
• Readonly year: number
valueObjects/composed/PlainDateTime.ts:31
• get dayMinutes(): number
returns the total amount of minutes that have passed on this day
number
PlainDateTime.dayMinutes
valueObjects/composed/PlainDateTime.ts:42
• get value(): T
the actual value of this ValueObject
T
PlainDateTime.value
valueObjects/ValueObject.ts:13
▸ compare(other, density?): 0 | 1 | -1
compares this date with a given other PlainDateTime or 'now' to compare it with the current dateTime.
- returns
-1if this dateTime is earlier than the other one - returns
0if the dates are equal - returns
1if this dateTime is later 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| Name | Type | Default value | Description |
|---|---|---|---|
other |
"now" | PlainDateTime
|
undefined |
the PlainDateTime to compare to / 'now' to use the current dateTime |
density |
PlainDateTimeDensity |
'YMDHMSs' |
the density the comparison has to have |
0 | 1 | -1
-1 | 0 | 1 indicating which dateTime is more recent
valueObjects/composed/PlainDateTime.ts:348
▸ createOffset(offset, options?): Timestamp
creates a new PlainDateTime derived from the existing dateTime, with a given offset
| Name | Type |
|---|---|
offset |
Partial<PlainDateTimeProps> |
options? |
CreationOptions |
valueObjects/composed/Timestamp.ts:59
▸ createSet(newData, options?): Timestamp
creates a new PlainDateTime derived from the existing dateTime, where the given newData
partial replaces the old data.
| Name | Type |
|---|---|
newData |
Partial<PlainDateTimeProps> |
options? |
CreationOptions |
valueObjects/composed/Timestamp.ts:55
▸ createTimezoneOffset(timezone, hasSummertime?, options?): Timestamp
creates a new PlainDateTime derived from the existing dateTime, with a given timezone offset.
The difference from createOffset() is that you only create the hour offset and automatically
have the daylight saving time offset added.
| Name | Type | Default value |
|---|---|---|
timezone |
number |
undefined |
hasSummertime |
boolean |
true |
options? |
CreationOptions |
undefined |
PlainDateTime.createTimezoneOffset
valueObjects/composed/Timestamp.ts:63
▸ distance(toOther, density?): number
compares this date with a given other PlainDateTime or 'now' to compare it with the current dateTime
and returns the distance between both.
- distance = other - this
- positive result = other dateTime was later
- negative result = other dateTime was earlier
- units depending on density:
- "Y" / "YM" / "YMD" = days
- "YMDH" = hours
- "YMDHM" = minutes
- "YMDHMS" = seconds
- "YMDHMSs" = milliseconds (default)
| Name | Type | Default value | Description |
|---|---|---|---|
toOther |
"now" | PlainDateTime
|
undefined |
- |
density |
PlainDateTimeDensity |
'YMDHMSs' |
the density the comparison has to have |
number
the distance in days
valueObjects/composed/PlainDateTime.ts:398
▸ 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 |
PlainDateTimeable | PlainDateTime
|
undefined |
to compare of equality |
density |
PlainDateTimeDensity |
'YMDHMSs' |
- |
boolean
valueObjects/composed/PlainDateTime.ts:310
▸ expiresIn(density?): number
returns the (negative) distance from the timestamp to "now"
| Name | Type |
|---|---|
density? |
PlainDateTimeDensity |
number
valueObjects/composed/Timestamp.ts:22
▸ getTime(): number
returns the time in ms since 1970 similar to Date.getTime()
number
valueObjects/composed/PlainDateTime.ts:47
▸ isExpired(range?): boolean
| Name | Type | Description |
|---|---|---|
range? |
Partial<PlainDateTime> |
to add to the existing Timestamp |
boolean
if the timestamp (incl. range) is expired
valueObjects/composed/Timestamp.ts:17
▸ isSummerTime(): boolean
boolean
valueObjects/composed/PlainDateTime.ts:72
▸ isToday(): boolean
returns true if this date matches with the date of today (without time)
boolean
valueObjects/composed/PlainDateTime.ts:62
▸ toDate(density?, timeZoned?): Date
| Name | Type | Default value |
|---|---|---|
density |
PlainDateTimeDensity |
'YMDHMSs' |
timeZoned |
boolean |
false |
Date
valueObjects/composed/PlainDateTime.ts:442
▸ toJSON(): Object
this function is invoked by JSON.stringify() and converts the inner "_propertyKey" to "propertyKey"
Object
the value
| Name | Type |
|---|---|
date |
number |
hours |
number |
milliseconds |
number |
minutes |
number |
month |
number |
seconds |
number |
weekday |
number |
year |
number |
valueObjects/composed/PlainDateTime.ts:429
▸ toString(): string
string
valueObjects/composed/PlainDateTime.ts:419
▸ Static create(value, options?): Timestamp
can be either PlainDateTimeProps:
{
year: number;
month?: number;
date?: number;
hours?: number;
minutes?: number;
seconds?: number;
milliseconds?: number;
}or YMDHMSs_Array:
[
year: number,
month?: number,
date?: number,
hours?: number,
minutes?: number,
seconds?: number,
milliseconds?: number
]or a string representation:
"DD.MM.YYYY""YYYY-MM-DD""DD.MM.YYYYTHH:MM:SS.sss+hh:mm"- JS dateString (RFC2822 || ISO8601)
| Name | Type | Description |
|---|---|---|
value |
PlainDateTimeable |
to create the ValueObject of |
options? |
CreationOptions |
constraints the value has to fulfill |
the created ValueObject
valueObjects/composed/Timestamp.ts:40
▸ Static fromList(values, options?): Timestamp[]
| Name | Type | Description |
|---|---|---|
values |
undefined | PlainDateTimeable[] |
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/Timestamp.ts:44
▸ Static in(offset, options?): Timestamp
creates a timestamp with an offset to "now" e.g. 1h in the future:
const soon = Timestamp.in({hours: 1});
soon.expiresIn('YMDH'); // 1
soon.isExpired(); // false| Name | Type |
|---|---|
offset |
Partial<PlainDateTimeProps> |
options? |
CreationOptions |
valueObjects/composed/Timestamp.ts:34
▸ 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?): Timestamp
creates a PlainDateTime from the current dateTime. Similar to new Date()
| Name | Type |
|---|---|
options? |
CreationOptions & PlainDateTimeNowOptions
|
valueObjects/composed/Timestamp.ts:51
▸ 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<PlainDateTimeProps>
Throws
various errors if not correct
| Name | Type | Description |
|---|---|---|
value |
PlainDateTimeable |
to be validated as a valid dateTime with the corresponding constraints (options) |
options? |
Omit<CreationOptions, "offset"> |
constraints the value has to fulfill |
Required<PlainDateTimeProps>
the value if the validation was successful
valueObjects/composed/PlainDateTime.ts:234
▸ Static Protected validateInterval(value, options): void
| Name | Type |
|---|---|
value |
string | number
|
options |
IntervalCreationOptions |
void
PlainDateTime.validateInterval
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[]