Skip to content

Commit

Permalink
Account for timezone offset between start/end time when calculating d…
Browse files Browse the repository at this point in the history
…uration (#34)
  • Loading branch information
tolu authored Dec 12, 2023
1 parent 0fbf79c commit e1e3750
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ export const toSeconds = (durationInput: Duration, startDate = new Date()) => {
const now = new Date(timestamp);
const then = end(duration, now);

// Account for timezone offset between start and end date
const tzStart = startDate.getTimezoneOffset();
const tzEnd = then.getTimezoneOffset();
let tzOffsetSeconds = (tzStart - tzEnd) * 60;

const seconds = (then.getTime() - now.getTime()) / 1000;
return seconds;
return seconds + tzOffsetSeconds;
};

export default {
Expand Down

0 comments on commit e1e3750

Please sign in to comment.