Skip to content

Commit

Permalink
Merge pull request #1909 from nextstrain/james/fix-root-date-bug
Browse files Browse the repository at this point in the history
[dates] handle 0-99CE root-node dates
  • Loading branch information
jameshadfield authored Nov 18, 2024
2 parents 7ec0222 + ca0e82a commit d7dfc68
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/util/dateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const numericToDateObject = (numDate) => {
const year = parseInt(numDate, 10);
const nDaysInYear = isLeapYear(year) ? 366 : 365;
const nDays = fracPart * nDaysInYear;
const date = new Date((new Date(year, 0, 1)).getTime() + nDays*24*60*60*1000);
const yearObj = new Date(year, 0, 1);
if (year<100) yearObj.setFullYear(year);
const date = new Date(yearObj.getTime() + nDays*24*60*60*1000);
return date;
};

Expand Down Expand Up @@ -130,8 +132,12 @@ export const getPreviousDate = (unit, date) => {
case "DECADE":
// decades start at "nice" numbers - i.e. multiples of 5 -- e.g. 2014 -> 2010, 2021 -> 2020
return new Date(Math.floor((date.getFullYear())/5)*5, 0, 1, 12);
case "CENTURY":
return new Date(Math.floor((date.getFullYear())/100)*100, 0, 1, 12);
case "CENTURY": {
const year = Math.floor((date.getFullYear())/100)*100;
const ret = new Date(year, 0, 1, 12);
ret.setFullYear(year);
return ret
}
default:
console.error("Unknown unit for `advanceDateTo`:", unit);
return dateClone;
Expand Down

0 comments on commit d7dfc68

Please sign in to comment.