@bgord/tools 1.1.0 → 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.
Files changed (49) hide show
  1. package/dist/age.vo.d.ts +5 -5
  2. package/dist/age.vo.js +5 -5
  3. package/dist/clock.vo.d.ts +2 -2
  4. package/dist/clock.vo.js +3 -3
  5. package/dist/date-calculator.service.d.ts +5 -5
  6. package/dist/date-calculator.service.js +6 -9
  7. package/dist/date-range.vo.d.ts +6 -6
  8. package/dist/date-range.vo.js +1 -1
  9. package/dist/day.vo.d.ts +5 -3
  10. package/dist/day.vo.js +8 -5
  11. package/dist/hour.vo.d.ts +4 -2
  12. package/dist/hour.vo.js +6 -2
  13. package/dist/minute.vo.d.ts +4 -2
  14. package/dist/minute.vo.js +6 -2
  15. package/dist/month.vo.d.ts +5 -3
  16. package/dist/month.vo.js +10 -7
  17. package/dist/quarter.vo.d.ts +5 -3
  18. package/dist/quarter.vo.js +9 -6
  19. package/dist/rate-limiter.service.d.ts +3 -3
  20. package/dist/rate-limiter.service.js +1 -3
  21. package/dist/relative-date.vo.d.ts +3 -3
  22. package/dist/relative-date.vo.js +1 -1
  23. package/dist/stopwatch.service.d.ts +3 -3
  24. package/dist/stopwatch.service.js +2 -3
  25. package/dist/timestamp.vo.d.ts +13 -12
  26. package/dist/timestamp.vo.js +10 -6
  27. package/dist/week.vo.d.ts +5 -3
  28. package/dist/week.vo.js +11 -8
  29. package/dist/weekday.vo.d.ts +4 -2
  30. package/dist/weekday.vo.js +6 -2
  31. package/dist/year.vo.d.ts +5 -3
  32. package/dist/year.vo.js +11 -8
  33. package/package.json +2 -2
  34. package/src/age.vo.ts +6 -6
  35. package/src/clock.vo.ts +4 -4
  36. package/src/date-calculator.service.ts +7 -11
  37. package/src/date-range.vo.ts +8 -8
  38. package/src/day.vo.ts +12 -7
  39. package/src/hour.vo.ts +8 -3
  40. package/src/minute.vo.ts +8 -3
  41. package/src/month.vo.ts +14 -9
  42. package/src/quarter.vo.ts +13 -8
  43. package/src/rate-limiter.service.ts +5 -7
  44. package/src/relative-date.vo.ts +5 -5
  45. package/src/stopwatch.service.ts +4 -4
  46. package/src/timestamp.vo.ts +20 -16
  47. package/src/week.vo.ts +15 -10
  48. package/src/weekday.vo.ts +8 -3
  49. package/src/year.vo.ts +15 -10
package/src/weekday.vo.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Timestamp } from "./timestamp.vo";
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 fromUtcTimestamp(timestamp: Timestamp, formatter?: WeekdayFormatter): Weekday {
56
- const dayZeroBased = new Date(timestamp.get()).getUTCDay(); // 0..6
56
+ static fromTimestamp(timestamp: TimestampVO, formatter?: WeekdayFormatter): Weekday {
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,17 +1,22 @@
1
1
  import { addYears, endOfYear, getYear, startOfYear } from "date-fns";
2
2
  import { DateRange } from "./date-range.vo";
3
- import { Timestamp } from "./timestamp.vo";
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 {
7
- static fromTimestamp(timestamp: Timestamp): Year {
8
- const start = Timestamp.fromNumber(startOfYear(timestamp.get()).getTime());
9
- const end = Timestamp.fromNumber(endOfYear(timestamp.get()).getTime());
8
+ static fromTimestamp(timestamp: TimestampVO): Year {
9
+ const start = TimestampVO.fromNumber(startOfYear(timestamp.ms).getTime());
10
+ const end = TimestampVO.fromNumber(endOfYear(timestamp.ms).getTime());
10
11
 
11
12
  return new Year(start, end);
12
13
  }
13
14
 
14
- static fromNow(now: Timestamp): Year {
15
+ static fromTimestampValue(timestamp: TimestampValueType): Year {
16
+ return Year.fromTimestamp(TimestampVO.fromValue(timestamp));
17
+ }
18
+
19
+ static fromNow(now: TimestampVO): Year {
15
20
  return Year.fromTimestamp(now);
16
21
  }
17
22
 
@@ -22,15 +27,15 @@ export class Year extends DateRange {
22
27
  static fromIsoId(isoId: YearIsoIdType): Year {
23
28
  const reference = Date.UTC(Number(isoId));
24
29
 
25
- return Year.fromTimestamp(Timestamp.fromNumber(reference));
30
+ return Year.fromTimestamp(TimestampVO.fromNumber(reference));
26
31
  }
27
32
 
28
33
  toIsoId(): YearIsoIdType {
29
- return YearIsoId.parse(String(getYear(this.getStart().get())));
34
+ return YearIsoId.parse(String(getYear(this.getStart().ms)));
30
35
  }
31
36
 
32
37
  isLeapYear(): boolean {
33
- const year = getYear(this.getStart().get());
38
+ const year = getYear(this.getStart().ms);
34
39
 
35
40
  return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
36
41
  }
@@ -44,9 +49,9 @@ export class Year extends DateRange {
44
49
  }
45
50
 
46
51
  shift(count: number): Year {
47
- const shifted = addYears(this.getStart().get(), count).getTime();
52
+ const shifted = addYears(this.getStart().ms, count).getTime();
48
53
 
49
- return Year.fromTimestamp(Timestamp.fromNumber(shifted));
54
+ return Year.fromTimestamp(TimestampVO.fromNumber(shifted));
50
55
  }
51
56
 
52
57
  toString(): string {