@bgord/tools 1.2.5 → 1.2.7

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.
@@ -1,4 +1,5 @@
1
1
  import { type DurationMsType } from "./duration-ms.vo";
2
+ import type { MultiplicationFactorType } from "./multiplication-factor.vo";
2
3
  export declare class Duration {
3
4
  private static readonly rounding;
4
5
  private readonly internal;
@@ -25,5 +26,6 @@ export declare class Duration {
25
26
  equals(other: Duration): boolean;
26
27
  add(another: Duration): Duration;
27
28
  subtract(another: Duration): Duration;
29
+ times(factor: MultiplicationFactorType): Duration;
28
30
  toAbsolute(): Duration;
29
31
  }
@@ -1,5 +1,5 @@
1
1
  import { DurationMs } from "./duration-ms.vo";
2
- import { RoundToDecimal } from "./rounding.adapter";
2
+ import { RoundToDecimal, RoundToNearest } from "./rounding.adapter";
3
3
  export class Duration {
4
4
  static rounding = new RoundToDecimal(2);
5
5
  internal;
@@ -62,6 +62,10 @@ export class Duration {
62
62
  subtract(another) {
63
63
  return Duration.Ms(this.internal - another.internal);
64
64
  }
65
+ times(factor) {
66
+ const rounding = new RoundToNearest();
67
+ return Duration.Ms(rounding.round(this.internal * factor));
68
+ }
65
69
  toAbsolute() {
66
70
  return Duration.Ms(Math.abs(this.internal));
67
71
  }
@@ -5,6 +5,8 @@ export declare class Timestamp {
5
5
  constructor(value: TimestampValueType);
6
6
  static fromValue(value: TimestampValueType): Timestamp;
7
7
  static fromNumber(value: number): Timestamp;
8
+ static fromDate(value: Date): Timestamp;
9
+ static fromDateLike(value: string): Timestamp;
8
10
  add(duration: Duration): Timestamp;
9
11
  subtract(duration: Duration): Timestamp;
10
12
  difference(another: Timestamp): Duration;
@@ -11,6 +11,12 @@ export class Timestamp {
11
11
  static fromNumber(value) {
12
12
  return new Timestamp(TimestampValue.parse(value));
13
13
  }
14
+ static fromDate(value) {
15
+ return Timestamp.fromNumber(value.getTime());
16
+ }
17
+ static fromDateLike(value) {
18
+ return Timestamp.fromNumber(new Date(value).getTime());
19
+ }
14
20
  add(duration) {
15
21
  return Timestamp.fromNumber(this.value + duration.ms);
16
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -27,7 +27,7 @@
27
27
  "@types/bun": "1.3.5",
28
28
  "@types/mime-types": "3.0.1",
29
29
  "cspell": "9.4.0",
30
- "knip": "5.77.1",
30
+ "knip": "5.78.0",
31
31
  "lefthook": "2.0.13",
32
32
  "lockfile-lint": "4.14.1",
33
33
  "only-allow": "1.2.2",
@@ -1,5 +1,6 @@
1
1
  import { DurationMs, type DurationMsType } from "./duration-ms.vo";
2
- import { RoundToDecimal } from "./rounding.adapter";
2
+ import type { MultiplicationFactorType } from "./multiplication-factor.vo";
3
+ import { RoundToDecimal, RoundToNearest } from "./rounding.adapter";
3
4
  import type { RoundingPort } from "./rounding.port";
4
5
 
5
6
  export class Duration {
@@ -73,6 +74,12 @@ export class Duration {
73
74
  return Duration.Ms(this.internal - another.internal);
74
75
  }
75
76
 
77
+ times(factor: MultiplicationFactorType): Duration {
78
+ const rounding = new RoundToNearest();
79
+
80
+ return Duration.Ms(rounding.round(this.internal * factor));
81
+ }
82
+
76
83
  toAbsolute(): Duration {
77
84
  return Duration.Ms(Math.abs(this.internal));
78
85
  }
@@ -12,6 +12,14 @@ export class Timestamp {
12
12
  return new Timestamp(TimestampValue.parse(value));
13
13
  }
14
14
 
15
+ static fromDate(value: Date): Timestamp {
16
+ return Timestamp.fromNumber(value.getTime());
17
+ }
18
+
19
+ static fromDateLike(value: string): Timestamp {
20
+ return Timestamp.fromNumber(new Date(value).getTime());
21
+ }
22
+
15
23
  add(duration: Duration): Timestamp {
16
24
  return Timestamp.fromNumber(this.value + duration.ms);
17
25
  }