Skip to content

Commit 3ea84e3

Browse files
authored
Merge pull request #565 from performant-software/bugfix/564-timeline-timezone
Prevent timeline timezone conversion issues (#564)
2 parents 09dd32b + 42fc338 commit 3ea84e3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/core-data/src/utils/Typesense.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ const getDate = (event: EventType) => {
133133

134134
if (_.isNumber(date)) {
135135
// Typesense date is a Unix timestamp, which is in seconds, so convert to ms
136-
return new Date(date * ONE_SECOND);
136+
const jsDate = new Date(date * ONE_SECOND);
137+
// prevent timezone errors by just using year, month, date
138+
return new Date(
139+
jsDate.getUTCFullYear(),
140+
jsDate.getUTCMonth(),
141+
jsDate.getUTCDate()
142+
);
137143
}
138144

139145
return date;

packages/storybook/src/core-data/FacetTimeline.stories.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,23 @@ export const ListView = () => {
199199
</>
200200
);
201201
};
202+
203+
// example of a single date at the exact beginning of the range, which
204+
// was causing errors due to timezone conversion
205+
const singleDate = {
206+
end_date: [-662688000, -631152000],
207+
end_year: [1949, 1950],
208+
name: 'African Progressive Association Founded',
209+
start_date: [-946771200, -915148800],
210+
start_year: [1940, 1941],
211+
uuid: '52f568cb-3036-478f-8a0c-62e93c1f0f20'
212+
};
213+
214+
export const SingleItem = () => (
215+
<FacetTimeline
216+
data={[singleDate]}
217+
range={{min: 1940, max: 1954}}
218+
refine={action('refine')}
219+
start={[1940, 1954]}
220+
/>
221+
);

0 commit comments

Comments
 (0)