@bgord/tools 0.12.6 → 0.12.8
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/day-iso-id.vo.d.ts +3 -0
- package/dist/day-iso-id.vo.js +10 -0
- package/dist/day.vo.d.ts +10 -0
- package/dist/day.vo.js +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/time.service.d.ts +5 -3
- package/dist/time.service.js +5 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +2 -0
- package/src/day-iso-id.vo.ts +16 -0
- package/src/day.vo.ts +31 -0
- package/src/index.ts +2 -0
- package/src/time.service.ts +10 -7
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isValid, parseISO } from "date-fns";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
export const DayIsoId = z
|
|
4
|
+
.string()
|
|
5
|
+
// 4-digit year, 2-digit month, 2-digit day
|
|
6
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
|
7
|
+
.refine((value) => {
|
|
8
|
+
const date = parseISO(value);
|
|
9
|
+
return isValid(date) && value === date.toISOString().slice(0, 10);
|
|
10
|
+
}, { message: "day-iso-id.invalid" });
|
package/dist/day.vo.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateRange } from "./date-range.vo";
|
|
2
|
+
import { DayIsoIdType } from "./day-iso-id.vo";
|
|
3
|
+
import { TimestampType } from "./timestamp.vo";
|
|
4
|
+
export declare class Day extends DateRange {
|
|
5
|
+
private constructor();
|
|
6
|
+
toIsoId(): DayIsoIdType;
|
|
7
|
+
static fromTimestamp(timestamp: TimestampType): Day;
|
|
8
|
+
static fromNow(now?: TimestampType): Day;
|
|
9
|
+
static fromIsoId(isoId: DayIsoIdType): Day;
|
|
10
|
+
}
|
package/dist/day.vo.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { endOfDay, startOfDay } from "date-fns";
|
|
2
|
+
import { DateRange } from "./date-range.vo";
|
|
3
|
+
import { DayIsoId } from "./day-iso-id.vo";
|
|
4
|
+
import { Timestamp } from "./timestamp.vo";
|
|
5
|
+
export class Day extends DateRange {
|
|
6
|
+
constructor(start, end) {
|
|
7
|
+
super(start, end);
|
|
8
|
+
}
|
|
9
|
+
toIsoId() {
|
|
10
|
+
return new Date(this.getStart()).toISOString().slice(0, 10);
|
|
11
|
+
}
|
|
12
|
+
static fromTimestamp(timestamp) {
|
|
13
|
+
const start = Timestamp.parse(startOfDay(timestamp).getTime());
|
|
14
|
+
const end = Timestamp.parse(endOfDay(timestamp).getTime());
|
|
15
|
+
return new Day(start, end);
|
|
16
|
+
}
|
|
17
|
+
static fromNow(now = Timestamp.parse(Date.now())) {
|
|
18
|
+
return Day.fromTimestamp(now);
|
|
19
|
+
}
|
|
20
|
+
static fromIsoId(isoId) {
|
|
21
|
+
const [year, month, day] = DayIsoId.parse(isoId).split("-").map(Number);
|
|
22
|
+
const reference = new Date(Date.UTC(year, month - 1, day));
|
|
23
|
+
return Day.fromTimestamp(Timestamp.parse(reference.getTime()));
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export * from "./date-calculator.service";
|
|
|
5
5
|
export * from "./date-formatter.service";
|
|
6
6
|
export * from "./date-range.vo";
|
|
7
7
|
export * from "./dates-of-the-week.vo";
|
|
8
|
+
export * from "./day.vo";
|
|
9
|
+
export * from "./day-iso-id.vo";
|
|
8
10
|
export * from "./dll.service";
|
|
9
11
|
export * from "./email-mask.service";
|
|
10
12
|
export * from "./etags.vo";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,8 @@ export * from "./date-calculator.service";
|
|
|
5
5
|
export * from "./date-formatter.service";
|
|
6
6
|
export * from "./date-range.vo";
|
|
7
7
|
export * from "./dates-of-the-week.vo";
|
|
8
|
+
export * from "./day.vo";
|
|
9
|
+
export * from "./day-iso-id.vo";
|
|
8
10
|
export * from "./dll.service";
|
|
9
11
|
export * from "./email-mask.service";
|
|
10
12
|
export * from "./etags.vo";
|
package/dist/time.service.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
1
2
|
interface TimeResultInterface {
|
|
2
3
|
readonly days: number;
|
|
3
4
|
readonly hours: number;
|
|
4
5
|
readonly minutes: number;
|
|
5
6
|
readonly seconds: number;
|
|
6
|
-
readonly ms:
|
|
7
|
+
readonly ms: TimestampType;
|
|
7
8
|
isAfter(another: TimeResultInterface): boolean;
|
|
8
9
|
isBefore(another: TimeResultInterface): boolean;
|
|
9
10
|
}
|
|
@@ -12,8 +13,8 @@ export declare class TimeResult implements TimeResultInterface {
|
|
|
12
13
|
readonly hours: number;
|
|
13
14
|
readonly minutes: number;
|
|
14
15
|
readonly seconds: number;
|
|
15
|
-
readonly ms:
|
|
16
|
-
constructor(days: number, hours: number, minutes: number, seconds: number, ms:
|
|
16
|
+
readonly ms: TimestampType;
|
|
17
|
+
constructor(days: number, hours: number, minutes: number, seconds: number, ms: TimestampType);
|
|
17
18
|
isAfter(another: TimeResultInterface): boolean;
|
|
18
19
|
isBefore(another: TimeResultInterface): boolean;
|
|
19
20
|
}
|
|
@@ -24,6 +25,7 @@ export declare class Time {
|
|
|
24
25
|
static Seconds(value: number): TimeResultInterface;
|
|
25
26
|
static Ms(value: number): TimeResultInterface;
|
|
26
27
|
static Now(now?: number): {
|
|
28
|
+
value: TimestampType;
|
|
27
29
|
Minus(time: TimeResultInterface): TimeResultInterface;
|
|
28
30
|
Add(time: TimeResultInterface): TimeResultInterface;
|
|
29
31
|
};
|
package/dist/time.service.js
CHANGED
|
@@ -22,22 +22,23 @@ export class TimeResult {
|
|
|
22
22
|
}
|
|
23
23
|
export class Time {
|
|
24
24
|
static Days(value) {
|
|
25
|
-
return new TimeResult(value, value * 24, value * 24 * 60, value * 24 * 60 * 60, value * 24 * 60 * 60 * 1000);
|
|
25
|
+
return new TimeResult(value, value * 24, value * 24 * 60, value * 24 * 60 * 60, (value * 24 * 60 * 60 * 1000));
|
|
26
26
|
}
|
|
27
27
|
static Hours(value) {
|
|
28
|
-
return new TimeResult(rounding.round(value / 24), value, value * 60, value * 60 * 60, value * 60 * 60 * 1000);
|
|
28
|
+
return new TimeResult(rounding.round(value / 24), value, value * 60, value * 60 * 60, (value * 60 * 60 * 1000));
|
|
29
29
|
}
|
|
30
30
|
static Minutes(value) {
|
|
31
|
-
return new TimeResult(rounding.round(value / 60 / 24), rounding.round(value / 60), value, value * 60, value * 60 * 1000);
|
|
31
|
+
return new TimeResult(rounding.round(value / 60 / 24), rounding.round(value / 60), value, value * 60, (value * 60 * 1000));
|
|
32
32
|
}
|
|
33
33
|
static Seconds(value) {
|
|
34
|
-
return new TimeResult(rounding.round(value / 60 / 60 / 24), rounding.round(value / 60 / 60), rounding.round(value / 60), value, value * 1000);
|
|
34
|
+
return new TimeResult(rounding.round(value / 60 / 60 / 24), rounding.round(value / 60 / 60), rounding.round(value / 60), value, (value * 1000));
|
|
35
35
|
}
|
|
36
36
|
static Ms(value) {
|
|
37
37
|
return new TimeResult(rounding.round(value / 1000 / 60 / 60 / 24), rounding.round(value / 1000 / 60 / 60), rounding.round(value / 1000 / 60), rounding.round(value / 1000), value);
|
|
38
38
|
}
|
|
39
39
|
static Now(now = Date.now()) {
|
|
40
40
|
return {
|
|
41
|
+
value: now,
|
|
41
42
|
Minus(time) {
|
|
42
43
|
return Time.Ms(now - time.ms);
|
|
43
44
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/api-key.vo.ts","../src/build-version.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/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/feature-flag.vo.ts","../src/filter.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/leap-year-checker.service.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/noop.service.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/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/z-score.service.ts"],"version":"5.9.2"}
|
|
1
|
+
{"root":["../src/api-key.vo.ts","../src/build-version.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/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/feature-flag.vo.ts","../src/filter.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/leap-year-checker.service.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/noop.service.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/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/z-score.service.ts"],"version":"5.9.2"}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isValid, parseISO } from "date-fns";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
|
|
4
|
+
export const DayIsoId = z
|
|
5
|
+
.string()
|
|
6
|
+
// 4-digit year, 2-digit month, 2-digit day
|
|
7
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
|
8
|
+
.refine(
|
|
9
|
+
(value) => {
|
|
10
|
+
const date = parseISO(value);
|
|
11
|
+
return isValid(date) && value === date.toISOString().slice(0, 10);
|
|
12
|
+
},
|
|
13
|
+
{ message: "day-iso-id.invalid" },
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export type DayIsoIdType = z.infer<typeof DayIsoId>;
|
package/src/day.vo.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { endOfDay, startOfDay } from "date-fns";
|
|
2
|
+
import { DateRange } from "./date-range.vo";
|
|
3
|
+
import { DayIsoId, DayIsoIdType } from "./day-iso-id.vo";
|
|
4
|
+
import { Timestamp, TimestampType } from "./timestamp.vo";
|
|
5
|
+
|
|
6
|
+
export class Day extends DateRange {
|
|
7
|
+
private constructor(start: TimestampType, end: TimestampType) {
|
|
8
|
+
super(start, end);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
toIsoId(): DayIsoIdType {
|
|
12
|
+
return new Date(this.getStart()).toISOString().slice(0, 10) as DayIsoIdType;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static fromTimestamp(timestamp: TimestampType): Day {
|
|
16
|
+
const start = Timestamp.parse(startOfDay(timestamp).getTime());
|
|
17
|
+
const end = Timestamp.parse(endOfDay(timestamp).getTime());
|
|
18
|
+
return new Day(start, end);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static fromNow(now: TimestampType = Timestamp.parse(Date.now())): Day {
|
|
22
|
+
return Day.fromTimestamp(now);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static fromIsoId(isoId: DayIsoIdType): Day {
|
|
26
|
+
const [year, month, day] = DayIsoId.parse(isoId).split("-").map(Number);
|
|
27
|
+
|
|
28
|
+
const reference = new Date(Date.UTC(year, month - 1, day));
|
|
29
|
+
return Day.fromTimestamp(Timestamp.parse(reference.getTime()));
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ export * from "./date-calculator.service";
|
|
|
5
5
|
export * from "./date-formatter.service";
|
|
6
6
|
export * from "./date-range.vo";
|
|
7
7
|
export * from "./dates-of-the-week.vo";
|
|
8
|
+
export * from "./day.vo";
|
|
9
|
+
export * from "./day-iso-id.vo";
|
|
8
10
|
export * from "./dll.service";
|
|
9
11
|
export * from "./email-mask.service";
|
|
10
12
|
export * from "./etags.vo";
|
package/src/time.service.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RoundToDecimal } from "./rounding.service";
|
|
2
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
2
3
|
|
|
3
4
|
const rounding = new RoundToDecimal(2);
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ interface TimeResultInterface {
|
|
|
7
8
|
readonly hours: number;
|
|
8
9
|
readonly minutes: number;
|
|
9
10
|
readonly seconds: number;
|
|
10
|
-
readonly ms:
|
|
11
|
+
readonly ms: TimestampType;
|
|
11
12
|
|
|
12
13
|
isAfter(another: TimeResultInterface): boolean;
|
|
13
14
|
isBefore(another: TimeResultInterface): boolean;
|
|
@@ -19,7 +20,7 @@ export class TimeResult implements TimeResultInterface {
|
|
|
19
20
|
readonly hours: number,
|
|
20
21
|
readonly minutes: number,
|
|
21
22
|
readonly seconds: number,
|
|
22
|
-
readonly ms:
|
|
23
|
+
readonly ms: TimestampType,
|
|
23
24
|
) {}
|
|
24
25
|
|
|
25
26
|
isAfter(another: TimeResultInterface): boolean {
|
|
@@ -38,7 +39,7 @@ export class Time {
|
|
|
38
39
|
value * 24,
|
|
39
40
|
value * 24 * 60,
|
|
40
41
|
value * 24 * 60 * 60,
|
|
41
|
-
value * 24 * 60 * 60 * 1000,
|
|
42
|
+
(value * 24 * 60 * 60 * 1000) as TimestampType,
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -48,7 +49,7 @@ export class Time {
|
|
|
48
49
|
value,
|
|
49
50
|
value * 60,
|
|
50
51
|
value * 60 * 60,
|
|
51
|
-
value * 60 * 60 * 1000,
|
|
52
|
+
(value * 60 * 60 * 1000) as TimestampType,
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -58,7 +59,7 @@ export class Time {
|
|
|
58
59
|
rounding.round(value / 60),
|
|
59
60
|
value,
|
|
60
61
|
value * 60,
|
|
61
|
-
value * 60 * 1000,
|
|
62
|
+
(value * 60 * 1000) as TimestampType,
|
|
62
63
|
);
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -68,7 +69,7 @@ export class Time {
|
|
|
68
69
|
rounding.round(value / 60 / 60),
|
|
69
70
|
rounding.round(value / 60),
|
|
70
71
|
value,
|
|
71
|
-
value * 1000,
|
|
72
|
+
(value * 1000) as TimestampType,
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -78,12 +79,14 @@ export class Time {
|
|
|
78
79
|
rounding.round(value / 1000 / 60 / 60),
|
|
79
80
|
rounding.round(value / 1000 / 60),
|
|
80
81
|
rounding.round(value / 1000),
|
|
81
|
-
value,
|
|
82
|
+
value as TimestampType,
|
|
82
83
|
);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
static Now(now = Date.now()) {
|
|
86
87
|
return {
|
|
88
|
+
value: now as TimestampType,
|
|
89
|
+
|
|
87
90
|
Minus(time: TimeResultInterface): TimeResultInterface {
|
|
88
91
|
return Time.Ms(now - time.ms);
|
|
89
92
|
},
|