@bgord/tools 1.2.19 → 1.2.20

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.
@@ -4,6 +4,7 @@ export declare class Duration {
4
4
  private static readonly rounding;
5
5
  private readonly internal;
6
6
  static readonly MIN: Duration;
7
+ private static readonly NS_IN_MS;
7
8
  private static readonly MS_IN_SECOND;
8
9
  private static readonly MS_IN_MINUTE;
9
10
  private static readonly MS_IN_HOUR;
@@ -16,12 +17,14 @@ export declare class Duration {
16
17
  static Minutes(value: number): Duration;
17
18
  static Seconds(value: number): Duration;
18
19
  static Ms(value: number): Duration;
20
+ static Ns(value: number): Duration;
19
21
  get weeks(): number;
20
22
  get days(): number;
21
23
  get hours(): number;
22
24
  get minutes(): number;
23
25
  get seconds(): number;
24
26
  get ms(): DurationMsType;
27
+ get ns(): number;
25
28
  isLongerThan(another: Duration): boolean;
26
29
  isShorterThan(another: Duration): boolean;
27
30
  equals(other: Duration): boolean;
@@ -5,6 +5,7 @@ export class Duration {
5
5
  static rounding = new RoundingDecimalStrategy(2);
6
6
  internal;
7
7
  static MIN = Duration.Ms(1);
8
+ static NS_IN_MS = 1000000;
8
9
  static MS_IN_SECOND = 1_000;
9
10
  static MS_IN_MINUTE = 60 * Duration.MS_IN_SECOND;
10
11
  static MS_IN_HOUR = 60 * Duration.MS_IN_MINUTE;
@@ -31,6 +32,9 @@ export class Duration {
31
32
  static Ms(value) {
32
33
  return new Duration(value);
33
34
  }
35
+ static Ns(value) {
36
+ return new Duration(new RoundingToNearestStrategy().round(value / Duration.NS_IN_MS));
37
+ }
34
38
  get weeks() {
35
39
  return Duration.rounding.round(this.internal / Duration.MS_IN_WEEK);
36
40
  }
@@ -49,6 +53,9 @@ export class Duration {
49
53
  get ms() {
50
54
  return this.internal;
51
55
  }
56
+ get ns() {
57
+ return this.internal * Duration.NS_IN_MS;
58
+ }
52
59
  isLongerThan(another) {
53
60
  return this.internal > another.internal;
54
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -10,6 +10,7 @@ export class Duration {
10
10
 
11
11
  static readonly MIN = Duration.Ms(1);
12
12
 
13
+ private static readonly NS_IN_MS = 1000000;
13
14
  private static readonly MS_IN_SECOND = 1_000;
14
15
  private static readonly MS_IN_MINUTE = 60 * Duration.MS_IN_SECOND;
15
16
  private static readonly MS_IN_HOUR = 60 * Duration.MS_IN_MINUTE;
@@ -23,7 +24,6 @@ export class Duration {
23
24
  static Weeks(value: number): Duration {
24
25
  return new Duration(value * Duration.MS_IN_WEEK);
25
26
  }
26
-
27
27
  static Days(value: number): Duration {
28
28
  return new Duration(value * Duration.MS_IN_DAY);
29
29
  }
@@ -39,11 +39,13 @@ export class Duration {
39
39
  static Ms(value: number): Duration {
40
40
  return new Duration(value);
41
41
  }
42
+ static Ns(value: number): Duration {
43
+ return new Duration(new RoundingToNearestStrategy().round(value / Duration.NS_IN_MS));
44
+ }
42
45
 
43
46
  get weeks(): number {
44
47
  return Duration.rounding.round(this.internal / Duration.MS_IN_WEEK);
45
48
  }
46
-
47
49
  get days(): number {
48
50
  return Duration.rounding.round(this.internal / Duration.MS_IN_DAY);
49
51
  }
@@ -59,6 +61,9 @@ export class Duration {
59
61
  get ms(): DurationMsType {
60
62
  return this.internal;
61
63
  }
64
+ get ns(): number {
65
+ return this.internal * Duration.NS_IN_MS;
66
+ }
62
67
 
63
68
  isLongerThan(another: Duration): boolean {
64
69
  return this.internal > another.internal;