Skip to content

Commit

Permalink
UICHKIN-420 - Time offset issue when crossing DST boundary. (#620)
Browse files Browse the repository at this point in the history
* remove DST compensation code

* specify expectation values via moment api to apply expected UTC offsets

* Update CHANGELOG.md
  • Loading branch information
JohnC-80 authored Mar 19, 2024
1 parent a4e099e commit 69aa418
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* UI tests replacement with RTL/Jest for view CheckIn. Refs UICHKIN-287.
* UI tests replacement with RTL/Jest for Scan component. Refs UICHKIN-289.
* Add support for displaySummary token for Staff Slips. Refs UICHKIN-415.
* Remove DST boundary adjustment for item return time. Refs UICHKIN-420.

## [9.0.1] (https://github.com/folio-org/ui-checkin/tree/v9.0.1) (2023-10-23)
[Full Changelog](https://github.com/folio-org/ui-checkin/compare/v9.0.0...v9.0.1)
Expand Down
15 changes: 0 additions & 15 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,6 @@ export function buildDateTime(date, time, timezone, now) {
const formattedTime = moment(time, ['HH:mm', 'HH:mm a']).format('HH:mm');
const effectiveReturnDate = moment.tz(`${formattedDate}T${formattedTime}`, timezone);

// Check for DST offset. 'time' is passed in adjusted to UTC from whatever time is specified in
// the picker before being converted to a date/time in the local timezone. This works fine if
// there is no difference between the UTC offset *now* and the offset at a date/time specified
// to count items as returned. If there is, due to a change from daylight savings time to standard
// time between the two dates, the recorded time will be an hour off. Unless we do somethng
// like this:
const inDstNow = now.isDST();
const inDstThen = effectiveReturnDate.isDST();

if (inDstNow && !inDstThen) {
effectiveReturnDate.add(1, 'hours');
} else if (!inDstNow && inDstThen) {
effectiveReturnDate.subtract(1, 'hours');
}

return effectiveReturnDate.toISOString();
} else {
return moment(now).toISOString();
Expand Down
15 changes: 11 additions & 4 deletions src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,31 @@ describe('buildDateTime', () => {
expect(v).toMatch('2021-02-14T17:14:00.000Z');
});

it('given an effective return date before DST, returns an ISO-8601 string', () => {
it('given an effective return date in non-DST, currenty in DST, returns an ISO-8601 string', () => {
const d = '2021-03-13';
const t = '12:14:00';
const z = 'America/New_York';

const now = moment('2021-03-14T12:14:00').tz(z);
const v = buildDateTime(d, t, z, now);

expect(v).toMatch('2021-03-13T18:14:00.000Z');
// America/New_York is offset -4 hrs in DST, -5 hours in non-DST.
// expect to match the non-DST offset of 5 hours in UTC time...
const expected = moment.tz(`${d}T${t}`, 'UTC').add(5, 'hours').toISOString();
expect(v).toMatch(expected);
});

it('given an effective return date after DST, returns an ISO-8601 string', () => {
it('given an effective return date in DST, currently non-DST, returns an ISO-8601 string', () => {
const d = '2021-11-06';
const t = '12:14:00';
const z = 'America/New_York';
const now = moment('2021-11-07T12:14:00').tz(z);
const v = buildDateTime(d, t, z, now);

expect(v).toMatch('2021-11-06T15:14:00.000Z');
// America/New_York is offset -4 hrs in DST, -5 hours in non-DST.
// expect to match the DST offset of 4 hours in UTC time...
const expected = moment.tz(`${d}T${t}`, 'UTC').add(4, 'hours').toISOString();
expect(v).toMatch(expected);
});
});

Expand Down

0 comments on commit 69aa418

Please sign in to comment.