-
Notifications
You must be signed in to change notification settings - Fork 0
PlainTime
This is a more simplified, but also flexible version of a Date which specifically represents just the time.
Related to PlainDate for dates and PlaneDateTime for a combination of both.
-
ValueObject<void>↳
PlainTime
- compare
- createOffset
- createSet
- distance
- equals
- getTime
- toJSON
- toString
- create
- fromList
- listEquals
- now
- parseString
- prefix
- validate
- validateInterval
- validateList
- validatePlainTimeable
• Private new PlainTime(props)
| Name | Type |
|---|---|
props |
Required<PlainTimeProps> |
valueObjects/composed/PlainTime.ts:34
• Protected Readonly _value: void
the actual value of the ValueObject
• Readonly hours: number
valueObjects/composed/PlainTime.ts:19
• Readonly milliseconds: number
valueObjects/composed/PlainTime.ts:22
• Readonly minutes: number
valueObjects/composed/PlainTime.ts:20
• Readonly seconds: number
valueObjects/composed/PlainTime.ts:21
• get value(): T
the actual value of this ValueObject
T
ValueObject.value
valueObjects/ValueObject.ts:13
▸ compare(other, density?): 0 | 1 | -1
compares this time with a given other PlainTime or 'now' to compare it with the current time.
- returns
-1if this time is earlier than the other one - returns
0if the times are equal - returns
1if this time is sooner than the other one
'05:24:57'.compare('08:15:30') => -1
'05:24:57'.compare('01:00:00') => 1
'05:24:57'.compare('05:00:01', 'H') => 0 (with density)| Name | Type | Default value | Description |
|---|---|---|---|
other |
"now" | PlainTime
|
undefined |
the PlainTime to compare to / 'now' to use the current time |
density |
PlainTimeDensity |
'HMSs' |
the density the comparison has to have |
0 | 1 | -1
-1 | 0 | 1 indicating which time is more recent
valueObjects/composed/PlainTime.ts:277
▸ createOffset(offset, options?): PlainTime
creates a new PlainTime derived from the existing time, with a given offset
| Name | Type |
|---|---|
offset |
Partial<PlainTimeProps> |
options? |
CreationOptions |
valueObjects/composed/PlainTime.ts:119
▸ createSet(newData, options?): PlainTime
creates a new PlainTime derived from the existing time, where the given newData
partial replaces the old data.
| Name | Type |
|---|---|
newData |
Partial<PlainTimeProps> |
options? |
CreationOptions |
valueObjects/composed/PlainTime.ts:106
▸ distance(toOther, density?): number
compares this time with a given other PlainTime or 'now' to compare it with the current time
and returns the distance between both.
- distance = other - this
- positive result = other time was later
- negative result = other time was earlier
- units depending on density:
- "H" = hours
- "HM" = minutes
- "HMS" = seconds
- "HMSs" = milliseconds (default)
| Name | Type | Default value | Description |
|---|---|---|---|
toOther |
"now" | PlainTime
|
undefined |
- |
density |
PlainTimeDensity |
'HMSs' |
the density the comparison has to have |
number
the distance whereas the unit correlates to the given density (defaults to ms)
valueObjects/composed/PlainTime.ts:313
▸ 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 |
PlainTimeable | PlainTime
|
undefined |
to compare of equality |
density |
PlainTimeDensity |
'HMSs' |
- |
boolean
valueObjects/composed/PlainTime.ts:245
▸ getTime(density): number
returns the time in ms since 1970 similar to Date.getTime()
| Name | Type |
|---|---|
density |
PlainTimeDensity |
number
valueObjects/composed/PlainTime.ts:25
▸ toJSON(): Object
this function is invoked by JSON.stringify() and converts the inner "_propertyKey" to "propertyKey"
Object
the value
| Name | Type |
|---|---|
hours |
number |
milliseconds |
number |
minutes |
number |
seconds |
number |
valueObjects/composed/PlainTime.ts:334
▸ toString(): string
string
valueObjects/composed/PlainTime.ts:330
▸ Static create(value, options?): PlainTime
can be either PlainTimeProps:
{
hours?: number;
minutes?: number;
seconds?: number;
milliseconds?: number;
}or HMSs_Array:
[hours?: number, minutes?: number, seconds?: number, milliseconds?: number]or a string representation:
"HH""HH:MM""HH:MM:SS"-
"HH:MM:SS.sss+hh:mm"(with offset)
| Name | Type | Description |
|---|---|---|
value |
PlainTimeable |
to create the ValueObject of |
options? |
CreationOptions |
constraints the value has to fulfill |
the created ValueObject
valueObjects/composed/PlainTime.ts:71
▸ Static fromList(values, options?): PlainTime[]
| Name | Type | Description |
|---|---|---|
values |
undefined | PlainTimeable[] |
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/PlainTime.ts:80
▸ 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?): PlainTime
creates a PlainTime from the current time. Similar to new Date()
| Name | Type |
|---|---|
options? |
CreationOptions & PlainTimeNowOptions
|
valueObjects/composed/PlainTime.ts:88
▸ Static Private parseString(value, options?): PlainTimeProps | HMSs_Array
| Name | Type |
|---|---|
value |
PlainTimeable |
options? |
CreationOptions |
PlainTimeProps | HMSs_Array
valueObjects/composed/PlainTime.ts:198
▸ 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<PlainTimeProps>
Throws
various errors if not correct
| Name | Type | Description |
|---|---|---|
value |
PlainTimeable |
to be validated as a valid time with the corresponding constraints (options) |
options? |
CreationOptions |
constraints the value has to fulfill |
Required<PlainTimeProps>
the value if the validation was successful
valueObjects/composed/PlainTime.ts:151
▸ 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 validatePlainTimeable(value, options): PlainTimeable
| Name | Type | Description |
|---|---|---|
value |
PlainTimeable |
to be validated as a string, array or object representation of time |
options |
undefined | CreationOptions
|
constraints the value has to fulfill |
PlainTimeable
the valid time