Skip to content

Commit

Permalink
fat/AN-4385 make padding calculation for HOUR interval timezone aware (
Browse files Browse the repository at this point in the history
…#104)

* make start timestamp timezone aware

* update Changelog

* fix test comment
  • Loading branch information
MGJamJam authored Oct 11, 2024
1 parent 071d1cd commit b1c8d74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Development

### Fix

- wrong padding of timeseries data for `HOUR` interval for timezones with minute offsets

## 1.3.0

### Added
Expand Down
6 changes: 3 additions & 3 deletions src/utils/dataUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ describe('calculateTimeSeriesStartTimestamp', () => {

it('should return correct timestamp for HOUR interval', () => {
//arrange
const referenceDataTimestamp = 1720598400000; // Wednesday, 10 July 2024 08:00:00
const intervalStartTimestamp = 1720591381300; // Wednesday, 10 July 2024 03:03:01.300
const referenceDataTimestamp = 1720600200000; // Wednesday, 10 July 2024 08:30:00
const intervalStartTimestamp = 1720591381300; // Wednesday, 10 July 2024 06:03:01.300

//act
const result = calculateTimeSeriesStartTimestamp(referenceDataTimestamp, intervalStartTimestamp, 'HOUR');

//assert
expect(result).toEqual(1720591200000); // Wednesday, 10 July 2024 06:00:00
expect(result).toEqual(1720593000000); // Wednesday, 10 July 2024 06:30:00
});

it('should return correct timestamp for DAY interval', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/dataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export function calculateTimeSeriesStartTimestamp(
case 'MINUTE':
return intervalStartDate.setSeconds(0, 0);
case 'HOUR':
return intervalStartDate.setMinutes(0, 0, 0);
// minutes set because of timezones that have a minutes offset
return intervalStartDate.setMinutes(referenceDataDate.getMinutes(), 0, 0);
case 'DAY':
return intervalStartDate.setHours(referenceDataDate.getHours(), referenceDataDate.getMinutes(), 0, 0);
case 'MONTH':
Expand Down

0 comments on commit b1c8d74

Please sign in to comment.