@tmlmobilidade/go-utils-dates 20260829.1122.26 → 20260829.1307.28

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.
@@ -1,12 +1,17 @@
1
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
+ * This function returns an array of `TimeInterval` objects, where the start timestamp
5
+ * is always before the end timestamp, no matter the specified order. This is to ensure
6
+ * clarity when using these intervals in database queries, with `$gte`-like operands.
7
+ * If you are going backwards in time, you are responsible for adpating your queries to the correct order.
4
8
  * @param from The start timestamp of the interval.
5
9
  * @param to The end timestamp of the interval.
6
10
  * @param intervalHrs The duration of the intervals in hours.
7
- * @returns An array of intervals.
11
+ * @param order The order of the intervals.
12
+ * @returns An array of `TimeInterval` objects, where the start timestamp is always before the end timestamp.
8
13
  */
9
- export declare function splitTimeIntervals(from: UnixMilliseconds, to: UnixMilliseconds, intervalHrs: number): {
14
+ export declare function splitTimeIntervals(from: UnixMilliseconds, to: UnixMilliseconds, intervalHrs: number, order: 'asc' | 'desc'): {
10
15
  end: number & {
11
16
  __brand: "UnixMilliseconds";
12
17
  };
@@ -2,12 +2,17 @@
2
2
  import { UnixMillisecondsSchema } from '@tmlmobilidade/go-types-shared';
3
3
  /**
4
4
  * Splits a time interval into smaller intervals of a given duration.
5
+ * This function returns an array of `TimeInterval` objects, where the start timestamp
6
+ * is always before the end timestamp, no matter the specified order. This is to ensure
7
+ * clarity when using these intervals in database queries, with `$gte`-like operands.
8
+ * If you are going backwards in time, you are responsible for adpating your queries to the correct order.
5
9
  * @param from The start timestamp of the interval.
6
10
  * @param to The end timestamp of the interval.
7
11
  * @param intervalHrs The duration of the intervals in hours.
8
- * @returns An array of intervals.
12
+ * @param order The order of the intervals.
13
+ * @returns An array of `TimeInterval` objects, where the start timestamp is always before the end timestamp.
9
14
  */
10
- export function splitTimeIntervals(from, to, intervalHrs) {
15
+ export function splitTimeIntervals(from, to, intervalHrs, order) {
11
16
  //
12
17
  //
13
18
  // Validate the input timestamps
@@ -42,6 +47,10 @@ export function splitTimeIntervals(from, to, intervalHrs) {
42
47
  endTimestamp = startTimestamp;
43
48
  }
44
49
  //
45
- // Return the intervals in reverse order.
46
- return finalIntervals.reverse();
50
+ // Return the intervals in the desired order.
51
+ // Since this function is calculating the intervals in descending order,
52
+ // we need to reverse the final array when going in ascending mode.
53
+ if (order === 'asc')
54
+ return finalIntervals.reverse();
55
+ return finalIntervals;
47
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-utils-dates",
3
- "version": "20260829.1122.26",
3
+ "version": "20260829.1307.28",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"