Method Deck / dates

Day of year and days remaining

Computes a date's ordinal position within its calendar year and how many days are left in that year.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Parse the date as a proleptic Gregorian civil date.
  2. Convert the date and January 1 of the same year to Julian Day Numbers (Hinnant days_from_civil, cited above).
  3. day_of_year = JDN(date) - JDN(year, 1, 1) + 1.
  4. days_in_year = 366 if the year is a Gregorian leap year, else 365.
  5. days_remaining = days_in_year - day_of_year.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"date":"2024-03-01"}Day 61 of 366; 305 days remaining in the year
test vector: last day of a non-leap year{"date":"2023-12-31"}Day 365 of 365; 0 days remaining in the year
test vector: first day of year{"date":"2026-01-01"}Day 1 of 365; 364 days remaining in the year

Published card