Skip to content

Commit

Permalink
Fix daylight savings bug in Pinterest delta table tooltip (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgopal492 authored Dec 10, 2024
1 parent c09b091 commit b3877f3
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ import { getTooltipTimeFormatter } from '../utils/formatters';
import { DeltaDirection, DeltaTableColumn } from './types';

const getPreviousDate = (date: Date, offsetDays: number) => {
const previousDate = new Date(date);
previousDate.setDate(date.getDate() - offsetDays);
return previousDate;
// Convert the date to UTC time in milliseconds, subtract the offsetDays,
// and return the new date. (UTC conversion is needed to avoid daylight savings issues)
const time = Date.UTC(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
);
// subtract offsetDays from the time in milliseconds
const newTime = time - offsetDays * 24 * 60 * 60 * 1000;
const newDate = new Date(newTime);
return newDate;
};

export const getDateByTimeDelta = {
Expand Down

0 comments on commit b3877f3

Please sign in to comment.