@tmlmobilidade/dates 20260526.1648.32 → 20260527.947.18
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 +12 -0
- package/dist/dates.js +15 -0
- package/package.json +1 -1
package/dist/dates.d.ts
CHANGED
|
@@ -12,6 +12,13 @@ interface DatesConstructor {
|
|
|
12
12
|
};
|
|
13
13
|
unix_timestamp: UnixTimestamp;
|
|
14
14
|
}
|
|
15
|
+
export interface CalendarEntry {
|
|
16
|
+
date: string;
|
|
17
|
+
day_type: '1' | '2' | '3';
|
|
18
|
+
holiday: '0' | '1';
|
|
19
|
+
notes: string;
|
|
20
|
+
period: '1' | '2' | '3';
|
|
21
|
+
}
|
|
15
22
|
export declare class Dates {
|
|
16
23
|
static readonly STANDARD_WINDOW_HOURS = 10;
|
|
17
24
|
static get FORMATS(): {
|
|
@@ -88,6 +95,11 @@ export declare class Dates {
|
|
|
88
95
|
* @returns A new Dates object with the current date and time in the specified timezone.
|
|
89
96
|
*/
|
|
90
97
|
static now(timezone: 'local' | 'utc' | TimezoneIdentified): Dates;
|
|
98
|
+
/**
|
|
99
|
+
* Fetches calendar data from the public API
|
|
100
|
+
* Returns an empty array if the request fails
|
|
101
|
+
*/
|
|
102
|
+
static fetchCalendarData(): Promise<CalendarEntry[]>;
|
|
91
103
|
/**
|
|
92
104
|
* Returns the difference between this date and another date.
|
|
93
105
|
* @param other The other Dates object to compare with
|
package/dist/dates.js
CHANGED
|
@@ -152,6 +152,21 @@ export class Dates {
|
|
|
152
152
|
unix_timestamp: dateTime.toMillis(),
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Fetches calendar data from the public API
|
|
157
|
+
* Returns an empty array if the request fails
|
|
158
|
+
*/
|
|
159
|
+
static async fetchCalendarData() {
|
|
160
|
+
let calendarJson = [];
|
|
161
|
+
try {
|
|
162
|
+
const response = await fetch('https://go.carrismetropolitana.pt/api/dates/public');
|
|
163
|
+
calendarJson = !response.ok ? [] : await response.json();
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.error('Error fetching calendar data:', error);
|
|
167
|
+
}
|
|
168
|
+
return calendarJson;
|
|
169
|
+
}
|
|
155
170
|
/**
|
|
156
171
|
* Returns the difference between this date and another date.
|
|
157
172
|
* @param other The other Dates object to compare with
|