@tmlmobilidade/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/calendar/periods/index.js +1 -1
- package/dist/calendar/rules/preview/affectedDates.js +1 -1
- package/dist/calendar/rules/preview/buildDayDetails.js +1 -1
- package/dist/calendar/rules/utils/date.js +1 -1
- package/dist/calendar/utils/index.js +1 -1
- package/dist/dates.d.ts +14 -14
- package/dist/dates.js +25 -25
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ export function convertRangeToKeysArray(start, end) {
|
|
|
14
14
|
const to = start < end ? end : start;
|
|
15
15
|
let current = datesFromCalendarKey(from);
|
|
16
16
|
const endDate = datesFromCalendarKey(to);
|
|
17
|
-
while (current.
|
|
17
|
+
while (current.unix_milliseconds <= endDate.unix_milliseconds) {
|
|
18
18
|
keys.push(calendarKey(current));
|
|
19
19
|
current = current.plus({ days: 1 });
|
|
20
20
|
}
|
|
@@ -97,7 +97,7 @@ export function getManualRuleAffectedDates(rule, ctx) {
|
|
|
97
97
|
}
|
|
98
98
|
let current = datesFromCalendarKey(from);
|
|
99
99
|
const end = datesFromCalendarKey(to);
|
|
100
|
-
while (current.
|
|
100
|
+
while (current.unix_milliseconds <= end.unix_milliseconds) {
|
|
101
101
|
const key = calendarKey(current);
|
|
102
102
|
if (ruleAppliesToCivilKey(rule, key, ctx, activePeriodDates)) {
|
|
103
103
|
affected.push(key);
|
|
@@ -89,7 +89,7 @@ function isTimeInRange(time, start, end) {
|
|
|
89
89
|
export function buildAffectedDaysDetails(startDate, endDate, allRules, periods, holidays, options) {
|
|
90
90
|
const affectedDays = new Map();
|
|
91
91
|
let currentDate = startDate.startOf('day');
|
|
92
|
-
while (currentDate.
|
|
92
|
+
while (currentDate.unix_milliseconds <= endDate.unix_milliseconds) {
|
|
93
93
|
const key = calendarKey(currentDate);
|
|
94
94
|
const dayDetails = buildDayScheduleDetail(key, allRules, periods, holidays, options?.events);
|
|
95
95
|
// Only include days that are "affected" (have active timepoints or applied rules)
|
|
@@ -50,7 +50,7 @@ export function buildOperationalDateRange(startDate, endDate) {
|
|
|
50
50
|
const dateRange = [];
|
|
51
51
|
let current = Dates.fromJSDate(startDate);
|
|
52
52
|
const end = Dates.fromJSDate(endDate);
|
|
53
|
-
while (current.
|
|
53
|
+
while (current.unix_milliseconds <= end.unix_milliseconds) {
|
|
54
54
|
dateRange.push(current.operational_date);
|
|
55
55
|
current = current.plus({ days: 1 });
|
|
56
56
|
}
|
|
@@ -83,7 +83,7 @@ export function eachCalendarDay(start, end, tz = DEFAULT_CAL_TZ) {
|
|
|
83
83
|
const out = [];
|
|
84
84
|
let current = Dates.fromFormat(`${start} 12:00`, 'yyyy-MM-dd HH:mm', tz);
|
|
85
85
|
const last = Dates.fromFormat(`${end} 12:00`, 'yyyy-MM-dd HH:mm', tz);
|
|
86
|
-
while (current.
|
|
86
|
+
while (current.unix_milliseconds <= last.unix_milliseconds) {
|
|
87
87
|
out.push(calendarKey(current, tz));
|
|
88
88
|
current = current.plus({ days: 1 });
|
|
89
89
|
}
|
package/dist/dates.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type DatesFormat } from './lib/date-format.js';
|
|
2
2
|
import { type TimezoneIdentified } from '@tmlmobilidade/go-types-shared';
|
|
3
|
-
import { type CalendarDate, type OperationalDate, type OperationalDateInt, type
|
|
3
|
+
import { type CalendarDate, type OperationalDate, type OperationalDateInt, type UnixMilliseconds } from '@tmlmobilidade/go-types-shared';
|
|
4
4
|
import { type DateObjectUnits, type DateTimeUnit, type DurationObjectUnits } from 'luxon';
|
|
5
5
|
interface DatesConstructor {
|
|
6
6
|
calendar_date: CalendarDate;
|
|
@@ -12,10 +12,10 @@ interface DatesConstructor {
|
|
|
12
12
|
operational_date: OperationalDate;
|
|
13
13
|
operational_date_int: OperationalDateInt;
|
|
14
14
|
std_window: {
|
|
15
|
-
end:
|
|
16
|
-
start:
|
|
15
|
+
end: UnixMilliseconds;
|
|
16
|
+
start: UnixMilliseconds;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
unix_milliseconds: UnixMilliseconds;
|
|
19
19
|
}
|
|
20
20
|
export interface CalendarEntry {
|
|
21
21
|
date: string;
|
|
@@ -39,10 +39,10 @@ export declare class Dates {
|
|
|
39
39
|
operational_date: OperationalDate;
|
|
40
40
|
operational_date_int: OperationalDateInt;
|
|
41
41
|
std_window: {
|
|
42
|
-
end:
|
|
43
|
-
start:
|
|
42
|
+
end: UnixMilliseconds;
|
|
43
|
+
start: UnixMilliseconds;
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
unix_milliseconds: UnixMilliseconds;
|
|
46
46
|
constructor(params: DatesConstructor);
|
|
47
47
|
static get FORMATS(): {
|
|
48
48
|
DATE_FULL: DatesFormat;
|
|
@@ -109,7 +109,7 @@ export declare class Dates {
|
|
|
109
109
|
* @param millis The number of milliseconds since Unix epoch. Unix timestamp is always in UTC.
|
|
110
110
|
* @returns A new Dates object created from the milliseconds timestamp.
|
|
111
111
|
*/
|
|
112
|
-
static
|
|
112
|
+
static fromUnixMilliseconds(millis: number | UnixMilliseconds): Dates;
|
|
113
113
|
/**
|
|
114
114
|
* Creates a Dates object with the current date and time.
|
|
115
115
|
* @param timezone The timezone to set for the Dates object.
|
|
@@ -168,23 +168,23 @@ export declare class Dates {
|
|
|
168
168
|
*/
|
|
169
169
|
startOf(unit: DateTimeUnit): Dates;
|
|
170
170
|
/**
|
|
171
|
-
* Returns the time remaining until a given
|
|
171
|
+
* Returns the time remaining until a given unix_milliseconds (in ms) from now,
|
|
172
172
|
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
173
|
-
* @param
|
|
173
|
+
* @param unixMilliseconds The target timestamp in milliseconds
|
|
174
174
|
* @returns { minutes: number, hours: number, days: number }
|
|
175
175
|
*/
|
|
176
|
-
timeUntil(
|
|
176
|
+
timeUntil(unixMilliseconds: UnixMilliseconds): {
|
|
177
177
|
days: number;
|
|
178
178
|
hours: number;
|
|
179
179
|
minutes: number;
|
|
180
180
|
};
|
|
181
181
|
/**
|
|
182
|
-
* Returns a human-readable, localized string for the time remaining until a given
|
|
183
|
-
* @param
|
|
182
|
+
* Returns a human-readable, localized string for the time remaining until a given unix_milliseconds (in ms) from now.
|
|
183
|
+
* @param unixMilliseconds The target timestamp in milliseconds
|
|
184
184
|
* @param locale Optional locale string (e.g., 'en', 'pt')
|
|
185
185
|
* @returns A localized string like "2 days, 3 hours, 15 minutes"
|
|
186
186
|
*/
|
|
187
|
-
timeUntilLocaleString(
|
|
187
|
+
timeUntilLocaleString(unixMilliseconds: UnixMilliseconds, locale?: 'en' | 'pt'): string;
|
|
188
188
|
/**
|
|
189
189
|
* Returns the date as a string in the specified format.
|
|
190
190
|
* @param format The format string (see Luxon tokens documentation)
|
package/dist/dates.js
CHANGED
|
@@ -19,7 +19,7 @@ export class Dates {
|
|
|
19
19
|
operational_date;
|
|
20
20
|
operational_date_int;
|
|
21
21
|
std_window;
|
|
22
|
-
|
|
22
|
+
unix_milliseconds;
|
|
23
23
|
constructor(params) {
|
|
24
24
|
this.calendar_date = params.calendar_date;
|
|
25
25
|
this.iso = params.iso ?? null;
|
|
@@ -27,7 +27,7 @@ export class Dates {
|
|
|
27
27
|
this.operational_date = params.operational_date;
|
|
28
28
|
this.operational_date_int = params.operational_date_int;
|
|
29
29
|
this.std_window = params.std_window;
|
|
30
|
-
this.
|
|
30
|
+
this.unix_milliseconds = params.unix_milliseconds;
|
|
31
31
|
}
|
|
32
32
|
static get FORMATS() { return FORMATS; }
|
|
33
33
|
static get TIMEZONE_LIST() { return TimezoneIdentifiedValues; }
|
|
@@ -51,7 +51,7 @@ export class Dates {
|
|
|
51
51
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
52
52
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
53
53
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
54
|
-
|
|
54
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
@@ -69,7 +69,7 @@ export class Dates {
|
|
|
69
69
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
70
70
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
71
71
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
72
|
-
|
|
72
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -88,7 +88,7 @@ export class Dates {
|
|
|
88
88
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
89
89
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
90
90
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
91
|
-
|
|
91
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
@@ -109,7 +109,7 @@ export class Dates {
|
|
|
109
109
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
110
110
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
111
111
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
112
|
-
|
|
112
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
@@ -130,7 +130,7 @@ export class Dates {
|
|
|
130
130
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
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
|
/**
|
|
@@ -149,7 +149,7 @@ export class Dates {
|
|
|
149
149
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
150
150
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
151
151
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
152
|
-
|
|
152
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
@@ -157,7 +157,7 @@ export class Dates {
|
|
|
157
157
|
* @param millis The number of milliseconds since Unix epoch. Unix timestamp is always in UTC.
|
|
158
158
|
* @returns A new Dates object created from the milliseconds timestamp.
|
|
159
159
|
*/
|
|
160
|
-
static
|
|
160
|
+
static fromUnixMilliseconds(millis) {
|
|
161
161
|
const dateTime = DateTime
|
|
162
162
|
.fromMillis(millis)
|
|
163
163
|
.setZone('utc', { keepLocalTime: false });
|
|
@@ -168,7 +168,7 @@ export class Dates {
|
|
|
168
168
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
169
169
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
170
170
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
171
|
-
|
|
171
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
@@ -187,7 +187,7 @@ export class Dates {
|
|
|
187
187
|
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
188
188
|
operational_date_int: this.prototype.getOperationalDateInt(dateTime.toISO()),
|
|
189
189
|
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
190
|
-
|
|
190
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
@@ -236,7 +236,7 @@ export class Dates {
|
|
|
236
236
|
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
237
237
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
238
238
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
239
|
-
|
|
239
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
/**
|
|
@@ -257,7 +257,7 @@ export class Dates {
|
|
|
257
257
|
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
258
258
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
259
259
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
260
|
-
|
|
260
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
@@ -278,7 +278,7 @@ export class Dates {
|
|
|
278
278
|
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
279
279
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
280
280
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
281
|
-
|
|
281
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
@@ -299,7 +299,7 @@ export class Dates {
|
|
|
299
299
|
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
300
300
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
301
301
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
302
|
-
|
|
302
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
@@ -323,7 +323,7 @@ export class Dates {
|
|
|
323
323
|
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
324
324
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
325
325
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
326
|
-
|
|
326
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
329
|
/**
|
|
@@ -344,19 +344,19 @@ export class Dates {
|
|
|
344
344
|
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
345
345
|
operational_date_int: this.getOperationalDateInt(dateTime.toISO()),
|
|
346
346
|
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
347
|
-
|
|
347
|
+
unix_milliseconds: dateTime.toMillis(),
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
|
-
* Returns the time remaining until a given
|
|
351
|
+
* Returns the time remaining until a given unix_milliseconds (in ms) from now,
|
|
352
352
|
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
353
|
-
* @param
|
|
353
|
+
* @param unixMilliseconds The target timestamp in milliseconds
|
|
354
354
|
* @returns { minutes: number, hours: number, days: number }
|
|
355
355
|
*/
|
|
356
|
-
timeUntil(
|
|
356
|
+
timeUntil(unixMilliseconds) {
|
|
357
357
|
// Calculate the difference in milliseconds
|
|
358
358
|
const now = Date.now();
|
|
359
|
-
const diffMs =
|
|
359
|
+
const diffMs = unixMilliseconds - now;
|
|
360
360
|
// Calculate the time remaining
|
|
361
361
|
const minutes = diffMs / (1000 * 60);
|
|
362
362
|
const hours = diffMs / (1000 * 60 * 60);
|
|
@@ -365,14 +365,14 @@ export class Dates {
|
|
|
365
365
|
return { days, hours, minutes };
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
|
-
* Returns a human-readable, localized string for the time remaining until a given
|
|
369
|
-
* @param
|
|
368
|
+
* Returns a human-readable, localized string for the time remaining until a given unix_milliseconds (in ms) from now.
|
|
369
|
+
* @param unixMilliseconds The target timestamp in milliseconds
|
|
370
370
|
* @param locale Optional locale string (e.g., 'en', 'pt')
|
|
371
371
|
* @returns A localized string like "2 days, 3 hours, 15 minutes"
|
|
372
372
|
*/
|
|
373
|
-
timeUntilLocaleString(
|
|
373
|
+
timeUntilLocaleString(unixMilliseconds, locale = 'pt') {
|
|
374
374
|
const now = Date.now();
|
|
375
|
-
const diffMs =
|
|
375
|
+
const diffMs = unixMilliseconds - now;
|
|
376
376
|
const parts = [];
|
|
377
377
|
if (diffMs < 60 * 1000) {
|
|
378
378
|
return locale === 'en' ? 'Arriving' : 'A Chegar';
|