time.calendars
calendar questions: weekdays, business days, holidays, week numbers, month grids, cron schedules, zodiac signs
Answers questions about the calendar rather than the clock: which weekday a date is, which week or quarter, how many business days apart, which days are holidays, a month grid, and when a cron schedule fires.
Tags: time
weekday_numthe day of the week as a number, from 1 for Monday to 7 for Sundayday_of_yearwhich day of the year it is, from 1 to 366iso_weekthe week number by the ISO standard used in Europe and businessweek_numthe week number when weeks start on first_day, where week 1 is the week with January 1year_fracthe length of time from a to b as a number of years, by a day-count basisquarterwhich quarter of the year the date is in, 1 to 4leap_yearwhether the year is a leap yeardays_in_monthhow many days the date’s month hasdays_in_yearhow many days the date’s year has, 365 or 366start_ofthe first moment of the period the date is inend_ofthe last moment of the period the date is in, with periods as for start_ofnextthe first date after d that falls on the given weekday, never d itselfprevthe latest date before d that falls on the given weekday, never d itselfnth_weekdaythe nth given weekday in d’s month, like the 4th Thursdayadd_workdaysthe date n business days later, counting only Monday to Friday and skipping holidaysworkdayshow many business days (Monday to Friday, less holidays) there are from a up to, but not including, bholidaysa year’s public holidays, on the day they’re taken off when they fall on a weekendcrona cron schedule in plain Englishcalendara month drawn as a calendar grid, weeks starting on Mondayzodiacthe Western star sign for a birthday (today without one)chinese_zodiacthe Chinese zodiac element and animal for a year
Functions
Section titled “Functions”weekday_num
Section titled “weekday_num”weekday_num(d: date) -> int
the day of the week as a number, from 1 for Monday to 7 for Sunday
1today.weekday_num3See also weekday
day_of_year
Section titled “day_of_year”day_of_year(d: date) -> int
which day of the year it is, from 1 to 366
1date("2026-12-31").day_of_year365See also iso_week
iso_week
Section titled “iso_week”iso_week(d: date) -> int
the week number by the ISO standard used in Europe and business
Weeks start on Monday, and week 1 is the one with the year’s first Thursday
1date("2026-12-31").iso_week53See also day_of_year, week_num, quarter
week_num
Section titled “week_num”week_num(d: date, first_day?: str) -> int
the week number when weeks start on first_day, where week 1 is the week with January 1
With no first_day this is iso_week. first_day is a day’s name, like “monday” or “sun”, and “sunday” gives the US numbering
1date("2026-12-31").week_num("sunday")53See also iso_week, day_of_year
year_frac
Section titled “year_frac”year_frac(a: date, b: date, basis?: str) -> float
the length of time from a to b as a number of years, by a day-count basis
basis is “actual/actual” (the default), “30/360”, “30E/360”, “actual/360” or “actual/365”, the conventions bonds and loans use
1year_frac(date("2026-01-15"), date("2026-07-15"), "30/360")0.5See also days_in_year
quarter
Section titled “quarter”quarter(d: date) -> int
which quarter of the year the date is in, 1 to 4
1today.quarter4See also iso_week
leap_year
Section titled “leap_year”leap_year(d: date|int) -> bool
whether the year is a leap year
1leap_year(2028)true2today.leap_yearfalseSee also days_in_year
days_in_month
Section titled “days_in_month”days_in_month(d: date) -> int
how many days the date’s month has
1date("2028-02-10").days_in_month29See also days_in_year
days_in_year
Section titled “days_in_year”days_in_year(d: date) -> int
how many days the date’s year has, 365 or 366
1today.days_in_year365start_of
Section titled “start_of”start_of(d: date, period: str) -> date
the first moment of the period the date is in
period is “second”, “minute”, “hour”, “day”, “week” (starting Monday), “month”, “quarter” or “year”
1now.start_of("week")2026-11-022now.start_of("quarter")2026-10-01end_of
Section titled “end_of”end_of(d: date, period: str) -> date
the last moment of the period the date is in, with periods as for start_of
1now.end_of("month")2026-11-30 23:59:59 -06:002(today.end_of("year") - now).parts"57 d 11 h 47 min"See also start_of
next(d: date, weekday: str) -> date / next(cron: str, n?: int) -> date|list
the first date after d that falls on the given weekday, never d itself
weekday is a day’s name, like “friday”, or its first 3 or more letters, like “fri”. Given a cron expression instead, when it next runs, or a list of the next n times
1today.next("friday")2026-11-062now.next("mon")2026-11-09 12:12:40 -06:003"0 9 * * mon".next2026-11-09 09:00:00 -06:004"@monthly".next(2)[2026-12-01, 2027-01-01]See also prev, nth_weekday, cron
prev(d: date, weekday: str) -> date
the latest date before d that falls on the given weekday, never d itself
weekday is a day’s name, like “sunday”, or its first 3 or more letters, like “sun”
1today.prev("sunday")2026-11-01See also next
nth_weekday
Section titled “nth_weekday”nth_weekday(d: date, n: int, weekday: str) -> date
the nth given weekday in d’s month, like the 4th Thursday
-1 is the last one, -2 the one before. weekday is a day’s name, like “thursday”, or its first 3 or more letters, like “thu”
1date(2026, 11, 1).nth_weekday(4, "thu")2026-11-262date(2026, 5, 1).nth_weekday(-1, "mon")2026-05-25See also next
add_workdays
Section titled “add_workdays”add_workdays(d: date, n: int, holidays?: list|str) -> date
the date n business days later, counting only Monday to Friday and skipping holidays
holidays is a list of dates, or “US” or “UK” for those public holidays. A negative n goes back
1today.add_workdays(10)2026-11-182date("2026-12-24").add_workdays(1, "US")2026-12-283date("2026-12-24").add_workdays(1, [date("2026-12-28")])2026-12-25See also workdays, holidays, is_weekend
workdays
Section titled “workdays”workdays(a: date, b: date, holidays?: list|str) -> int
how many business days (Monday to Friday, less holidays) there are from a up to, but not including, b
1workdays(today, date("2026-12-25"))372workdays(date("2026-12-01"), date("2027-01-01"), "UK")21See also add_workdays, holidays
holidays
Section titled “holidays”holidays(year: int, country: str) -> list
a year’s public holidays, on the day they’re taken off when they fall on a weekend
“US” gives federal holidays and “UK” bank holidays in England
1holidays(2026, "US")[2026-01-01, 2026-01-19, 2026-02-16, 2026-05-25, 2026-06-19, 2026-07-03, 2026-09-07, 2026-10-12, 2026-11-11, 2026-11-26, 2026-12-25]2holidays(2026, "UK").len8See also add_workdays, workdays
cron(expr: str) -> str
a cron schedule in plain English
Cron, the Unix job scheduler, writes schedules as five fields, minute hour day-of-month month weekday, where * means every and */15 every 15th, or a shortcut like @daily
1cron("0 9 * * 1-5")"at 09:00, on Monday through Friday"2cron("30 4 1,15 * fri")"at 04:30, on days 1 and 15 of the month, or on Friday"3cron("@hourly")"at minute 0 of every hour"See also next
calendar
Section titled “calendar”calendar(d: date) -> str / calendar(year: int, month: int) -> str
a month drawn as a calendar grid, weeks starting on Monday
1calendar(2026, 12) December 2026
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31See also date
zodiac
Section titled “zodiac”zodiac(day?: date) -> str
the Western star sign for a birthday (today without one)
1zodiac(date("2000-01-01"))"♑ Capricorn"See also chinese_zodiac
chinese_zodiac
Section titled “chinese_zodiac”chinese_zodiac(year: int|date) -> str
the Chinese zodiac element and animal for a year
It goes by the calendar year, so for a date in January or February before Lunar New Year it gives the next year’s sign
1chinese_zodiac(2026)"Fire Horse"2chinese_zodiac(1984)"Wood Rat"See also zodiac
More examples
Section titled “More examples”calendars
Section titled “calendars”1# Thanksgiving: 4th Thursday2date(2026, 11, 1).nth_weekday(4, "thu")2026-11-263# Memorial Day: last Monday4date(2026, 5, 1).nth_weekday(-1, "mon")2026-05-255# 3 business days later6date("2026-12-24").add_workdays(3)2026-12-297# workdays in December8workdays(date("2026-12-01"), date("2026-12-31"))229# skipping US holidays10date("2026-12-24").add_workdays(3, "US")2026-12-3011# this week's number, by the ISO standard12today.iso_week4513# what does this cron line mean?14cron("*/15 9-17 * * mon-fri")"every 15 minutes, during hours 9 through 17, on Monday through Friday"15# when does it run next?16"0 9 * * 1-5".next(3)[2026-11-05 09:00:00 -06:00, 2026-11-06 09:00:00 -06:00, 2026-11-09 09:00:00 -06:00]17# star sign and Chinese zodiac for a 1990 birthday18[zodiac(date("1990-08-10")), chinese_zodiac(1990)]["♌ Leo", "Metal Horse"]Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.