Yearly time scale in newick files & leap years

A rather minor point, but I see that often the time scale in Nextstrain downloaded trees (e.g. newick/nexus files) is quoted in years since the present. I want to convert this to days. Do I need to take into account the fact that 2020 was a leap year (e.g. by using a proper date conversion library), or in the Nexstrain pipeline is the conversion from day of submission (or day of sampling) to fractions-of-a-year done by simply dividing by 365 regardless of the year (in which case I assume I can get back to days by simply multiplying by 365).


If I understand correctly, you are looking for something to convert the decimal part of a numeric date (e.g. .124 in 2023.124) to a month+day representation. There are a few functions in the TreeTime package that can help (TreeTime is a dependency of Augur, the package used to generate tree files in Nextstrain analyses). An example snippet that converts a date to numeric form and back to month/day:

import datetime
from treetime.utils import numeric_date, datetime_from_numeric

numeric_date(, 2, 15))
# 2023.1246575342466

date = datetime_from_numeric(2023.1246575342466)
# datetime.datetime(2023, 2, 15, 0, 0)

# (2, 15)

As for your concern about the number of days being different for leap years, that is handled in both treetime.utils.numeric_date (src) and treetime.utils.datetime_from_numeric (src).

– Victor