@tmlmobilidade/go-utils-dates 20260916.1655.43 → 20260916.1720.37

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.
@@ -0,0 +1,25 @@
1
+ import { type OperationalDateInt, type OperationalTime, type TimezoneIdentified, type UnixMilliseconds } from '@tmlmobilidade/go-types-shared';
2
+ interface FromOperationalDateTimeToUnixMillisecondsParams {
3
+ /**
4
+ * The operational date to convert.
5
+ * @example '20260101' or '2026-01-01'
6
+ */
7
+ operational_date: OperationalDateInt;
8
+ /**
9
+ * The operational time to convert.
10
+ * @example '23:00:00' or '26:30:00'
11
+ */
12
+ operational_time: OperationalTime;
13
+ /**
14
+ * The timezone to use for the conversion.
15
+ * @example 'Europe/Lisbon' or 'Spain/Madrid'
16
+ */
17
+ timezone: TimezoneIdentified;
18
+ }
19
+ /**
20
+ * Convert the combination of an operational date and an operational time to a Unix timestamp.
21
+ * @param params The parameters for the conversion.
22
+ * @returns The given time and date as a Unix timestamp.
23
+ */
24
+ export declare function fromOperationalDateTimeToUnixMilliseconds(params: FromOperationalDateTimeToUnixMillisecondsParams): UnixMilliseconds;
25
+ export {};
@@ -0,0 +1,36 @@
1
+ /* * */
2
+ import { OperationalDateIntSchema, OperationalTimeSchema, TimezoneIdentifiedSchema } from '@tmlmobilidade/go-types-shared';
3
+ import { Dates } from '../dates.js';
4
+ /**
5
+ * Convert the combination of an operational date and an operational time to a Unix timestamp.
6
+ * @param params The parameters for the conversion.
7
+ * @returns The given time and date as a Unix timestamp.
8
+ */
9
+ export function fromOperationalDateTimeToUnixMilliseconds(params) {
10
+ //
11
+ //
12
+ // Verify if all params are provided
13
+ if (!params)
14
+ throw new Error(`[fromOperationalDateTimeToUnixMilliseconds()] No parameters provided. params: ${params}`);
15
+ if (!params.operational_time)
16
+ throw new Error(`[fromOperationalDateTimeToUnixMilliseconds()] No operational time provided. params: ${params}`);
17
+ if (!params.operational_date)
18
+ throw new Error(`[fromOperationalDateTimeToUnixMilliseconds()] No operational date provided. params: ${params}`);
19
+ if (!params.timezone)
20
+ throw new Error(`[fromOperationalDateTimeToUnixMilliseconds()] No timezone provided. params: ${params}`);
21
+ //
22
+ // Validate each required param
23
+ const validatedOperationalTime = OperationalTimeSchema.parse(params.operational_time);
24
+ const validatedOperationalDate = OperationalDateIntSchema.parse(params.operational_date);
25
+ const validatedTimezone = TimezoneIdentifiedSchema.parse(params.timezone);
26
+ //
27
+ // Extract the individual components of the time string (HH:MM:SS)
28
+ const [hours, minutes, seconds] = validatedOperationalTime.split(':').map(Number);
29
+ //
30
+ // Convert the combination of the time and date to a Unix timestamp
31
+ return Dates
32
+ .fromOperationalDateInt(validatedOperationalDate, validatedTimezone)
33
+ .set({ hour: hours, minute: minutes, second: seconds })
34
+ .unix_milliseconds;
35
+ }
36
+ ;
@@ -1,2 +1,3 @@
1
1
  export * from './dates-from-range.js';
2
+ export * from './from-operational-date-time-to-unix-milliseconds.js';
2
3
  export * from './split-time-intervals.js';
@@ -1,2 +1,3 @@
1
1
  export * from './dates-from-range.js';
2
+ export * from './from-operational-date-time-to-unix-milliseconds.js';
2
3
  export * from './split-time-intervals.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-utils-dates",
3
- "version": "20260916.1655.43",
3
+ "version": "20260916.1720.37",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"