@tmlmobilidade/utils 20260615.1002.3 → 20260615.1437.21

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.
@@ -7,8 +7,9 @@ export interface PerformInTimeChunksItem {
7
7
  total: number;
8
8
  }
9
9
  export interface PerformInTimeChunksOptions {
10
+ endDate?: UnixTimestamp;
10
11
  onChunk: (chunk: PerformInTimeChunksItem) => Promise<void>;
11
12
  splitBy: DurationObjectUnits;
12
13
  startDate: UnixTimestamp;
13
14
  }
14
- export declare function performInTimeChunks({ onChunk, splitBy, startDate }: PerformInTimeChunksOptions): Promise<void>;
15
+ export declare function performInTimeChunks({ endDate, onChunk, splitBy, startDate }: PerformInTimeChunksOptions): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  /* * */
2
2
  import { Dates } from '@tmlmobilidade/dates';
3
3
  import { Interval } from 'luxon';
4
- export async function performInTimeChunks({ onChunk, splitBy, startDate }) {
4
+ export async function performInTimeChunks({ endDate, onChunk, splitBy, startDate }) {
5
5
  //
6
6
  // In order to sync both collections in a manageable way, due to the high volume of data,
7
7
  // it is necessary to divide the process into smaller blocks. Instead of syncing all documents at once,
@@ -9,12 +9,15 @@ export async function performInTimeChunks({ onChunk, splitBy, startDate }) {
9
9
  // Like this we can more easily compare the IDs in memory and sync only the missing documents.
10
10
  // More recent data is more important than older data, so we start syncing the most recent data first.
11
11
  // It makes sense to divide chunks by day, but this should be adjusted according to the volume of data in each chunk.
12
- const thirtySecondsAgo = Dates
13
- .now('Europe/Lisbon')
14
- .minus({ seconds: 30 });
15
- const earliestDataNeeded = Dates.fromUnixTimestamp(startDate);
12
+ const endDateValue = endDate
13
+ ? Dates
14
+ .fromUnixTimestamp(endDate)
15
+ : Dates
16
+ .now('Europe/Lisbon')
17
+ .minus({ seconds: 30 });
18
+ const startDateValue = Dates.fromUnixTimestamp(startDate);
16
19
  const allTimestampChunks = Interval
17
- .fromISO(`${earliestDataNeeded.iso}/${thirtySecondsAgo.iso}`)
20
+ .fromISO(`${startDateValue.iso}/${endDateValue.iso}`)
18
21
  .splitBy(splitBy)
19
22
  .map(interval => ({ end: interval.end.toMillis(), start: interval.start.toMillis() }))
20
23
  .sort((a, b) => b.start - a.start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20260615.1002.3",
3
+ "version": "20260615.1437.21",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"