@bgord/tools 1.0.5 → 1.1.0

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.
Files changed (60) hide show
  1. package/dist/age.vo.d.ts +4 -4
  2. package/dist/age.vo.js +6 -5
  3. package/dist/clock.vo.d.ts +2 -2
  4. package/dist/clock.vo.js +7 -7
  5. package/dist/date-calculator.service.d.ts +3 -3
  6. package/dist/date-calculator.service.js +3 -3
  7. package/dist/date-range.vo.d.ts +6 -6
  8. package/dist/date-range.vo.js +4 -4
  9. package/dist/day.vo.d.ts +3 -4
  10. package/dist/day.vo.js +10 -14
  11. package/dist/hour.vo.d.ts +2 -2
  12. package/dist/hour.vo.js +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/minute.vo.d.ts +2 -2
  16. package/dist/minute.vo.js +1 -1
  17. package/dist/month.vo.d.ts +3 -3
  18. package/dist/month.vo.js +6 -6
  19. package/dist/quarter.vo.d.ts +3 -3
  20. package/dist/quarter.vo.js +5 -5
  21. package/dist/rate-limiter.service.d.ts +2 -2
  22. package/dist/rate-limiter.service.js +3 -3
  23. package/dist/relative-date.vo.d.ts +5 -4
  24. package/dist/relative-date.vo.js +2 -2
  25. package/dist/stopwatch.service.d.ts +3 -3
  26. package/dist/stopwatch.service.js +4 -4
  27. package/dist/timestamp-value.vo.d.ts +6 -0
  28. package/dist/timestamp-value.vo.js +7 -0
  29. package/dist/timestamp.vo.d.ts +18 -6
  30. package/dist/timestamp.vo.js +43 -7
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/week.vo.d.ts +3 -3
  33. package/dist/week.vo.js +7 -7
  34. package/dist/weekday.vo.d.ts +2 -2
  35. package/dist/weekday.vo.js +1 -1
  36. package/dist/year.vo.d.ts +3 -3
  37. package/dist/year.vo.js +7 -7
  38. package/package.json +1 -1
  39. package/readme.md +1 -1
  40. package/src/age.vo.ts +8 -8
  41. package/src/clock.vo.ts +7 -7
  42. package/src/date-calculator.service.ts +6 -6
  43. package/src/date-range.vo.ts +11 -11
  44. package/src/day.vo.ts +15 -19
  45. package/src/hour.vo.ts +3 -3
  46. package/src/index.ts +1 -1
  47. package/src/minute.vo.ts +3 -3
  48. package/src/month.vo.ts +9 -9
  49. package/src/quarter.vo.ts +8 -8
  50. package/src/rate-limiter.service.ts +6 -6
  51. package/src/relative-date.vo.ts +7 -6
  52. package/src/stopwatch.service.ts +3 -3
  53. package/src/timestamp-value.vo.ts +11 -0
  54. package/src/timestamp.vo.ts +51 -8
  55. package/src/week.vo.ts +10 -10
  56. package/src/weekday.vo.ts +3 -3
  57. package/src/year.vo.ts +10 -10
  58. package/dist/time.service.d.ts +0 -8
  59. package/dist/time.service.js +0 -13
  60. package/src/time.service.ts +0 -15
package/dist/age.vo.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TimestampType } from "./timestamp.vo";
1
+ import { Timestamp } from "./timestamp.vo";
2
2
  export declare const AgeError: {
3
3
  readonly FutureBirthdate: "age.future.birthdate";
4
4
  };
@@ -9,12 +9,12 @@ export declare class Age {
9
9
  private constructor();
10
10
  static fromValue(candidate: number): Age;
11
11
  static fromBirthdateEpochMs(params: {
12
- birthdate: TimestampType;
13
- now: TimestampType;
12
+ birthdate: Timestamp;
13
+ now: Timestamp;
14
14
  }): Age;
15
15
  static fromBirthdate(candidate: {
16
16
  birthdate: string;
17
- now: TimestampType;
17
+ now: Timestamp;
18
18
  }): Age;
19
19
  get(): number;
20
20
  equals(other: Age): boolean;
package/dist/age.vo.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { differenceInYears } from "date-fns";
2
2
  import { AgeYears, AgeYearsConstraints } from "./age-years.vo";
3
+ import { Timestamp } from "./timestamp.vo";
3
4
  export const AgeError = { FutureBirthdate: "age.future.birthdate" };
4
5
  export class Age {
5
6
  value;
@@ -12,15 +13,15 @@ export class Age {
12
13
  return new Age(AgeYears.parse(candidate));
13
14
  }
14
15
  static fromBirthdateEpochMs(params) {
15
- if (params.birthdate > params.now)
16
+ if (params.birthdate.isAfter(params.now))
16
17
  throw new Error(AgeError.FutureBirthdate);
17
- return Age.fromValue(differenceInYears(params.now, params.birthdate));
18
+ return Age.fromValue(differenceInYears(params.now.get(), params.birthdate.get()));
18
19
  }
19
20
  static fromBirthdate(candidate) {
20
- const birthdateMs = new Date(candidate.birthdate).getTime();
21
- if (birthdateMs > candidate.now)
21
+ const birthdate = Timestamp.fromNumber(new Date(candidate.birthdate).getTime());
22
+ if (birthdate.isAfter(candidate.now))
22
23
  throw new Error(AgeError.FutureBirthdate);
23
- return Age.fromValue(differenceInYears(candidate.now, birthdateMs));
24
+ return Age.fromValue(differenceInYears(candidate.now.get(), birthdate.get()));
24
25
  }
25
26
  get() {
26
27
  return this.value;
@@ -3,13 +3,13 @@ import { Hour } from "./hour.vo";
3
3
  import type { HourSchemaType } from "./hour-schema.vo";
4
4
  import { Minute } from "./minute.vo";
5
5
  import type { MinuteSchemaType } from "./minute-schema.vo";
6
- import type { TimestampType } from "./timestamp.vo";
6
+ import type { Timestamp } from "./timestamp.vo";
7
7
  export declare class Clock {
8
8
  private readonly hour;
9
9
  private readonly minute;
10
10
  private readonly formatter;
11
11
  constructor(hour: Hour, minute: Minute, formatter?: ClockFormatter);
12
- static fromEpochMs(timestamp: TimestampType, formatter?: ClockFormatter): Clock;
12
+ static fromEpochMs(timestamp: Timestamp, formatter?: ClockFormatter): Clock;
13
13
  get(): {
14
14
  hour: HourSchemaType;
15
15
  minute: MinuteSchemaType;
package/dist/clock.vo.js CHANGED
@@ -22,17 +22,17 @@ export class Clock {
22
22
  return this.formatter(this.hour, this.minute);
23
23
  }
24
24
  equals(another) {
25
- return this.hour.get() === another.hour.get() && this.minute.get() === another.minute.get();
25
+ return this.hour.equals(another.hour) && this.minute.equals(another.minute);
26
26
  }
27
27
  isAfter(another) {
28
- if (this.hour.get() !== another.hour.get())
29
- return this.hour.get() > another.hour.get();
30
- return this.minute.get() > another.minute.get();
28
+ if (!this.hour.equals(another.hour))
29
+ return this.hour.isAfter(another.hour);
30
+ return this.minute.isAfter(another.minute);
31
31
  }
32
32
  isBefore(another) {
33
- if (this.hour.get() !== another.hour.get())
34
- return this.hour.get() < another.hour.get();
35
- return this.minute.get() < another.minute.get();
33
+ if (!this.hour.equals(another.hour))
34
+ return this.hour.isBefore(another.hour);
35
+ return this.minute.isBefore(another.minute);
36
36
  }
37
37
  toString() {
38
38
  return this.format();
@@ -1,10 +1,10 @@
1
1
  import type { TimeZoneOffsetValueType } from "./time-zone-offset-value.vo";
2
- import { type TimestampType } from "./timestamp.vo";
2
+ import { Timestamp } from "./timestamp.vo";
3
3
  type GetStartOfDayTsInTzConfigType = {
4
- now: TimestampType;
4
+ now: Timestamp;
5
5
  timeZoneOffsetMs: TimeZoneOffsetValueType;
6
6
  };
7
7
  export declare class DateCalculator {
8
- static getStartOfDayTsInTz(config: GetStartOfDayTsInTzConfigType): TimestampType;
8
+ static getStartOfDayTsInTz(config: GetStartOfDayTsInTzConfigType): Timestamp;
9
9
  }
10
10
  export {};
@@ -4,12 +4,12 @@ export class DateCalculator {
4
4
  static getStartOfDayTsInTz(config) {
5
5
  const dayMs = Duration.Days(1).ms;
6
6
  // UTC midnight for the UTC date of `now`
7
- const utcMidnight = Math.floor(config.now / dayMs) * dayMs;
7
+ const utcMidnight = Math.floor(config.now.get() / dayMs) * dayMs;
8
8
  // Candidate start of the local day (in UTC), anchored to the same UTC date
9
9
  let start = utcMidnight + config.timeZoneOffsetMs;
10
10
  // If the candidate is in the future relative to `now`, it means local midnight was "yesterday" in UTC.
11
- if (start > config.now)
11
+ if (start > config.now.get())
12
12
  start -= dayMs;
13
- return Timestamp.parse(start);
13
+ return Timestamp.fromNumber(start);
14
14
  }
15
15
  }
@@ -1,15 +1,15 @@
1
- import type { TimestampType } from "./timestamp.vo";
1
+ import type { Timestamp } from "./timestamp.vo";
2
2
  export declare const DateRangeError: {
3
3
  readonly Invalid: "date.range.invalid";
4
4
  };
5
5
  export declare class DateRange {
6
6
  private readonly start;
7
7
  private readonly end;
8
- constructor(start: TimestampType, end: TimestampType);
9
- getStart(): TimestampType;
10
- getEnd(): TimestampType;
11
- toRange(): [TimestampType, TimestampType];
12
- contains(timestamp: TimestampType): boolean;
8
+ constructor(start: Timestamp, end: Timestamp);
9
+ getStart(): Timestamp;
10
+ getEnd(): Timestamp;
11
+ toRange(): [Timestamp, Timestamp];
12
+ contains(timestamp: Timestamp): boolean;
13
13
  equals(other: DateRange): boolean;
14
14
  toJSON(): {
15
15
  start: number;
@@ -5,7 +5,7 @@ export class DateRange {
5
5
  constructor(start, end) {
6
6
  this.start = start;
7
7
  this.end = end;
8
- if (start > end)
8
+ if (start.isAfter(end))
9
9
  throw new Error(DateRangeError.Invalid);
10
10
  }
11
11
  getStart() {
@@ -18,12 +18,12 @@ export class DateRange {
18
18
  return [this.start, this.end];
19
19
  }
20
20
  contains(timestamp) {
21
- return timestamp >= this.start && timestamp <= this.end;
21
+ return timestamp.isAfterOrEqual(this.start) && timestamp.isBeforeOrEqual(this.end);
22
22
  }
23
23
  equals(other) {
24
- return this.start === other.start && this.end === other.end;
24
+ return this.start.equals(other.start) && this.end.equals(other.end);
25
25
  }
26
26
  toJSON() {
27
- return { start: this.getStart(), end: this.getEnd() };
27
+ return { start: this.getStart().get(), end: this.getEnd().get() };
28
28
  }
29
29
  }
package/dist/day.vo.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { DateRange } from "./date-range.vo";
2
2
  import { type DayIsoIdType } from "./day-iso-id.vo";
3
- import { type TimestampType } from "./timestamp.vo";
3
+ import { Timestamp } from "./timestamp.vo";
4
4
  export declare class Day extends DateRange {
5
- private constructor();
6
- static fromTimestamp(timestamp: TimestampType): Day;
7
- static fromNow(now: TimestampType): Day;
5
+ static fromTimestamp(timestamp: Timestamp): Day;
6
+ static fromNow(now: Timestamp): Day;
8
7
  static fromIsoId(isoId: DayIsoIdType): Day;
9
8
  toIsoId(): DayIsoIdType;
10
9
  previous(): Day;
package/dist/day.vo.js CHANGED
@@ -4,27 +4,24 @@ import { DayIsoId } from "./day-iso-id.vo";
4
4
  import { Duration } from "./duration.service";
5
5
  import { Timestamp } from "./timestamp.vo";
6
6
  export class Day extends DateRange {
7
- constructor(start, end) {
8
- super(start, end);
9
- }
10
7
  static fromTimestamp(timestamp) {
11
- const date = new Date(timestamp);
12
- const startUtc = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
13
- const endUtc = startUtc + Duration.Days(1).ms - 1;
14
- return new Day(Timestamp.parse(startUtc), Timestamp.parse(endUtc));
8
+ const date = new Date(timestamp.get());
9
+ const startUtc = Timestamp.fromNumber(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
10
+ const endUtc = startUtc.add(Duration.Days(1)).subtract(Duration.Ms(1));
11
+ return new Day(startUtc, endUtc);
15
12
  }
16
13
  static fromNow(now) {
17
14
  return Day.fromTimestamp(now);
18
15
  }
19
16
  static fromIsoId(isoId) {
20
17
  const [year, month, day] = DayIsoId.parse(isoId).split("-").map(Number);
21
- const startUtc = Date.UTC(year, month - 1, day);
22
- const endUtc = startUtc + Duration.Days(1).ms - 1;
23
- return new Day(Timestamp.parse(startUtc), Timestamp.parse(endUtc));
18
+ const startUtc = Timestamp.fromNumber(Date.UTC(year, month - 1, day));
19
+ const endUtc = startUtc.add(Duration.Days(1)).subtract(Duration.Ms(1));
20
+ return new Day(startUtc, endUtc);
24
21
  }
25
22
  toIsoId() {
26
- const midday = this.getStart() + Duration.Hours(12).ms;
27
- return DayIsoId.parse(formatISO(midday, { representation: "date" }));
23
+ const midday = this.getStart().add(Duration.Hours(12));
24
+ return DayIsoId.parse(formatISO(midday.get(), { representation: "date" }));
28
25
  }
29
26
  previous() {
30
27
  return this.shift(-1);
@@ -33,8 +30,7 @@ export class Day extends DateRange {
33
30
  return this.shift(1);
34
31
  }
35
32
  shift(count) {
36
- const timestamp = this.getStart() + count * Duration.Days(1).ms;
37
- return Day.fromTimestamp(Timestamp.parse(timestamp));
33
+ return Day.fromTimestamp(this.getStart().add(Duration.Days(count)));
38
34
  }
39
35
  toString() {
40
36
  return this.toIsoId();
package/dist/hour.vo.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { type HourFormatter } from "./hour-format.service";
2
2
  import { type HourSchemaType } from "./hour-schema.vo";
3
- import type { TimestampType } from "./timestamp.vo";
3
+ import type { Timestamp } from "./timestamp.vo";
4
4
  export declare class Hour {
5
5
  private readonly value;
6
6
  static readonly ZERO: Hour;
7
7
  static readonly MAX: Hour;
8
8
  constructor(candidate: number);
9
- static fromEpochMs(timestamp: TimestampType): Hour;
9
+ static fromEpochMs(timestamp: Timestamp): Hour;
10
10
  get(): HourSchemaType;
11
11
  format(formatter: HourFormatter): string;
12
12
  equals(another: Hour): boolean;
package/dist/hour.vo.js CHANGED
@@ -8,7 +8,7 @@ export class Hour {
8
8
  this.value = HourSchema.parse(candidate);
9
9
  }
10
10
  static fromEpochMs(timestamp) {
11
- return new Hour(new Date(timestamp).getUTCHours());
11
+ return new Hour(new Date(timestamp.get()).getUTCHours());
12
12
  }
13
13
  get() {
14
14
  return this.value;
package/dist/index.d.ts CHANGED
@@ -78,9 +78,9 @@ export * from "./size-bytes.vo";
78
78
  export * from "./stopwatch.service";
79
79
  export * from "./sum.service";
80
80
  export * from "./thousands-separator.service";
81
- export * from "./time.service";
82
81
  export * from "./time-zone-offset-value.vo";
83
82
  export * from "./timestamp.vo";
83
+ export * from "./timestamp-value.vo";
84
84
  export * from "./timezone.vo";
85
85
  export * from "./ts-utils";
86
86
  export * from "./visually-unambiguous-characters-generator.service";
package/dist/index.js CHANGED
@@ -78,9 +78,9 @@ export * from "./size-bytes.vo";
78
78
  export * from "./stopwatch.service";
79
79
  export * from "./sum.service";
80
80
  export * from "./thousands-separator.service";
81
- export * from "./time.service";
82
81
  export * from "./time-zone-offset-value.vo";
83
82
  export * from "./timestamp.vo";
83
+ export * from "./timestamp-value.vo";
84
84
  export * from "./timezone.vo";
85
85
  export * from "./ts-utils";
86
86
  export * from "./visually-unambiguous-characters-generator.service";
@@ -1,11 +1,11 @@
1
1
  import { type MinuteSchemaType } from "./minute-schema.vo";
2
- import type { TimestampType } from "./timestamp.vo";
2
+ import type { Timestamp } from "./timestamp.vo";
3
3
  export declare class Minute {
4
4
  private readonly value;
5
5
  static readonly ZERO: Minute;
6
6
  static readonly MAX: Minute;
7
7
  constructor(candidate: number);
8
- static fromEpochMs(timestamp: TimestampType): Minute;
8
+ static fromEpochMs(timestamp: Timestamp): Minute;
9
9
  get(): MinuteSchemaType;
10
10
  equals(another: Minute): boolean;
11
11
  isAfter(another: Minute): boolean;
package/dist/minute.vo.js CHANGED
@@ -7,7 +7,7 @@ export class Minute {
7
7
  this.value = MinuteSchema.parse(candidate);
8
8
  }
9
9
  static fromEpochMs(timestamp) {
10
- return new Minute(new Date(timestamp).getUTCMinutes());
10
+ return new Minute(new Date(timestamp.get()).getUTCMinutes());
11
11
  }
12
12
  get() {
13
13
  return this.value;
@@ -1,9 +1,9 @@
1
1
  import { DateRange } from "./date-range.vo";
2
2
  import { type MonthIsoIdType } from "./month-iso-id.vo";
3
- import { type TimestampType } from "./timestamp.vo";
3
+ import { Timestamp } from "./timestamp.vo";
4
4
  export declare class Month extends DateRange {
5
- static fromTimestamp(timestamp: TimestampType): Month;
6
- static fromNow(now: TimestampType): Month;
5
+ static fromTimestamp(timestamp: Timestamp): Month;
6
+ static fromNow(now: Timestamp): Month;
7
7
  static fromIsoId(iso: MonthIsoIdType): Month;
8
8
  toIsoId(): MonthIsoIdType;
9
9
  previous(): Month;
package/dist/month.vo.js CHANGED
@@ -4,8 +4,8 @@ import { MonthIsoId } from "./month-iso-id.vo";
4
4
  import { Timestamp } from "./timestamp.vo";
5
5
  export class Month extends DateRange {
6
6
  static fromTimestamp(timestamp) {
7
- const start = Timestamp.parse(startOfMonth(timestamp).getTime());
8
- const end = Timestamp.parse(endOfMonth(timestamp).getTime());
7
+ const start = Timestamp.fromNumber(startOfMonth(timestamp.get()).getTime());
8
+ const end = Timestamp.fromNumber(endOfMonth(timestamp.get()).getTime());
9
9
  return new Month(start, end);
10
10
  }
11
11
  static fromNow(now) {
@@ -14,10 +14,10 @@ export class Month extends DateRange {
14
14
  static fromIsoId(iso) {
15
15
  const [year, month] = MonthIsoId.parse(iso).split("-").map(Number);
16
16
  const reference = setMonth(Date.UTC(year), month - 1).getTime();
17
- return Month.fromTimestamp(Timestamp.parse(reference));
17
+ return Month.fromTimestamp(Timestamp.fromNumber(reference));
18
18
  }
19
19
  toIsoId() {
20
- return MonthIsoId.parse(format(this.getStart(), "yyyy-MM"));
20
+ return MonthIsoId.parse(format(this.getStart().get(), "yyyy-MM"));
21
21
  }
22
22
  previous() {
23
23
  return this.shift(-1);
@@ -26,8 +26,8 @@ export class Month extends DateRange {
26
26
  return this.shift(1);
27
27
  }
28
28
  shift(count) {
29
- const shifted = setMonth(this.getStart(), getMonth(this.getStart()) + count).getTime();
30
- return Month.fromTimestamp(Timestamp.parse(shifted));
29
+ const shifted = setMonth(this.getStart().get(), getMonth(this.getStart().get()) + count).getTime();
30
+ return Month.fromTimestamp(Timestamp.fromNumber(shifted));
31
31
  }
32
32
  toString() {
33
33
  return this.toIsoId();
@@ -1,9 +1,9 @@
1
1
  import { DateRange } from "./date-range.vo";
2
2
  import { type QuarterIsoIdType } from "./quarter-iso-id.vo";
3
- import { type TimestampType } from "./timestamp.vo";
3
+ import { Timestamp } from "./timestamp.vo";
4
4
  export declare class Quarter extends DateRange {
5
- static fromTimestamp(timestamp: TimestampType): Quarter;
6
- static fromNow(now: TimestampType): Quarter;
5
+ static fromTimestamp(timestamp: Timestamp): Quarter;
6
+ static fromNow(now: Timestamp): Quarter;
7
7
  static fromIsoId(isoId: QuarterIsoIdType): Quarter;
8
8
  toIsoId(): QuarterIsoIdType;
9
9
  toString(): string;
@@ -4,8 +4,8 @@ import { QuarterIsoId } from "./quarter-iso-id.vo";
4
4
  import { Timestamp } from "./timestamp.vo";
5
5
  export class Quarter extends DateRange {
6
6
  static fromTimestamp(timestamp) {
7
- const start = Timestamp.parse(startOfQuarter(timestamp).getTime());
8
- const end = Timestamp.parse(endOfQuarter(timestamp).getTime());
7
+ const start = Timestamp.fromNumber(startOfQuarter(timestamp.get()).getTime());
8
+ const end = Timestamp.fromNumber(endOfQuarter(timestamp.get()).getTime());
9
9
  return new Quarter(start, end);
10
10
  }
11
11
  static fromNow(now) {
@@ -14,11 +14,11 @@ export class Quarter extends DateRange {
14
14
  static fromIsoId(isoId) {
15
15
  const [year, quarter] = QuarterIsoId.parse(isoId).split("-Q").map(Number);
16
16
  const reference = setQuarter(Date.UTC(year), quarter).getTime();
17
- return Quarter.fromTimestamp(Timestamp.parse(reference));
17
+ return Quarter.fromTimestamp(Timestamp.fromNumber(reference));
18
18
  }
19
19
  toIsoId() {
20
- const year = getYear(this.getStart());
21
- const quarter = getQuarter(this.getStart());
20
+ const year = getYear(this.getStart().get());
21
+ const quarter = getQuarter(this.getStart().get());
22
22
  return QuarterIsoId.parse(`${year}-Q${quarter}`);
23
23
  }
24
24
  toString() {
@@ -1,5 +1,5 @@
1
1
  import { Duration } from "./duration.service";
2
- import type { TimestampType } from "./timestamp.vo";
2
+ import type { Timestamp } from "./timestamp.vo";
3
3
  type RateLimiterResultSuccessType = {
4
4
  allowed: true;
5
5
  };
@@ -12,6 +12,6 @@ export declare class RateLimiter {
12
12
  private readonly duration;
13
13
  private lastInvocation;
14
14
  constructor(duration: Duration);
15
- verify(now: TimestampType): RateLimiterResultType;
15
+ verify(now: Timestamp): RateLimiterResultType;
16
16
  }
17
17
  export {};
@@ -10,12 +10,12 @@ export class RateLimiter {
10
10
  this.lastInvocation = now;
11
11
  return { allowed: true };
12
12
  }
13
- const nextAllowedTimestamp = this.lastInvocation + this.duration.ms;
14
- if (nextAllowedTimestamp <= now) {
13
+ const nextAllowedTimestamp = this.lastInvocation.add(this.duration);
14
+ if (nextAllowedTimestamp.isBeforeOrEqual(now)) {
15
15
  this.lastInvocation = now;
16
16
  return { allowed: true };
17
17
  }
18
- const remainingDelta = nextAllowedTimestamp - now;
18
+ const remainingDelta = nextAllowedTimestamp.get() - now.get();
19
19
  return { allowed: false, remaining: Duration.Ms(remainingDelta) };
20
20
  }
21
21
  }
@@ -1,12 +1,13 @@
1
- import type { TimestampType } from "./timestamp.vo";
1
+ import type { Timestamp } from "./timestamp.vo";
2
+ import type { TimestampValueType } from "./timestamp-value.vo";
2
3
  import type { Falsy } from "./ts-utils";
3
4
  type RelativeDateType = {
4
- raw: TimestampType;
5
+ raw: TimestampValueType;
5
6
  relative: string;
6
7
  };
7
8
  export declare class RelativeDate {
8
- static truthy(timestamp: TimestampType): RelativeDateType;
9
- static falsy(timestamp: Falsy<TimestampType>): RelativeDateType | null;
9
+ static truthy(timestamp: Timestamp): RelativeDateType;
10
+ static falsy(timestamp: Falsy<Timestamp>): RelativeDateType | null;
10
11
  private static _format;
11
12
  }
12
13
  export {};
@@ -8,7 +8,7 @@ export class RelativeDate {
8
8
  return null;
9
9
  return RelativeDate._format(timestamp);
10
10
  }
11
- static _format(timestampMs) {
12
- return { raw: timestampMs, relative: DateFormatters.relative(timestampMs) };
11
+ static _format(timestamp) {
12
+ return { raw: timestamp.get(), relative: DateFormatters.relative(timestamp.get()) };
13
13
  }
14
14
  }
@@ -1,12 +1,12 @@
1
1
  import { Duration } from "./duration.service";
2
- import { type TimestampType } from "./timestamp.vo";
2
+ import { Timestamp } from "./timestamp.vo";
3
3
  export declare const StopwatchError: {
4
4
  readonly AlreadyStopped: "stopwatch.already.stopped";
5
5
  };
6
6
  export type StopwatchResultType = Duration;
7
7
  export declare class Stopwatch {
8
- private readonly startMs;
8
+ private readonly start;
9
9
  private state;
10
- constructor(startMs: TimestampType);
10
+ constructor(start: Timestamp);
11
11
  stop(): StopwatchResultType;
12
12
  }
@@ -7,15 +7,15 @@ var StopwatchState;
7
7
  StopwatchState["stopped"] = "stopped";
8
8
  })(StopwatchState || (StopwatchState = {}));
9
9
  export class Stopwatch {
10
- startMs;
10
+ start;
11
11
  state = StopwatchState.started;
12
- constructor(startMs) {
13
- this.startMs = startMs;
12
+ constructor(start) {
13
+ this.start = start;
14
14
  }
15
15
  stop() {
16
16
  if (this.state === StopwatchState.stopped)
17
17
  throw new Error(StopwatchError.AlreadyStopped);
18
18
  this.state = StopwatchState.stopped;
19
- return Duration.Ms(Timestamp.parse(Date.now() - this.startMs));
19
+ return Duration.Ms(Timestamp.fromNumber(Date.now() - this.start.get()).get());
20
20
  }
21
21
  }
@@ -0,0 +1,6 @@
1
+ import { z } from "zod/v4";
2
+ export declare const TimestampValueError: {
3
+ readonly Invalid: "timestamp.invalid";
4
+ };
5
+ export declare const TimestampValue: z.core.$ZodBranded<z.ZodNumber, "TimestampValue">;
6
+ export type TimestampValueType = z.infer<typeof TimestampValue>;
@@ -0,0 +1,7 @@
1
+ import { z } from "zod/v4";
2
+ export const TimestampValueError = { Invalid: "timestamp.invalid" };
3
+ export const TimestampValue = z
4
+ .number(TimestampValueError.Invalid)
5
+ .int(TimestampValueError.Invalid)
6
+ .gte(0, TimestampValueError.Invalid)
7
+ .brand("TimestampValue");
@@ -1,6 +1,18 @@
1
- import { z } from "zod/v4";
2
- export declare const TimestampError: {
3
- readonly Invalid: "timestamp.invalid";
4
- };
5
- export declare const Timestamp: z.core.$ZodBranded<z.ZodNumber, "Timestamp">;
6
- export type TimestampType = z.infer<typeof Timestamp>;
1
+ import type { Duration } from "./duration.service";
2
+ import { type TimestampValueType } from "./timestamp-value.vo";
3
+ export declare class Timestamp {
4
+ private readonly value;
5
+ constructor(value: TimestampValueType);
6
+ static fromValue(value: TimestampValueType): Timestamp;
7
+ static fromNumber(value: number): Timestamp;
8
+ add(duration: Duration): Timestamp;
9
+ subtract(duration: Duration): Timestamp;
10
+ isBefore(another: Timestamp): boolean;
11
+ isBeforeOrEqual(another: Timestamp): boolean;
12
+ isAfter(another: Timestamp): boolean;
13
+ isAfterOrEqual(another: Timestamp): boolean;
14
+ equals(another: Timestamp): boolean;
15
+ get(): TimestampValueType;
16
+ toJSON(): TimestampValueType;
17
+ toString(): string;
18
+ }
@@ -1,7 +1,43 @@
1
- import { z } from "zod/v4";
2
- export const TimestampError = { Invalid: "timestamp.invalid" };
3
- export const Timestamp = z
4
- .number(TimestampError.Invalid)
5
- .int(TimestampError.Invalid)
6
- .gte(0, TimestampError.Invalid)
7
- .brand("Timestamp");
1
+ import { TimestampValue } from "./timestamp-value.vo";
2
+ export class Timestamp {
3
+ value;
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
7
+ static fromValue(value) {
8
+ return new Timestamp(value);
9
+ }
10
+ static fromNumber(value) {
11
+ return new Timestamp(TimestampValue.parse(value));
12
+ }
13
+ add(duration) {
14
+ return Timestamp.fromNumber(this.value + duration.ms);
15
+ }
16
+ subtract(duration) {
17
+ return Timestamp.fromNumber(this.value - duration.ms);
18
+ }
19
+ isBefore(another) {
20
+ return this.value < another.value;
21
+ }
22
+ isBeforeOrEqual(another) {
23
+ return this.value <= another.value;
24
+ }
25
+ isAfter(another) {
26
+ return this.value > another.value;
27
+ }
28
+ isAfterOrEqual(another) {
29
+ return this.value >= another.value;
30
+ }
31
+ equals(another) {
32
+ return this.value === another.value;
33
+ }
34
+ get() {
35
+ return this.value;
36
+ }
37
+ toJSON() {
38
+ return this.value;
39
+ }
40
+ toString() {
41
+ return this.value.toString();
42
+ }
43
+ }
@@ -1 +1 @@
1
- {"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock-format.service.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.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/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.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-milimiters.vo.ts","../src/height.vo.ts","../src/hour-format.service.ts","../src/hour-schema.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute-schema.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.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-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding.adapter.ts","../src/rounding.port.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/stopwatch.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-grams.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"}
1
+ {"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock-format.service.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.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/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.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-milimiters.vo.ts","../src/height.vo.ts","../src/hour-format.service.ts","../src/hour-schema.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute-schema.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.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-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding.adapter.ts","../src/rounding.port.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/stopwatch.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/timestamp-value.vo.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-grams.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
@@ -1,9 +1,9 @@
1
1
  import { DateRange } from "./date-range.vo";
2
- import { type TimestampType } from "./timestamp.vo";
2
+ import { Timestamp } from "./timestamp.vo";
3
3
  import { type WeekIsoIdType } from "./week-iso-id.vo";
4
4
  export declare class Week extends DateRange {
5
- static fromTimestamp(timestamp: TimestampType): Week;
6
- static fromNow(now: TimestampType): Week;
5
+ static fromTimestamp(timestamp: Timestamp): Week;
6
+ static fromNow(now: Timestamp): Week;
7
7
  static fromIsoId(isoId: WeekIsoIdType): Week;
8
8
  toIsoId(): WeekIsoIdType;
9
9
  previous(): Week;