@tmlmobilidade/go-utils-dates 20260828.1831.23 → 20260829.23.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.
package/dist/dates.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CalendarDate, DateFormat, type OperationalDateInt, type TimezoneIdentified, type
|
|
1
|
+
import { type CalendarDate, DateFormat, type OperationalDateInt, type TimezoneIdentified, type UnixMilliseconds } from '@tmlmobilidade/go-types-shared';
|
|
2
2
|
import { type DateObjectUnits, type DateTimeUnit, type DurationObjectUnits } from 'luxon';
|
|
3
3
|
interface DatesConstructor {
|
|
4
4
|
calendar_date: CalendarDate;
|
|
@@ -6,10 +6,10 @@ interface DatesConstructor {
|
|
|
6
6
|
js_date: Date;
|
|
7
7
|
operational_date_int: OperationalDateInt;
|
|
8
8
|
std_window: {
|
|
9
|
-
end:
|
|
10
|
-
start:
|
|
9
|
+
end: UnixMilliseconds;
|
|
10
|
+
start: UnixMilliseconds;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
unix_milliseconds: UnixMilliseconds;
|
|
13
13
|
}
|
|
14
14
|
export declare class Dates {
|
|
15
15
|
static readonly standardWindowHours = 10;
|
|
@@ -19,10 +19,10 @@ export declare class Dates {
|
|
|
19
19
|
js_date: Date;
|
|
20
20
|
operational_date_int: OperationalDateInt;
|
|
21
21
|
std_window: {
|
|
22
|
-
end:
|
|
23
|
-
start:
|
|
22
|
+
end: UnixMilliseconds;
|
|
23
|
+
start: UnixMilliseconds;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
unix_milliseconds: UnixMilliseconds;
|
|
26
26
|
constructor(params: DatesConstructor);
|
|
27
27
|
/**
|
|
28
28
|
* Creates a Dates object from a date/time string in a specific format.
|
|
@@ -64,7 +64,7 @@ export declare class Dates {
|
|
|
64
64
|
* @param millis The number of milliseconds since Unix epoch. Unix timestamp is always in UTC.
|
|
65
65
|
* @returns A new Dates object created from the milliseconds timestamp.
|
|
66
66
|
*/
|
|
67
|
-
static
|
|
67
|
+
static fromUnixMilliseconds(millis: number | UnixMilliseconds): Dates;
|
|
68
68
|
/**
|
|
69
69
|
* Creates a Dates object with the current date and time.
|
|
70
70
|
* @param timezone The timezone to set for the Dates object.
|
|
@@ -118,12 +118,12 @@ export declare class Dates {
|
|
|
118
118
|
*/
|
|
119
119
|
startOf(unit: DateTimeUnit): Dates;
|
|
120
120
|
/**
|
|
121
|
-
* Returns the time remaining until a given
|
|
121
|
+
* Returns the time remaining until a given unix_milliseconds (in ms) from now,
|
|
122
122
|
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
123
|
-
* @param
|
|
123
|
+
* @param unixMilliseconds The target timestamp in milliseconds
|
|
124
124
|
* @returns { minutes: number, hours: number, days: number }
|
|
125
125
|
*/
|
|
126
|
-
timeUntil(
|
|
126
|
+
timeUntil(unixMilliseconds: UnixMilliseconds): {
|
|
127
127
|
days: number;
|
|
128
128
|
hours: number;
|
|
129
129
|
minutes: number;
|
package/dist/dates.js
CHANGED
|
@@ -12,14 +12,14 @@ export class Dates {
|
|
|
12
12
|
js_date;
|
|
13
13
|
operational_date_int;
|
|
14
14
|
std_window;
|
|
15
|
-
|
|
15
|
+
unix_milliseconds;
|
|
16
16
|
constructor(params) {
|
|
17
17
|
this.calendar_date = params.calendar_date;
|
|
18
18
|
this.iso = params.iso ?? null;
|
|
19
19
|
this.js_date = params.js_date;
|
|
20
20
|
this.operational_date_int = params.operational_date_int;
|
|
21
21
|
this.std_window = params.std_window;
|
|
22
|
-
this.
|
|
22
|
+
this.unix_milliseconds = params.unix_milliseconds;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Creates a Dates object from a date/time string in a specific format.
|
|
@@ -39,7 +39,7 @@ export class Dates {
|
|
|
39
39
|
js_date: dateTime.toJSDate(),
|
|
40
40
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
41
41
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
42
|
-
|
|
42
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -56,7 +56,7 @@ export class Dates {
|
|
|
56
56
|
js_date: dateTime.toJSDate(),
|
|
57
57
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
58
58
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
59
|
-
|
|
59
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
@@ -74,7 +74,7 @@ export class Dates {
|
|
|
74
74
|
js_date: dateTime.toJSDate(),
|
|
75
75
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
76
76
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
77
|
-
|
|
77
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -94,7 +94,7 @@ export class Dates {
|
|
|
94
94
|
js_date: dateTime.toJSDate(),
|
|
95
95
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
96
96
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
97
|
-
|
|
97
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
@@ -112,7 +112,7 @@ export class Dates {
|
|
|
112
112
|
js_date: dateTime.toJSDate(),
|
|
113
113
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
114
114
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
115
|
-
|
|
115
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -120,7 +120,7 @@ export class Dates {
|
|
|
120
120
|
* @param millis The number of milliseconds since Unix epoch. Unix timestamp is always in UTC.
|
|
121
121
|
* @returns A new Dates object created from the milliseconds timestamp.
|
|
122
122
|
*/
|
|
123
|
-
static
|
|
123
|
+
static fromUnixMilliseconds(millis) {
|
|
124
124
|
const dateTime = DateTime
|
|
125
125
|
.fromMillis(millis)
|
|
126
126
|
.setZone('utc', { keepLocalTime: false });
|
|
@@ -130,7 +130,7 @@ export class Dates {
|
|
|
130
130
|
js_date: dateTime.toJSDate(),
|
|
131
131
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
132
132
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
133
|
-
|
|
133
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
@@ -148,7 +148,7 @@ export class Dates {
|
|
|
148
148
|
js_date: dateTime.toJSDate(),
|
|
149
149
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
150
150
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
151
|
-
|
|
151
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
@@ -181,7 +181,7 @@ export class Dates {
|
|
|
181
181
|
js_date: dateTime.toJSDate(),
|
|
182
182
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
183
183
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
184
|
-
|
|
184
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
@@ -201,7 +201,7 @@ export class Dates {
|
|
|
201
201
|
js_date: dateTime.toJSDate(),
|
|
202
202
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
203
203
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
204
|
-
|
|
204
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
@@ -221,7 +221,7 @@ export class Dates {
|
|
|
221
221
|
js_date: dateTime.toJSDate(),
|
|
222
222
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
223
223
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
224
|
-
|
|
224
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
@@ -241,7 +241,7 @@ export class Dates {
|
|
|
241
241
|
js_date: dateTime.toJSDate(),
|
|
242
242
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
243
243
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
244
|
-
|
|
244
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
@@ -264,7 +264,7 @@ export class Dates {
|
|
|
264
264
|
js_date: dateTime.toJSDate(),
|
|
265
265
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
266
266
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
267
|
-
|
|
267
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
@@ -284,19 +284,19 @@ export class Dates {
|
|
|
284
284
|
js_date: dateTime.toJSDate(),
|
|
285
285
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
286
286
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
287
|
-
|
|
287
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
291
|
-
* Returns the time remaining until a given
|
|
291
|
+
* Returns the time remaining until a given unix_milliseconds (in ms) from now,
|
|
292
292
|
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
293
|
-
* @param
|
|
293
|
+
* @param unixMilliseconds The target timestamp in milliseconds
|
|
294
294
|
* @returns { minutes: number, hours: number, days: number }
|
|
295
295
|
*/
|
|
296
|
-
timeUntil(
|
|
296
|
+
timeUntil(unixMilliseconds) {
|
|
297
297
|
// Calculate the difference in milliseconds
|
|
298
298
|
const now = Date.now();
|
|
299
|
-
const diffMs =
|
|
299
|
+
const diffMs = unixMilliseconds - now;
|
|
300
300
|
// Calculate the time remaining
|
|
301
301
|
const minutes = diffMs / (1000 * 60);
|
|
302
302
|
const hours = diffMs / (1000 * 60 * 60);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UnixMilliseconds } from '@tmlmobilidade/go-types-shared';
|
|
2
2
|
/**
|
|
3
3
|
* Splits a time interval into smaller intervals of a given duration.
|
|
4
4
|
* @param from The start timestamp of the interval.
|
|
@@ -6,11 +6,11 @@ import { type UnixTimestamp } from '@tmlmobilidade/go-types-shared';
|
|
|
6
6
|
* @param intervalHrs The duration of the intervals in hours.
|
|
7
7
|
* @returns An array of intervals.
|
|
8
8
|
*/
|
|
9
|
-
export declare function splitTimeIntervals(from:
|
|
9
|
+
export declare function splitTimeIntervals(from: UnixMilliseconds, to: UnixMilliseconds, intervalHrs: number): {
|
|
10
10
|
end: number & {
|
|
11
|
-
__brand: "
|
|
11
|
+
__brand: "UnixMilliseconds";
|
|
12
12
|
};
|
|
13
13
|
start: number & {
|
|
14
|
-
__brand: "
|
|
14
|
+
__brand: "UnixMilliseconds";
|
|
15
15
|
};
|
|
16
16
|
}[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import {
|
|
2
|
+
import { UnixMillisecondsSchema } from '@tmlmobilidade/go-types-shared';
|
|
3
3
|
/**
|
|
4
4
|
* Splits a time interval into smaller intervals of a given duration.
|
|
5
5
|
* @param from The start timestamp of the interval.
|
|
@@ -28,7 +28,7 @@ export function splitTimeIntervals(from, to, intervalHrs) {
|
|
|
28
28
|
// Handle the first, potentially shorter interval.
|
|
29
29
|
// If there is a remainder, create an interval with the remainder as the duration.
|
|
30
30
|
if (remainder > 0) {
|
|
31
|
-
const startTimestamp =
|
|
31
|
+
const startTimestamp = UnixMillisecondsSchema.parse(Math.max(from, endTimestamp - remainder));
|
|
32
32
|
finalIntervals.push({ end: endTimestamp, start: startTimestamp });
|
|
33
33
|
endTimestamp = startTimestamp;
|
|
34
34
|
}
|
|
@@ -37,7 +37,7 @@ export function splitTimeIntervals(from, to, intervalHrs) {
|
|
|
37
37
|
// If the end timestamp is greater than the start timestamp,
|
|
38
38
|
// create an interval with the duration of the interval.
|
|
39
39
|
while (endTimestamp > from) {
|
|
40
|
-
const startTimestamp =
|
|
40
|
+
const startTimestamp = UnixMillisecondsSchema.parse(Math.max(from, endTimestamp - intervalMs));
|
|
41
41
|
finalIntervals.push({ end: endTimestamp, start: startTimestamp });
|
|
42
42
|
endTimestamp = startTimestamp;
|
|
43
43
|
}
|