Method Deck / dates

Weekday of a date

Computes the day of the week for any proleptic Gregorian calendar date.

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 (year, month, day).
  2. Compute its day-number using the Hinnant days_from_civil algorithm (equivalent to a Julian Day Number offset), which counts whole days since 1970-01-01.
  3. Take the day-number modulo 7. 1970-01-01 has day-number 0 and was a Thursday, so the remainder indexes into the cycle starting at Thursday.
  4. Map the remainder to a weekday name using that calibrated cycle.

Constants

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"date":"2000-01-01"}Saturday
test vector: Unix epoch{"date":"1970-01-01"}Thursday
test vector: recent date{"date":"2024-01-01"}Monday

Published card