Skip to content

Commit

Permalink
Merge pull request #627 from nextstrain/negative_dates
Browse files Browse the repository at this point in the history
make calendarToNumeric parse negative dates
  • Loading branch information
jameshadfield committed Aug 17, 2018
2 parents e24cde9 + 16c0650 commit 2bb17f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/components/info/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ const pluralise = (word, n) => {
};

const styliseDateRange = (dateStr) => {
// 2012-01-22
const fields = dateStr.split('-');
return `${months[fields[1]]} ${fields[0]}`;
// 2012-01-22
if (fields.length==3){
return `${months[fields[1]]} ${fields[0]}`;
}else{ // other cases like negative numbers
return dateStr;
}
};

const getNumSelectedTips = (nodes, visibility) => {
Expand Down
14 changes: 11 additions & 3 deletions src/util/dateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ const dateScale = scaleTime()
.range([2000, 2100]);

export const numericToCalendar = (numDate) => {
if (numDate<0){
return Math.round(numDate).toString();
}
const d3Date = dateScale.invert(numDate);
const calDate = dateFormatter(d3Date);
return calDate;
};

export const calendarToNumeric = (calDate) => {
const d3Date = dateParser(calDate);
const numDate = dateScale(d3Date);
return numDate;
if (calDate[0]==='-'){
const pieces = calDate.substring(1).split('-');
return -parseFloat(pieces[0]);
}else{
const d3Date = dateParser(calDate);
const numDate = dateScale(d3Date);
return numDate;
}
};

export const currentNumDate = () => {
Expand Down

0 comments on commit 2bb17f0

Please sign in to comment.