Repository navigation
How Dates Are Computed
The hub never does date arithmetic in its head: reign lengths, ages, BCE crossings, Old Style dates and era names all go through hw.py cal. This page states the rules it follows, each with the output of 0.5.0 (commit 3239fbf).
-
Every date becomes a Julian Day Number (JDN), a count of days, with integer arithmetic. Python's
datetimeis never used, because it stops at year 1. -
There is no year 0. 1 BC is followed by AD 1. ISO 8601 and EDTF write years astronomically, so 100 BC is
-0099, andhw.pyprints both forms. -
Julian before 15 October 1582, Gregorian from then on, unless the date says otherwise:
O.S.forces Julian,N.S.forces Gregorian, and--calpicks one. Any Gregorian reading before 15 October 1582 is labelled proleptic. -
Each country switched on its own date.
--countrynames the civil calendar in force there (GB, US, RU, SE, FR, GR, JP, CN, KR, TR and others) and adds the Old Style and New Style pair. - Before 1 January 45 BC, Rome used the republican calendar, which drifted months from the sun. A Roman date from then has no exact solar equivalent, and the output says so.
-
A date has a precision. "100 BC" covers a year, "July 100 BC" a month.
jdngives the first and last day covered, andprecisionnames which. - Unreadable input is refused, not guessed. See Errors and edge cases.
python hw.py cal date "12 July 100 BC"{
"ok": true,
"input": "12 July 100 BC",
"read_as": {
"astronomical_year": -99,
"month": 7,
"day": 12,
"calendar": "julian",
"label": "12 July 100 BC"
},
"precision": "day",
"jdn": [
1685091,
1685091
],
"edtf": "-0099-07-12",
"day": {
"jdn": 1685091,
"weekday": "Wednesday",
"julian": {
"iso": "-0099-07-12",
"label": "12 July 100 BC",
"auc": 654
},
"gregorian": {
"iso": "-0099-07-10",
"label": "10 July 100 BC"
},
"notes": [
"before 1 January 45 BC: Rome used the republican calendar, so a Roman date as written does not map to this solar day; the Julian reading is proleptic",
"Gregorian reading before 15 October 1582 is proleptic"
]
}
}
The proleptic Gregorian reading is two days earlier than the Julian one. AUC is the Roman year count from the founding of the city (Varronian: AUC 1 = 753 BC).
Russia kept the Julian calendar until 31 January 1918 (hw.py's table of switch dates), so the October Revolution fell in November by the Gregorian count:
python hw.py cal date "1917-10-25 O.S." --country RU{
"ok": true,
"input": "1917-10-25 O.S.",
"read_as": {
"astronomical_year": 1917,
"month": 10,
"day": 25,
"calendar": "julian",
"label": "25 October 1917"
},
"precision": "day",
"jdn": [
2421540,
2421540
],
"edtf": "1917-10-25",
"day": {
"jdn": 2421540,
"weekday": "Wednesday",
"julian": {
"iso": "1917-10-25",
"label": "25 October 1917",
"auc": 2670
},
"gregorian": {
"iso": "1917-11-07",
"label": "7 November 1917"
},
"islamic_tabular": {
"ah": "1336-01-22",
"note": "tabular; observed dates can differ by a day or two"
},
"civil_calendar": {
"country": "RU",
"calendar": "julian"
},
"os_ns": {
"old_style": "25 October 1917",
"new_style": "7 November 1917",
"difference_days": 13
}
}
}
Before 1752, the English legal year began on 25 March, so a date between 1 January and 24 March carries the previous year's number in documents of the time. hw.py always reads a year as starting on 1 January: pass the January-start year and --country GB prints the dual year as it was written then. George Washington's birth, written "11 February 1731" at the time:
python hw.py cal date "1732-02-11 O.S." --country GB{
"ok": true,
"input": "1732-02-11 O.S.",
"read_as": {
"astronomical_year": 1732,
"month": 2,
"day": 11,
"calendar": "julian",
"label": "11 February 1732"
},
"precision": "day",
"jdn": [
2353712,
2353712
],
"edtf": "1732-02-11",
"day": {
"jdn": 2353712,
"weekday": "Friday",
"julian": {
"iso": "1732-02-11",
"label": "11 February 1732",
"auc": 2485
},
"gregorian": {
"iso": "1732-02-22",
"label": "22 February 1732"
},
"islamic_tabular": {
"ah": "1144-08-25",
"note": "tabular; observed dates can differ by a day or two"
},
"civil_calendar": {
"country": "GB",
"calendar": "julian",
"dual_year": "1731/32"
},
"os_ns": {
"old_style": "11 February 1732",
"new_style": "22 February 1732",
"difference_days": 11
},
"notes": [
"legal year began 25 March before 1752"
]
}
}
cal span gives the exact days, and the years, months and days, between two dates. The Kangxi Emperor's formal reign:
python hw.py cal span "1661-02-05" "1722-12-20"{
"ok": true,
"start": "5 February 1661",
"end": "20 December 1722",
"days": 22597,
"years": 61,
"months": 10,
"rest_days": 15,
"calendar_for_y_m_d": "gregorian",
"crosses_bc_ad": false,
"note": null
}
Across the BC and AD boundary, the missing year 0 is accounted for. From 44 BC to AD 14 is 57 years, not 58:
python hw.py cal span "44 BC" "AD 14"{
"ok": true,
"start": "44 BC",
"end": "AD 14",
"days": 20819,
"years": 57,
"months": 0,
"rest_days": 0,
"calendar_for_y_m_d": "julian",
"crosses_bc_ad": true,
"note": "no year 0 between 1 BC and AD 1; computed on astronomical years"
}
AUC 709 and 709 AUC are the same year, 45 BC, the first year of the Julian calendar:
python hw.py cal date "709 AUC"{
"ok": true,
"input": "709 AUC",
"read_as": {
"astronomical_year": -44,
"month": null,
"day": null,
"calendar": "julian",
"label": "45 BC"
},
"precision": "year",
"jdn": [
1704987,
1705352
],
"edtf": "-0044",
"day": {
"jdn": 1704987,
"weekday": "Friday",
"julian": {
"iso": "-0044-01-01",
"label": "1 January 45 BC",
"auc": 709
},
"gregorian": {
"iso": "-0045-12-30",
"label": "30 December 46 BC"
},
"notes": [
"Gregorian reading before 15 October 1582 is proleptic"
]
},
"notes": [
"AUC read as Varronian (AUC 1 = 753 BC)"
]
}
An Islamic (AH) year is about 354 days, so it starts in one Western year and ends in the next. A year-only AH date covers its own days, and EDTF writes it as an interval. The calendar is the tabular one: observed months can differ by a day or two.
python hw.py cal date "AH 1300"{
"ok": true,
"input": "AH 1300",
"read_as": {
"calendar": "islamic (tabular)",
"ah_year": 1300,
"ah_month": null,
"ah_day": null,
"label": "AH 1300",
"western_start": {
"astronomical_year": 1882,
"month": null,
"day": null,
"calendar": "gregorian",
"label": "1882"
}
},
"precision": "year",
"jdn": [
2408762,
2409116
],
"edtf": "1882-11-12/1883-11-01",
"day": {
"jdn": 2408762,
"weekday": "Sunday",
"julian": {
"iso": "1882-10-31",
"label": "31 October 1882",
"auc": 2635
},
"gregorian": {
"iso": "1882-11-12",
"label": "12 November 1882"
},
"islamic_tabular": {
"ah": "1300-01-01",
"note": "tabular; observed dates can differ by a day or two"
},
"os_ns": {
"old_style": "31 October 1882",
"new_style": "12 November 1882",
"difference_days": 12
}
},
"notes": [
"tabular Islamic calendar (civil epoch); observed dates can differ by a day or two"
]
}
read_as labels the date in AH and gives the Western year it begins in under western_start (0.1.0 showed only that Western year, as "label": "1882"); jdn and edtf give the year's real extent.
Since 0.2.0 cal date also reads Roman day counts (Ides of March 44 BC, a.d. III Id. Mar. 44 BC) with Roman inclusive counting, Hijri month names (1 Muharram 1 AH, and Ramadan 1445 as that month's own days), and c. or circa as an approximate date, EDTF ~. Their output and what is still refused are on Errors and edge cases.
cal jdn reads one Julian Day in every calendar. JDN 2299161 is the first day of the Gregorian calendar:
python hw.py cal jdn 2299161{
"ok": true,
"jdn": 2299161,
"weekday": "Friday",
"julian": {
"iso": "1582-10-05",
"label": "5 October 1582",
"auc": 2335
},
"gregorian": {
"iso": "1582-10-15",
"label": "15 October 1582"
},
"islamic_tabular": {
"ah": "990-09-17",
"note": "tabular; observed dates can differ by a day or two"
},
"os_ns": {
"old_style": "5 October 1582",
"new_style": "15 October 1582",
"difference_days": 10
}
}
East Asian dates come from the DILA Time Authority Database (Dharma Drum Institute of Liberal Arts, CC BY-SA 3.0). hw.py downloads it on first use (about 1.3 MB) and builds a table in the home folder; cal setup does it ahead of time:
python hw.py cal setup{
"ok": true,
"db": "<home>/dila_time.sqlite",
"built": true,
"from": "https://authority.dila.edu.tw/downloads/authority_time.2012-02.zip",
"rows": {
"dynasty": 123,
"dynasty_name": 149,
"emperor": 692,
"emperor_name": 1040,
"era": 1503,
"era_name": 1984,
"month": 117428
},
"licence": "CC BY-SA 3.0 Unported; the table stays on this machine",
"attribution": "East Asian calendar data: DILA Time Authority Database, Dharma Drum Institute of Liberal Arts (authority.dila.edu.tw), CC BY-SA 3.0. Lookup design after kltng/humanities-skills cjk-calendar."
}
Coverage is China from about 220 BC to 1912, Japan 593 to 1872 and Korea 56 BC to 1885. An era name returns every era that used it. 康熙 returns two: the Kangxi Emperor's own (聖祖), and the same name under the next emperor (世宗) from 21 December 1722 to 4 February 1723, because an era name can outlast the reign that started it:
python hw.py cal era 康熙{
"ok": true,
"era": "康熙",
"matches": [
{
"era_id": 660,
"era_name": "康熙",
"emperor_id": 332,
"emperor_name": "聖祖",
"dynasty_id": 92,
"dynasty_name": "清",
"country": "chinese",
"start_jdn": 2328142,
"end_jdn": 2350361,
"start": "18 February 1662",
"end": "20 December 1722"
},
{
"era_id": 1204,
"era_name": "康熙",
"emperor_id": 333,
"emperor_name": "世宗",
"dynasty_id": 92,
"dynasty_name": "清",
"country": "chinese",
"start_jdn": 2350362,
"end_jdn": 2350407,
"start": "21 December 1722",
"end": "4 February 1723"
}
],
"attribution": "East Asian calendar data: DILA Time Authority Database, Dharma Drum Institute of Liberal Arts (authority.dila.edu.tw), CC BY-SA 3.0. Lookup design after kltng/humanities-skills cjk-calendar.",
"note": "every era with this name is listed; pick by dynasty and country"
}
That is why the hub gives accession and death dates, not the era span, for the length of a reign. An era date converts to a Western date:
python hw.py cal cjk 崇禎三年四月初三{
"ok": true,
"input": "崇禎三年四月初三",
"parsed": {
"era": "崇禎",
"year": 3,
"leap": false,
"month": 4,
"day": 3
},
"matches": [
{
"era": "崇禎",
"emperor": "思宗",
"dynasty": "明",
"country": "chinese",
"era_year": 3,
"year_ganzhi": "庚午",
"month_name": "四月",
"jdn": [
2316539,
2316539
],
"western": [
"14 May 1630",
"14 May 1630"
]
}
],
"attribution": "East Asian calendar data: DILA Time Authority Database, Dharma Drum Institute of Liberal Arts (authority.dila.edu.tw), CC BY-SA 3.0. Lookup design after kltng/humanities-skills cjk-calendar.",
"note": "an ambiguous era name returns every match; DILA covers China c. 220 BCE-1912, Japan 593-1872, Korea 56 BCE-1885"
}
Credit DILA in any answer that uses these tables; the output's attribution line is the wording.
This wiki describes historywright 0.6.1 (released 2026-11-02, commit 078613e) and was last updated on 2026-11-02. The plugin is MIT licensed. Report problems in the issues.
Using it
- Getting started
- The skills
- Commands
- How dates are computed
- How claims are checked
- The research pack
- Errors and edge cases
- Recipes
- FAQ
The releases
Contributing
Elsewhere