Skip to content

Commit

Permalink
RC #291 - Adding more complete year calculation to FacetTimeline comp…
Browse files Browse the repository at this point in the history
…onent
  • Loading branch information
dleadbetter committed Aug 12, 2024
1 parent 87b10ea commit 6ed6e73
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/core-data/src/components/FacetTimeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ const FacetTimeline = (props: Props) => {

const ref = useRef();

/**
* Returns the year value for the passed event.
*
* @type {function(*): *}
*/
const getYear = useCallback((event) => {
let year;

const date = event.start_date?.start_date || event.end_date?.start_date;

if (date) {
year = new Date(date).getFullYear();
}

return year;
}, []);

/**
* Sets the new range and min/max values on the state.
*
Expand All @@ -95,7 +112,7 @@ const FacetTimeline = (props: Props) => {
const onLoad = useCallback((data) => {
setEvents(_.map(data.events, (event) => ({
...event,
year: new Date(event.start_date?.start_date).getFullYear()
year: getYear(event)
})));
}, []);

Expand Down

0 comments on commit 6ed6e73

Please sign in to comment.