@tmlmobilidade/go-utils-dates 20260905.1222.34 → 20260905.2252.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.js +12 -6
- package/package.json +1 -1
package/dist/dates.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { CALENDAR_DATE_FORMAT, OPERATIONAL_DATE_FORMAT } from '@tmlmobilidade/go-types-shared';
|
|
2
|
+
import { CALENDAR_DATE_FORMAT, OPERATIONAL_DATE_FORMAT, OperationalDateIntSchema } from '@tmlmobilidade/go-types-shared';
|
|
3
3
|
import { DateTime } from 'luxon';
|
|
4
4
|
import { DateFormatConfigMap } from './date-format.js';
|
|
5
5
|
/* * */
|
|
@@ -84,8 +84,13 @@ export class Dates {
|
|
|
84
84
|
* @returns A new Dates object created from the operational date.
|
|
85
85
|
*/
|
|
86
86
|
static fromOperationalDateInt(date, timezone) {
|
|
87
|
+
// Validate the date
|
|
88
|
+
const validatedDate = OperationalDateIntSchema.safeParse(date);
|
|
89
|
+
if (!validatedDate.success)
|
|
90
|
+
throw new Error(`Received an invalid operational date: ${date} - ${validatedDate.error.message}`);
|
|
91
|
+
// Create the date time object
|
|
87
92
|
const dateTime = DateTime
|
|
88
|
-
.fromFormat(String(
|
|
93
|
+
.fromFormat(String(validatedDate.data), OPERATIONAL_DATE_FORMAT)
|
|
89
94
|
.setZone(timezone, { keepLocalTime: true })
|
|
90
95
|
.set({ hour: 4, millisecond: 0, minute: 0, second: 0 }); // Start of the operational date
|
|
91
96
|
return new Dates({
|
|
@@ -370,9 +375,10 @@ export class Dates {
|
|
|
370
375
|
if (!isoDate)
|
|
371
376
|
throw new Error('ISO date is not set.');
|
|
372
377
|
const dateTime = DateTime.fromISO(isoDate, { setZone: true });
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
378
|
+
// Get the start and end of the standard window interval
|
|
379
|
+
const startMs = dateTime.minus({ hours: Dates.standardWindowHours }).startOf('hour').toMillis();
|
|
380
|
+
const endMs = dateTime.plus({ hours: Dates.standardWindowHours }).endOf('hour').toMillis();
|
|
381
|
+
// Return the start and end of the standard window interval
|
|
382
|
+
return { end: endMs, start: startMs };
|
|
377
383
|
}
|
|
378
384
|
}
|