@bgord/tools 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/age.vo.d.ts +1 -1
- package/dist/age.vo.js +1 -1
- package/dist/clock.vo.d.ts +1 -1
- package/dist/clock.vo.js +3 -3
- package/dist/day.vo.d.ts +2 -0
- package/dist/day.vo.js +3 -0
- package/dist/hour.vo.d.ts +4 -2
- package/dist/hour.vo.js +5 -1
- package/dist/minute.vo.d.ts +4 -2
- package/dist/minute.vo.js +5 -1
- package/dist/month.vo.d.ts +2 -0
- package/dist/month.vo.js +3 -0
- package/dist/quarter.vo.d.ts +2 -0
- package/dist/quarter.vo.js +3 -0
- package/dist/week.vo.d.ts +2 -0
- package/dist/week.vo.js +3 -0
- package/dist/weekday.vo.d.ts +4 -2
- package/dist/weekday.vo.js +5 -1
- package/dist/year.vo.d.ts +2 -0
- package/dist/year.vo.js +3 -0
- package/package.json +2 -2
- package/src/age.vo.ts +1 -1
- package/src/clock.vo.ts +3 -3
- package/src/day.vo.ts +5 -0
- package/src/hour.vo.ts +7 -2
- package/src/minute.vo.ts +7 -2
- package/src/month.vo.ts +5 -0
- package/src/quarter.vo.ts +5 -0
- package/src/week.vo.ts +5 -0
- package/src/weekday.vo.ts +7 -2
- package/src/year.vo.ts +5 -0
package/dist/age.vo.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class Age {
|
|
|
8
8
|
static readonly MAX: number;
|
|
9
9
|
private constructor();
|
|
10
10
|
static fromValue(candidate: number): Age;
|
|
11
|
-
static
|
|
11
|
+
static fromBirthdateTimestamp(params: {
|
|
12
12
|
birthdate: TimestampVO;
|
|
13
13
|
now: TimestampVO;
|
|
14
14
|
}): Age;
|
package/dist/age.vo.js
CHANGED
|
@@ -12,7 +12,7 @@ export class Age {
|
|
|
12
12
|
static fromValue(candidate) {
|
|
13
13
|
return new Age(AgeYears.parse(candidate));
|
|
14
14
|
}
|
|
15
|
-
static
|
|
15
|
+
static fromBirthdateTimestamp(params) {
|
|
16
16
|
if (params.birthdate.isAfter(params.now))
|
|
17
17
|
throw new Error(AgeError.FutureBirthdate);
|
|
18
18
|
return Age.fromValue(differenceInYears(params.now.ms, params.birthdate.ms));
|
package/dist/clock.vo.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class Clock {
|
|
|
9
9
|
private readonly minute;
|
|
10
10
|
private readonly formatter;
|
|
11
11
|
constructor(hour: Hour, minute: Minute, formatter?: ClockFormatter);
|
|
12
|
-
static
|
|
12
|
+
static fromTimestamp(timestamp: TimestampVO, formatter?: ClockFormatter): Clock;
|
|
13
13
|
get(): {
|
|
14
14
|
hour: HourSchemaType;
|
|
15
15
|
minute: MinuteSchemaType;
|
package/dist/clock.vo.js
CHANGED
|
@@ -10,9 +10,9 @@ export class Clock {
|
|
|
10
10
|
this.minute = minute;
|
|
11
11
|
this.formatter = formatter ?? ClockFormatters.TWENTY_FOUR_HOURS;
|
|
12
12
|
}
|
|
13
|
-
static
|
|
14
|
-
const hour = Hour.
|
|
15
|
-
const minute = Minute.
|
|
13
|
+
static fromTimestamp(timestamp, formatter) {
|
|
14
|
+
const hour = Hour.fromTimestamp(timestamp);
|
|
15
|
+
const minute = Minute.fromTimestamp(timestamp);
|
|
16
16
|
return new Clock(hour, minute, formatter);
|
|
17
17
|
}
|
|
18
18
|
get() {
|
package/dist/day.vo.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DateRange } from "./date-range.vo";
|
|
2
2
|
import { type DayIsoIdType } from "./day-iso-id.vo";
|
|
3
3
|
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
export declare class Day extends DateRange {
|
|
5
6
|
static fromTimestamp(timestamp: TimestampVO): Day;
|
|
7
|
+
static fromTimestampValue(timestamp: TimestampValueType): Day;
|
|
6
8
|
static fromNow(now: TimestampVO): Day;
|
|
7
9
|
static fromIsoId(isoId: DayIsoIdType): Day;
|
|
8
10
|
toIsoId(): DayIsoIdType;
|
package/dist/day.vo.js
CHANGED
|
@@ -10,6 +10,9 @@ export class Day extends DateRange {
|
|
|
10
10
|
const endUtc = startUtc.add(Duration.Days(1)).subtract(Duration.Ms(1));
|
|
11
11
|
return new Day(startUtc, endUtc);
|
|
12
12
|
}
|
|
13
|
+
static fromTimestampValue(timestamp) {
|
|
14
|
+
return Day.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
15
|
+
}
|
|
13
16
|
static fromNow(now) {
|
|
14
17
|
return Day.fromTimestamp(now);
|
|
15
18
|
}
|
package/dist/hour.vo.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type HourFormatter } from "./hour-format.service";
|
|
2
2
|
import { type HourSchemaType } from "./hour-schema.vo";
|
|
3
|
-
import
|
|
3
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
export declare class Hour {
|
|
5
6
|
private readonly value;
|
|
6
7
|
static readonly ZERO: Hour;
|
|
7
8
|
static readonly MAX: Hour;
|
|
8
9
|
constructor(candidate: number);
|
|
9
|
-
static
|
|
10
|
+
static fromTimestamp(timestamp: TimestampVO): Hour;
|
|
11
|
+
static fromTimestampValue(timestamp: TimestampValueType): Hour;
|
|
10
12
|
get(): HourSchemaType;
|
|
11
13
|
format(formatter: HourFormatter): string;
|
|
12
14
|
equals(another: Hour): boolean;
|
package/dist/hour.vo.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HourFormatters } from "./hour-format.service";
|
|
2
2
|
import { HourSchema } from "./hour-schema.vo";
|
|
3
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
3
4
|
export class Hour {
|
|
4
5
|
value;
|
|
5
6
|
static ZERO = new Hour(0);
|
|
@@ -7,9 +8,12 @@ export class Hour {
|
|
|
7
8
|
constructor(candidate) {
|
|
8
9
|
this.value = HourSchema.parse(candidate);
|
|
9
10
|
}
|
|
10
|
-
static
|
|
11
|
+
static fromTimestamp(timestamp) {
|
|
11
12
|
return new Hour(new Date(timestamp.ms).getUTCHours());
|
|
12
13
|
}
|
|
14
|
+
static fromTimestampValue(timestamp) {
|
|
15
|
+
return Hour.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
16
|
+
}
|
|
13
17
|
get() {
|
|
14
18
|
return this.value;
|
|
15
19
|
}
|
package/dist/minute.vo.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type MinuteSchemaType } from "./minute-schema.vo";
|
|
2
|
-
import
|
|
2
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
3
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
3
4
|
export declare class Minute {
|
|
4
5
|
private readonly value;
|
|
5
6
|
static readonly ZERO: Minute;
|
|
6
7
|
static readonly MAX: Minute;
|
|
7
8
|
constructor(candidate: number);
|
|
8
|
-
static
|
|
9
|
+
static fromTimestamp(timestamp: TimestampVO): Minute;
|
|
10
|
+
static fromTimestampValue(timestamp: TimestampValueType): Minute;
|
|
9
11
|
get(): MinuteSchemaType;
|
|
10
12
|
equals(another: Minute): boolean;
|
|
11
13
|
isAfter(another: Minute): boolean;
|
package/dist/minute.vo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MinuteSchema } from "./minute-schema.vo";
|
|
2
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
2
3
|
export class Minute {
|
|
3
4
|
value;
|
|
4
5
|
static ZERO = new Minute(0);
|
|
@@ -6,9 +7,12 @@ export class Minute {
|
|
|
6
7
|
constructor(candidate) {
|
|
7
8
|
this.value = MinuteSchema.parse(candidate);
|
|
8
9
|
}
|
|
9
|
-
static
|
|
10
|
+
static fromTimestamp(timestamp) {
|
|
10
11
|
return new Minute(new Date(timestamp.ms).getUTCMinutes());
|
|
11
12
|
}
|
|
13
|
+
static fromTimestampValue(timestamp) {
|
|
14
|
+
return Minute.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
15
|
+
}
|
|
12
16
|
get() {
|
|
13
17
|
return this.value;
|
|
14
18
|
}
|
package/dist/month.vo.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DateRange } from "./date-range.vo";
|
|
2
2
|
import { type MonthIsoIdType } from "./month-iso-id.vo";
|
|
3
3
|
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
export declare class Month extends DateRange {
|
|
5
6
|
static fromTimestamp(timestamp: TimestampVO): Month;
|
|
7
|
+
static fromTimestampValue(timestamp: TimestampValueType): Month;
|
|
6
8
|
static fromNow(now: TimestampVO): Month;
|
|
7
9
|
static fromIsoId(iso: MonthIsoIdType): Month;
|
|
8
10
|
toIsoId(): MonthIsoIdType;
|
package/dist/month.vo.js
CHANGED
|
@@ -8,6 +8,9 @@ export class Month extends DateRange {
|
|
|
8
8
|
const end = TimestampVO.fromNumber(endOfMonth(timestamp.ms).getTime());
|
|
9
9
|
return new Month(start, end);
|
|
10
10
|
}
|
|
11
|
+
static fromTimestampValue(timestamp) {
|
|
12
|
+
return Month.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
13
|
+
}
|
|
11
14
|
static fromNow(now) {
|
|
12
15
|
return Month.fromTimestamp(now);
|
|
13
16
|
}
|
package/dist/quarter.vo.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DateRange } from "./date-range.vo";
|
|
2
2
|
import { type QuarterIsoIdType } from "./quarter-iso-id.vo";
|
|
3
3
|
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
export declare class Quarter extends DateRange {
|
|
5
6
|
static fromTimestamp(timestamp: TimestampVO): Quarter;
|
|
7
|
+
static fromTimestampValue(timestamp: TimestampValueType): Quarter;
|
|
6
8
|
static fromNow(now: TimestampVO): Quarter;
|
|
7
9
|
static fromIsoId(isoId: QuarterIsoIdType): Quarter;
|
|
8
10
|
toIsoId(): QuarterIsoIdType;
|
package/dist/quarter.vo.js
CHANGED
|
@@ -8,6 +8,9 @@ export class Quarter extends DateRange {
|
|
|
8
8
|
const end = TimestampVO.fromNumber(endOfQuarter(timestamp.ms).getTime());
|
|
9
9
|
return new Quarter(start, end);
|
|
10
10
|
}
|
|
11
|
+
static fromTimestampValue(timestamp) {
|
|
12
|
+
return Quarter.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
13
|
+
}
|
|
11
14
|
static fromNow(now) {
|
|
12
15
|
return Quarter.fromTimestamp(now);
|
|
13
16
|
}
|
package/dist/week.vo.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DateRange } from "./date-range.vo";
|
|
2
2
|
import { TimestampVO } from "./timestamp.vo";
|
|
3
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
3
4
|
import { type WeekIsoIdType } from "./week-iso-id.vo";
|
|
4
5
|
export declare class Week extends DateRange {
|
|
5
6
|
static fromTimestamp(timestamp: TimestampVO): Week;
|
|
7
|
+
static fromTimestampValue(timestamp: TimestampValueType): Week;
|
|
6
8
|
static fromNow(now: TimestampVO): Week;
|
|
7
9
|
static fromIsoId(isoId: WeekIsoIdType): Week;
|
|
8
10
|
toIsoId(): WeekIsoIdType;
|
package/dist/week.vo.js
CHANGED
|
@@ -8,6 +8,9 @@ export class Week extends DateRange {
|
|
|
8
8
|
const end = TimestampVO.fromNumber(endOfISOWeek(timestamp.ms).getTime());
|
|
9
9
|
return new Week(start, end);
|
|
10
10
|
}
|
|
11
|
+
static fromTimestampValue(timestamp) {
|
|
12
|
+
return Week.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
13
|
+
}
|
|
11
14
|
static fromNow(now) {
|
|
12
15
|
return Week.fromTimestamp(now);
|
|
13
16
|
}
|
package/dist/weekday.vo.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
2
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
2
3
|
export type WeekdayFormatter = (value: Weekday["value"]) => string;
|
|
3
4
|
export declare enum WeekdayFormatterEnum {
|
|
4
5
|
FULL = "FULL",// "Sunday"
|
|
@@ -19,7 +20,8 @@ export declare class Weekday {
|
|
|
19
20
|
static readonly FRIDAY: Weekday;
|
|
20
21
|
static readonly SATURDAY: Weekday;
|
|
21
22
|
constructor(candidate: number, formatter?: WeekdayFormatter);
|
|
22
|
-
static
|
|
23
|
+
static fromTimestamp(timestamp: TimestampVO, formatter?: WeekdayFormatter): Weekday;
|
|
24
|
+
static fromTimestampValue(timestamp: TimestampValueType): Weekday;
|
|
23
25
|
get(): number;
|
|
24
26
|
format(): string;
|
|
25
27
|
toString(): string;
|
package/dist/weekday.vo.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
1
2
|
export var WeekdayFormatterEnum;
|
|
2
3
|
(function (WeekdayFormatterEnum) {
|
|
3
4
|
WeekdayFormatterEnum["FULL"] = "FULL";
|
|
@@ -40,10 +41,13 @@ export class Weekday {
|
|
|
40
41
|
this.value = candidate;
|
|
41
42
|
this.formatter = formatter ?? WeekdayFormatters.FULL;
|
|
42
43
|
}
|
|
43
|
-
static
|
|
44
|
+
static fromTimestamp(timestamp, formatter) {
|
|
44
45
|
const dayZeroBased = new Date(timestamp.ms).getUTCDay(); // 0..6
|
|
45
46
|
return new Weekday(dayZeroBased, formatter);
|
|
46
47
|
}
|
|
48
|
+
static fromTimestampValue(timestamp) {
|
|
49
|
+
return Weekday.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
50
|
+
}
|
|
47
51
|
get() {
|
|
48
52
|
return this.value;
|
|
49
53
|
}
|
package/dist/year.vo.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DateRange } from "./date-range.vo";
|
|
2
2
|
import { TimestampVO } from "./timestamp.vo";
|
|
3
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
3
4
|
import { type YearIsoIdType } from "./year-iso-id.vo";
|
|
4
5
|
export declare class Year extends DateRange {
|
|
5
6
|
static fromTimestamp(timestamp: TimestampVO): Year;
|
|
7
|
+
static fromTimestampValue(timestamp: TimestampValueType): Year;
|
|
6
8
|
static fromNow(now: TimestampVO): Year;
|
|
7
9
|
static fromNumber(candidate: number): Year;
|
|
8
10
|
static fromIsoId(isoId: YearIsoIdType): Year;
|
package/dist/year.vo.js
CHANGED
|
@@ -8,6 +8,9 @@ export class Year extends DateRange {
|
|
|
8
8
|
const end = TimestampVO.fromNumber(endOfYear(timestamp.ms).getTime());
|
|
9
9
|
return new Year(start, end);
|
|
10
10
|
}
|
|
11
|
+
static fromTimestampValue(timestamp) {
|
|
12
|
+
return Year.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
13
|
+
}
|
|
11
14
|
static fromNow(now) {
|
|
12
15
|
return Year.fromTimestamp(now);
|
|
13
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/tools",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@types/bun": "1.3.1",
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
29
|
"cspell": "9.2.2",
|
|
30
|
-
"knip": "5.
|
|
30
|
+
"knip": "5.67.0",
|
|
31
31
|
"lefthook": "2.0.2",
|
|
32
32
|
"only-allow": "1.2.1",
|
|
33
33
|
"shellcheck": "4.1.0",
|
package/src/age.vo.ts
CHANGED
|
@@ -14,7 +14,7 @@ export class Age {
|
|
|
14
14
|
return new Age(AgeYears.parse(candidate));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
static
|
|
17
|
+
static fromBirthdateTimestamp(params: { birthdate: TimestampVO; now: TimestampVO }): Age {
|
|
18
18
|
if (params.birthdate.isAfter(params.now)) throw new Error(AgeError.FutureBirthdate);
|
|
19
19
|
return Age.fromValue(differenceInYears(params.now.ms, params.birthdate.ms));
|
|
20
20
|
}
|
package/src/clock.vo.ts
CHANGED
|
@@ -16,9 +16,9 @@ export class Clock {
|
|
|
16
16
|
this.formatter = formatter ?? ClockFormatters.TWENTY_FOUR_HOURS;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
static
|
|
20
|
-
const hour = Hour.
|
|
21
|
-
const minute = Minute.
|
|
19
|
+
static fromTimestamp(timestamp: TimestampVO, formatter?: ClockFormatter): Clock {
|
|
20
|
+
const hour = Hour.fromTimestamp(timestamp);
|
|
21
|
+
const minute = Minute.fromTimestamp(timestamp);
|
|
22
22
|
|
|
23
23
|
return new Clock(hour, minute, formatter);
|
|
24
24
|
}
|
package/src/day.vo.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DateRange } from "./date-range.vo";
|
|
|
3
3
|
import { DayIsoId, type DayIsoIdType } from "./day-iso-id.vo";
|
|
4
4
|
import { Duration } from "./duration.service";
|
|
5
5
|
import { TimestampVO } from "./timestamp.vo";
|
|
6
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
6
7
|
|
|
7
8
|
export class Day extends DateRange {
|
|
8
9
|
static fromTimestamp(timestamp: TimestampVO): Day {
|
|
@@ -16,6 +17,10 @@ export class Day extends DateRange {
|
|
|
16
17
|
return new Day(startUtc, endUtc);
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
static fromTimestampValue(timestamp: TimestampValueType): Day {
|
|
21
|
+
return Day.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
static fromNow(now: TimestampVO): Day {
|
|
20
25
|
return Day.fromTimestamp(now);
|
|
21
26
|
}
|
package/src/hour.vo.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type HourFormatter, HourFormatters } from "./hour-format.service";
|
|
2
2
|
import { HourSchema, type HourSchemaType } from "./hour-schema.vo";
|
|
3
|
-
import
|
|
3
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
|
|
5
6
|
export class Hour {
|
|
6
7
|
private readonly value: HourSchemaType;
|
|
@@ -12,10 +13,14 @@ export class Hour {
|
|
|
12
13
|
this.value = HourSchema.parse(candidate);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
static
|
|
16
|
+
static fromTimestamp(timestamp: TimestampVO): Hour {
|
|
16
17
|
return new Hour(new Date(timestamp.ms).getUTCHours());
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
static fromTimestampValue(timestamp: TimestampValueType): Hour {
|
|
21
|
+
return Hour.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
get(): HourSchemaType {
|
|
20
25
|
return this.value;
|
|
21
26
|
}
|
package/src/minute.vo.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MinuteSchema, type MinuteSchemaType } from "./minute-schema.vo";
|
|
2
|
-
import
|
|
2
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
3
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
3
4
|
|
|
4
5
|
export class Minute {
|
|
5
6
|
private readonly value: MinuteSchemaType;
|
|
@@ -11,10 +12,14 @@ export class Minute {
|
|
|
11
12
|
this.value = MinuteSchema.parse(candidate);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
static
|
|
15
|
+
static fromTimestamp(timestamp: TimestampVO): Minute {
|
|
15
16
|
return new Minute(new Date(timestamp.ms).getUTCMinutes());
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
static fromTimestampValue(timestamp: TimestampValueType): Minute {
|
|
20
|
+
return Minute.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
get(): MinuteSchemaType {
|
|
19
24
|
return this.value;
|
|
20
25
|
}
|
package/src/month.vo.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { endOfMonth, format, getMonth, setMonth, startOfMonth } from "date-fns";
|
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { MonthIsoId, type MonthIsoIdType } from "./month-iso-id.vo";
|
|
4
4
|
import { TimestampVO } from "./timestamp.vo";
|
|
5
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
5
6
|
|
|
6
7
|
export class Month extends DateRange {
|
|
7
8
|
static fromTimestamp(timestamp: TimestampVO): Month {
|
|
@@ -11,6 +12,10 @@ export class Month extends DateRange {
|
|
|
11
12
|
return new Month(start, end);
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
static fromTimestampValue(timestamp: TimestampValueType): Month {
|
|
16
|
+
return Month.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
static fromNow(now: TimestampVO): Month {
|
|
15
20
|
return Month.fromTimestamp(now);
|
|
16
21
|
}
|
package/src/quarter.vo.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { endOfQuarter, getQuarter, getYear, setQuarter, startOfQuarter } from "d
|
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { QuarterIsoId, type QuarterIsoIdType } from "./quarter-iso-id.vo";
|
|
4
4
|
import { TimestampVO } from "./timestamp.vo";
|
|
5
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
5
6
|
|
|
6
7
|
export class Quarter extends DateRange {
|
|
7
8
|
static fromTimestamp(timestamp: TimestampVO): Quarter {
|
|
@@ -11,6 +12,10 @@ export class Quarter extends DateRange {
|
|
|
11
12
|
return new Quarter(start, end);
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
static fromTimestampValue(timestamp: TimestampValueType): Quarter {
|
|
16
|
+
return Quarter.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
static fromNow(now: TimestampVO): Quarter {
|
|
15
20
|
return Quarter.fromTimestamp(now);
|
|
16
21
|
}
|
package/src/week.vo.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addWeeks, endOfISOWeek, getISOWeek, getISOWeekYear, setISOWeek, startOfISOWeek } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
import { WeekIsoId, type WeekIsoIdType } from "./week-iso-id.vo";
|
|
5
6
|
|
|
6
7
|
export class Week extends DateRange {
|
|
@@ -11,6 +12,10 @@ export class Week extends DateRange {
|
|
|
11
12
|
return new Week(start, end);
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
static fromTimestampValue(timestamp: TimestampValueType): Week {
|
|
16
|
+
return Week.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
static fromNow(now: TimestampVO): Week {
|
|
15
20
|
return Week.fromTimestamp(now);
|
|
16
21
|
}
|
package/src/weekday.vo.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TimestampVO } from "./timestamp.vo";
|
|
2
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
2
3
|
|
|
3
4
|
export type WeekdayFormatter = (value: Weekday["value"]) => string;
|
|
4
5
|
|
|
@@ -52,11 +53,15 @@ export class Weekday {
|
|
|
52
53
|
this.formatter = formatter ?? WeekdayFormatters.FULL;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
static
|
|
56
|
+
static fromTimestamp(timestamp: TimestampVO, formatter?: WeekdayFormatter): Weekday {
|
|
56
57
|
const dayZeroBased = new Date(timestamp.ms).getUTCDay(); // 0..6
|
|
57
58
|
return new Weekday(dayZeroBased, formatter);
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
static fromTimestampValue(timestamp: TimestampValueType): Weekday {
|
|
62
|
+
return Weekday.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
63
|
+
}
|
|
64
|
+
|
|
60
65
|
get(): number {
|
|
61
66
|
return this.value;
|
|
62
67
|
}
|
package/src/year.vo.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addYears, endOfYear, getYear, startOfYear } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { TimestampVO } from "./timestamp.vo";
|
|
4
|
+
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
5
|
import { YearIsoId, type YearIsoIdType } from "./year-iso-id.vo";
|
|
5
6
|
|
|
6
7
|
export class Year extends DateRange {
|
|
@@ -11,6 +12,10 @@ export class Year extends DateRange {
|
|
|
11
12
|
return new Year(start, end);
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
static fromTimestampValue(timestamp: TimestampValueType): Year {
|
|
16
|
+
return Year.fromTimestamp(TimestampVO.fromValue(timestamp));
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
static fromNow(now: TimestampVO): Year {
|
|
15
20
|
return Year.fromTimestamp(now);
|
|
16
21
|
}
|