@bgord/tools 0.14.1 → 0.14.3
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 +27 -0
- package/dist/age.vo.js +49 -0
- package/dist/day.vo.d.ts +3 -0
- package/dist/day.vo.js +13 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/month.vo.d.ts +3 -0
- package/dist/month.vo.js +13 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/week.vo.d.ts +3 -0
- package/dist/week.vo.js +13 -1
- package/dist/year.vo.d.ts +3 -0
- package/dist/year.vo.js +13 -1
- package/package.json +4 -4
- package/readme.md +1 -0
- package/src/age.vo.ts +59 -0
- package/src/day.vo.ts +16 -1
- package/src/index.ts +1 -0
- package/src/month.vo.ts +16 -1
- package/src/week.vo.ts +16 -1
- package/src/year.vo.ts +16 -1
package/dist/age.vo.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
3
|
+
export declare const AgeValueError: {
|
|
4
|
+
error: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class Age {
|
|
7
|
+
private readonly value;
|
|
8
|
+
static readonly MIN = 1;
|
|
9
|
+
static readonly MAX = 130;
|
|
10
|
+
static readonly AgeValue: z.core.$ZodBranded<z.ZodNumber, "AgeValue">;
|
|
11
|
+
private constructor();
|
|
12
|
+
get(): number;
|
|
13
|
+
compare(other: Age): -1 | 0 | 1;
|
|
14
|
+
equals(another: Age): boolean;
|
|
15
|
+
isOlderThan(another: Age): boolean;
|
|
16
|
+
isYoungerThan(another: Age): boolean;
|
|
17
|
+
isAdult(minAge: Age): boolean;
|
|
18
|
+
static fromValue(candidate: number): Age;
|
|
19
|
+
static fromBirthdateTimestamp(params: {
|
|
20
|
+
birthdate: TimestampType;
|
|
21
|
+
now: TimestampType;
|
|
22
|
+
}): Age;
|
|
23
|
+
static fromBirthdate(params: {
|
|
24
|
+
birthdate: string;
|
|
25
|
+
now: TimestampType;
|
|
26
|
+
}): Age;
|
|
27
|
+
}
|
package/dist/age.vo.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { differenceInYears } from "date-fns";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
export const AgeValueError = { error: "invalid.age" };
|
|
4
|
+
export class Age {
|
|
5
|
+
value;
|
|
6
|
+
static MIN = 1;
|
|
7
|
+
static MAX = 130;
|
|
8
|
+
static AgeValue = z
|
|
9
|
+
.number(AgeValueError)
|
|
10
|
+
.int(AgeValueError)
|
|
11
|
+
.min(Age.MIN, AgeValueError)
|
|
12
|
+
.max(Age.MAX, AgeValueError)
|
|
13
|
+
.brand("AgeValue");
|
|
14
|
+
constructor(value) {
|
|
15
|
+
this.value = value;
|
|
16
|
+
}
|
|
17
|
+
get() {
|
|
18
|
+
return this.value;
|
|
19
|
+
}
|
|
20
|
+
compare(other) {
|
|
21
|
+
return this.value === other.value ? 0 : this.value < other.value ? -1 : 1;
|
|
22
|
+
}
|
|
23
|
+
equals(another) {
|
|
24
|
+
return this.compare(another) === 0;
|
|
25
|
+
}
|
|
26
|
+
isOlderThan(another) {
|
|
27
|
+
return this.compare(another) === 1;
|
|
28
|
+
}
|
|
29
|
+
isYoungerThan(another) {
|
|
30
|
+
return this.compare(another) === -1;
|
|
31
|
+
}
|
|
32
|
+
isAdult(minAge) {
|
|
33
|
+
return this.equals(minAge) || this.isOlderThan(minAge);
|
|
34
|
+
}
|
|
35
|
+
static fromValue(candidate) {
|
|
36
|
+
return new Age(Age.AgeValue.parse(candidate));
|
|
37
|
+
}
|
|
38
|
+
static fromBirthdateTimestamp(params) {
|
|
39
|
+
if (params.birthdate > params.now)
|
|
40
|
+
throw new Error("invalid.birthdate_in_future");
|
|
41
|
+
return Age.fromValue(differenceInYears(params.now, params.birthdate));
|
|
42
|
+
}
|
|
43
|
+
static fromBirthdate(params) {
|
|
44
|
+
const birthdate = new Date(params.birthdate).getTime();
|
|
45
|
+
if (birthdate > params.now)
|
|
46
|
+
throw new Error("invalid.birthdate_in_future");
|
|
47
|
+
return Age.fromValue(differenceInYears(params.now, birthdate));
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/day.vo.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { type TimestampType } from "./timestamp.vo";
|
|
|
4
4
|
export declare class Day extends DateRange {
|
|
5
5
|
private constructor();
|
|
6
6
|
toIsoId(): DayIsoIdType;
|
|
7
|
+
previous(): Day;
|
|
8
|
+
next(): Day;
|
|
9
|
+
shift(count: number): Day;
|
|
7
10
|
static fromTimestamp(timestamp: TimestampType): Day;
|
|
8
11
|
static fromNow(now: TimestampType): Day;
|
|
9
12
|
static fromIsoId(isoId: DayIsoIdType): Day;
|
package/dist/day.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfDay, startOfDay } from "date-fns";
|
|
1
|
+
import { addDays, endOfDay, startOfDay } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { DayIsoId } from "./day-iso-id.vo";
|
|
4
4
|
import { Time } from "./time.service";
|
|
@@ -10,6 +10,18 @@ export class Day extends DateRange {
|
|
|
10
10
|
toIsoId() {
|
|
11
11
|
return new Date(this.getStart() + Time.Hours(12).ms).toISOString().slice(0, 10);
|
|
12
12
|
}
|
|
13
|
+
previous() {
|
|
14
|
+
const shifted = addDays(new Date(this.getStart()), -1).getTime();
|
|
15
|
+
return Day.fromTimestamp(Timestamp.parse(shifted));
|
|
16
|
+
}
|
|
17
|
+
next() {
|
|
18
|
+
const shifted = addDays(new Date(this.getStart()), 1).getTime();
|
|
19
|
+
return Day.fromTimestamp(Timestamp.parse(shifted));
|
|
20
|
+
}
|
|
21
|
+
shift(count) {
|
|
22
|
+
const shifted = addDays(new Date(this.getStart()), count).getTime();
|
|
23
|
+
return Day.fromTimestamp(Timestamp.parse(shifted));
|
|
24
|
+
}
|
|
13
25
|
static fromTimestamp(timestamp) {
|
|
14
26
|
const start = Timestamp.parse(startOfDay(timestamp).getTime());
|
|
15
27
|
const end = Timestamp.parse(endOfDay(timestamp).getTime());
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/month.vo.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { type MonthIsoIdType } from "./month-iso-id.vo";
|
|
|
3
3
|
import { type TimestampType } from "./timestamp.vo";
|
|
4
4
|
export declare class Month extends DateRange {
|
|
5
5
|
toIsoId(): MonthIsoIdType;
|
|
6
|
+
previous(): Month;
|
|
7
|
+
next(): Month;
|
|
8
|
+
shift(count: number): Month;
|
|
6
9
|
static fromTimestamp(timestamp: TimestampType): Month;
|
|
7
10
|
static fromNow(now: TimestampType): Month;
|
|
8
11
|
static fromIsoId(iso: MonthIsoIdType): Month;
|
package/dist/month.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfMonth, startOfMonth } from "date-fns";
|
|
1
|
+
import { addMonths, endOfMonth, startOfMonth } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { MonthIsoId } from "./month-iso-id.vo";
|
|
4
4
|
import { Timestamp } from "./timestamp.vo";
|
|
@@ -6,6 +6,18 @@ export class Month extends DateRange {
|
|
|
6
6
|
toIsoId() {
|
|
7
7
|
return new Date(this.getStart()).toISOString().slice(0, 7);
|
|
8
8
|
}
|
|
9
|
+
previous() {
|
|
10
|
+
const shifted = addMonths(new Date(this.getStart()), -1).getTime();
|
|
11
|
+
return Month.fromTimestamp(Timestamp.parse(shifted));
|
|
12
|
+
}
|
|
13
|
+
next() {
|
|
14
|
+
const shifted = addMonths(new Date(this.getStart()), 1).getTime();
|
|
15
|
+
return Month.fromTimestamp(Timestamp.parse(shifted));
|
|
16
|
+
}
|
|
17
|
+
shift(count) {
|
|
18
|
+
const shifted = addMonths(new Date(this.getStart()), count).getTime();
|
|
19
|
+
return Month.fromTimestamp(Timestamp.parse(shifted));
|
|
20
|
+
}
|
|
9
21
|
static fromTimestamp(timestamp) {
|
|
10
22
|
const start = Timestamp.parse(startOfMonth(timestamp).getTime());
|
|
11
23
|
const end = Timestamp.parse(endOfMonth(timestamp).getTime());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/dates-of-the-week.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-from-string.vo.ts","../src/filename-suffix.vo.ts","../src/filename.vo.ts","../src/height.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering.service.ts","../src/revision.vo.ts","../src/rounding.service.ts","../src/simple-linear-regression.service.ts","../src/size.vo.ts","../src/stepper.service.ts","../src/stopwatch.service.ts","../src/streak-calculator.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/time.service.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.
|
|
1
|
+
{"root":["../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/dates-of-the-week.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-from-string.vo.ts","../src/filename-suffix.vo.ts","../src/filename.vo.ts","../src/height.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering.service.ts","../src/revision.vo.ts","../src/rounding.service.ts","../src/simple-linear-regression.service.ts","../src/size.vo.ts","../src/stepper.service.ts","../src/stopwatch.service.ts","../src/streak-calculator.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/time.service.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.3"}
|
package/dist/week.vo.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { type TimestampType } from "./timestamp.vo";
|
|
|
3
3
|
import { type WeekIsoIdType } from "./week-iso-id.vo";
|
|
4
4
|
export declare class Week extends DateRange {
|
|
5
5
|
toIsoId(): WeekIsoIdType;
|
|
6
|
+
previous(): Week;
|
|
7
|
+
next(): Week;
|
|
8
|
+
shift(count: number): Week;
|
|
6
9
|
static fromTimestamp(timestamp: TimestampType): Week;
|
|
7
10
|
static fromNow(now: TimestampType): Week;
|
|
8
11
|
static fromIsoId(isoId: WeekIsoIdType): Week;
|
package/dist/week.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfISOWeek, getISOWeek, getISOWeekYear, setISOWeek, startOfISOWeek } from "date-fns";
|
|
1
|
+
import { addWeeks, endOfISOWeek, getISOWeek, getISOWeekYear, setISOWeek, startOfISOWeek } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { Timestamp } from "./timestamp.vo";
|
|
4
4
|
import { WeekIsoId } from "./week-iso-id.vo";
|
|
@@ -8,6 +8,18 @@ export class Week extends DateRange {
|
|
|
8
8
|
const week = getISOWeek(this.getStart()).toString().padStart(2, "0");
|
|
9
9
|
return `${year}-W${week}`;
|
|
10
10
|
}
|
|
11
|
+
previous() {
|
|
12
|
+
const shifted = addWeeks(new Date(this.getStart()), -1).getTime();
|
|
13
|
+
return Week.fromTimestamp(Timestamp.parse(shifted));
|
|
14
|
+
}
|
|
15
|
+
next() {
|
|
16
|
+
const shifted = addWeeks(new Date(this.getStart()), 1).getTime();
|
|
17
|
+
return Week.fromTimestamp(Timestamp.parse(shifted));
|
|
18
|
+
}
|
|
19
|
+
shift(count) {
|
|
20
|
+
const shifted = addWeeks(new Date(this.getStart()), count).getTime();
|
|
21
|
+
return Week.fromTimestamp(Timestamp.parse(shifted));
|
|
22
|
+
}
|
|
11
23
|
static fromTimestamp(timestamp) {
|
|
12
24
|
const start = Timestamp.parse(startOfISOWeek(timestamp).getTime());
|
|
13
25
|
const end = Timestamp.parse(endOfISOWeek(timestamp).getTime());
|
package/dist/year.vo.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { type YearIsoIdType } from "./year-iso-id.vo";
|
|
|
4
4
|
export declare class Year extends DateRange {
|
|
5
5
|
toIsoId(): YearIsoIdType;
|
|
6
6
|
isLeapYear(): boolean;
|
|
7
|
+
previous(): Year;
|
|
8
|
+
next(): Year;
|
|
9
|
+
shift(count: number): Year;
|
|
7
10
|
static fromTimestamp(timestamp: TimestampType): Year;
|
|
8
11
|
static fromNow(now: TimestampType): Year;
|
|
9
12
|
static fromNumber(value: number): Year;
|
package/dist/year.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfYear, getYear, startOfYear } from "date-fns";
|
|
1
|
+
import { addYears, endOfYear, getYear, startOfYear } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { Timestamp } from "./timestamp.vo";
|
|
4
4
|
import { YearIsoId } from "./year-iso-id.vo";
|
|
@@ -10,6 +10,18 @@ export class Year extends DateRange {
|
|
|
10
10
|
const year = getYear(this.getStart());
|
|
11
11
|
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
12
12
|
}
|
|
13
|
+
previous() {
|
|
14
|
+
const shifted = addYears(new Date(this.getStart()), -1).getTime();
|
|
15
|
+
return Year.fromTimestamp(Timestamp.parse(shifted));
|
|
16
|
+
}
|
|
17
|
+
next() {
|
|
18
|
+
const shifted = addYears(new Date(this.getStart()), 1).getTime();
|
|
19
|
+
return Year.fromTimestamp(Timestamp.parse(shifted));
|
|
20
|
+
}
|
|
21
|
+
shift(count) {
|
|
22
|
+
const shifted = addYears(new Date(this.getStart()), count).getTime();
|
|
23
|
+
return Year.fromTimestamp(Timestamp.parse(shifted));
|
|
24
|
+
}
|
|
13
25
|
static fromTimestamp(timestamp) {
|
|
14
26
|
const start = Timestamp.parse(startOfYear(timestamp).getTime());
|
|
15
27
|
const end = Timestamp.parse(endOfYear(timestamp).getTime());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/tools",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@biomejs/biome": "2.2.4",
|
|
25
|
-
"@commitlint/cli": "20.
|
|
25
|
+
"@commitlint/cli": "20.1.0",
|
|
26
26
|
"@commitlint/config-conventional": "20.0.0",
|
|
27
27
|
"@types/bun": "1.2.23",
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
29
|
"cspell": "9.2.1",
|
|
30
30
|
"knip": "5.64.1",
|
|
31
|
-
"lefthook": "1.13.
|
|
31
|
+
"lefthook": "1.13.6",
|
|
32
32
|
"only-allow": "1.2.1",
|
|
33
33
|
"shellcheck": "4.1.0",
|
|
34
|
-
"typescript": "5.9.
|
|
34
|
+
"typescript": "5.9.3",
|
|
35
35
|
"zod": "4.1.11"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
package/readme.md
CHANGED
package/src/age.vo.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { differenceInYears } from "date-fns";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
4
|
+
|
|
5
|
+
export const AgeValueError = { error: "invalid.age" };
|
|
6
|
+
|
|
7
|
+
export class Age {
|
|
8
|
+
static readonly MIN = 1;
|
|
9
|
+
static readonly MAX = 130;
|
|
10
|
+
|
|
11
|
+
static readonly AgeValue = z
|
|
12
|
+
.number(AgeValueError)
|
|
13
|
+
.int(AgeValueError)
|
|
14
|
+
.min(Age.MIN, AgeValueError)
|
|
15
|
+
.max(Age.MAX, AgeValueError)
|
|
16
|
+
.brand("AgeValue");
|
|
17
|
+
|
|
18
|
+
private constructor(private readonly value: z.infer<typeof Age.AgeValue>) {}
|
|
19
|
+
|
|
20
|
+
get(): number {
|
|
21
|
+
return this.value as number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
compare(other: Age): -1 | 0 | 1 {
|
|
25
|
+
return this.value === other.value ? 0 : this.value < other.value ? -1 : 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
equals(another: Age): boolean {
|
|
29
|
+
return this.compare(another) === 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isOlderThan(another: Age): boolean {
|
|
33
|
+
return this.compare(another) === 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
isYoungerThan(another: Age): boolean {
|
|
37
|
+
return this.compare(another) === -1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
isAdult(minAge: Age): boolean {
|
|
41
|
+
return this.equals(minAge) || this.isOlderThan(minAge);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static fromValue(candidate: number): Age {
|
|
45
|
+
return new Age(Age.AgeValue.parse(candidate));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static fromBirthdateTimestamp(params: { birthdate: TimestampType; now: TimestampType }): Age {
|
|
49
|
+
if (params.birthdate > params.now) throw new Error("invalid.birthdate_in_future");
|
|
50
|
+
return Age.fromValue(differenceInYears(params.now, params.birthdate));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static fromBirthdate(params: { birthdate: string; now: TimestampType }): Age {
|
|
54
|
+
const birthdate = new Date(params.birthdate).getTime();
|
|
55
|
+
|
|
56
|
+
if (birthdate > params.now) throw new Error("invalid.birthdate_in_future");
|
|
57
|
+
return Age.fromValue(differenceInYears(params.now, birthdate));
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/day.vo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfDay, startOfDay } from "date-fns";
|
|
1
|
+
import { addDays, endOfDay, startOfDay } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { DayIsoId, type DayIsoIdType } from "./day-iso-id.vo";
|
|
4
4
|
import { Time } from "./time.service";
|
|
@@ -13,6 +13,21 @@ export class Day extends DateRange {
|
|
|
13
13
|
return new Date(this.getStart() + Time.Hours(12).ms).toISOString().slice(0, 10) as DayIsoIdType;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
previous(): Day {
|
|
17
|
+
const shifted = addDays(new Date(this.getStart()), -1).getTime();
|
|
18
|
+
return Day.fromTimestamp(Timestamp.parse(shifted));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
next(): Day {
|
|
22
|
+
const shifted = addDays(new Date(this.getStart()), 1).getTime();
|
|
23
|
+
return Day.fromTimestamp(Timestamp.parse(shifted));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
shift(count: number): Day {
|
|
27
|
+
const shifted = addDays(new Date(this.getStart()), count).getTime();
|
|
28
|
+
return Day.fromTimestamp(Timestamp.parse(shifted));
|
|
29
|
+
}
|
|
30
|
+
|
|
16
31
|
static fromTimestamp(timestamp: TimestampType): Day {
|
|
17
32
|
const start = Timestamp.parse(startOfDay(timestamp).getTime());
|
|
18
33
|
const end = Timestamp.parse(endOfDay(timestamp).getTime());
|
package/src/index.ts
CHANGED
package/src/month.vo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfMonth, startOfMonth } from "date-fns";
|
|
1
|
+
import { addMonths, endOfMonth, 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 { Timestamp, type TimestampType } from "./timestamp.vo";
|
|
@@ -8,6 +8,21 @@ export class Month extends DateRange {
|
|
|
8
8
|
return new Date(this.getStart()).toISOString().slice(0, 7) as MonthIsoIdType;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
previous(): Month {
|
|
12
|
+
const shifted = addMonths(new Date(this.getStart()), -1).getTime();
|
|
13
|
+
return Month.fromTimestamp(Timestamp.parse(shifted));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
next(): Month {
|
|
17
|
+
const shifted = addMonths(new Date(this.getStart()), 1).getTime();
|
|
18
|
+
return Month.fromTimestamp(Timestamp.parse(shifted));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
shift(count: number): Month {
|
|
22
|
+
const shifted = addMonths(new Date(this.getStart()), count).getTime();
|
|
23
|
+
return Month.fromTimestamp(Timestamp.parse(shifted));
|
|
24
|
+
}
|
|
25
|
+
|
|
11
26
|
static fromTimestamp(timestamp: TimestampType): Month {
|
|
12
27
|
const start = Timestamp.parse(startOfMonth(timestamp).getTime());
|
|
13
28
|
const end = Timestamp.parse(endOfMonth(timestamp).getTime());
|
package/src/week.vo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfISOWeek, getISOWeek, getISOWeekYear, setISOWeek, startOfISOWeek } from "date-fns";
|
|
1
|
+
import { addWeeks, endOfISOWeek, getISOWeek, getISOWeekYear, setISOWeek, startOfISOWeek } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { Timestamp, type TimestampType } from "./timestamp.vo";
|
|
4
4
|
import { WeekIsoId, type WeekIsoIdType } from "./week-iso-id.vo";
|
|
@@ -11,6 +11,21 @@ export class Week extends DateRange {
|
|
|
11
11
|
return `${year}-W${week}`;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
previous(): Week {
|
|
15
|
+
const shifted = addWeeks(new Date(this.getStart()), -1).getTime();
|
|
16
|
+
return Week.fromTimestamp(Timestamp.parse(shifted));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
next(): Week {
|
|
20
|
+
const shifted = addWeeks(new Date(this.getStart()), 1).getTime();
|
|
21
|
+
return Week.fromTimestamp(Timestamp.parse(shifted));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
shift(count: number): Week {
|
|
25
|
+
const shifted = addWeeks(new Date(this.getStart()), count).getTime();
|
|
26
|
+
return Week.fromTimestamp(Timestamp.parse(shifted));
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
static fromTimestamp(timestamp: TimestampType): Week {
|
|
15
30
|
const start = Timestamp.parse(startOfISOWeek(timestamp).getTime());
|
|
16
31
|
const end = Timestamp.parse(endOfISOWeek(timestamp).getTime());
|
package/src/year.vo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfYear, getYear, startOfYear } from "date-fns";
|
|
1
|
+
import { addYears, endOfYear, getYear, startOfYear } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { Timestamp, type TimestampType } from "./timestamp.vo";
|
|
4
4
|
import { YearIsoId, type YearIsoIdType } from "./year-iso-id.vo";
|
|
@@ -13,6 +13,21 @@ export class Year extends DateRange {
|
|
|
13
13
|
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
previous(): Year {
|
|
17
|
+
const shifted = addYears(new Date(this.getStart()), -1).getTime();
|
|
18
|
+
return Year.fromTimestamp(Timestamp.parse(shifted));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
next(): Year {
|
|
22
|
+
const shifted = addYears(new Date(this.getStart()), 1).getTime();
|
|
23
|
+
return Year.fromTimestamp(Timestamp.parse(shifted));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
shift(count: number): Year {
|
|
27
|
+
const shifted = addYears(new Date(this.getStart()), count).getTime();
|
|
28
|
+
return Year.fromTimestamp(Timestamp.parse(shifted));
|
|
29
|
+
}
|
|
30
|
+
|
|
16
31
|
static fromTimestamp(timestamp: TimestampType): Year {
|
|
17
32
|
const start = Timestamp.parse(startOfYear(timestamp).getTime());
|
|
18
33
|
const end = Timestamp.parse(endOfYear(timestamp).getTime());
|