Julian day number and Julian date calculations supporting the following calendars:
| Calendar | Epoch ¹ | Era |
|---|---|---|
| Armenian | 0552-07-11 CE | Armenian |
| Astronomical | 0001-01-01 CE | CE |
| Baháʼí | 1844-03-21 CE | Baháʼí |
| Coptic | 0284-08-29 CE | Diocletian |
| Egyptian | 0747-02-26 BCE | Nabonassar |
| Ethiopian | 0008-08-29 CE | Incarnation |
| French Republican | 1792-09-22 CE | Republican |
| Gregorian | 0001-01-03 CE | CE |
| Hebrew | 3761-10-07 BCE | AM |
| Islamic | 0622-07-16 CE | AH |
| ISO | ||
| Julian | 0001-01-01 CE | CE |
| Khwarizmian | 0632-06-21 CE | Yazdegerd |
| Macedonian | 0312-09-01 BCE | Alexander |
| Maya | 3114-09-06 BCE | |
| Persian | 0632-06-16 CE | Yazdegerd |
| Śaka | 0079-03-24 CE | Śaka |
| Syrian | 0312-10-01 BCE | Alexander |
¹ Epoch in Julian calendar
The Julian day number interconverting algorithms use integer math to avoid rounding errors and the implementations have been round-trip tested for all valid Julian day numbers in the years -999,999 to +999,999.
Add a package dependency to https://github.com/sbooth/JulianDayNumber in Xcode.
- Clone the JulianDayNumber repository.
swift build.
- Calculate the Julian date for the total solar eclipse on 1919-05-29.
let jd = AstronomicalCalendar.julianDateFrom(year: 1919, month: 5, day: 29)
// 2422107.5Note
The astronomical calendar is a hybrid calendar using the Julian calendar for dates on or before October 4, 1582 and the Gregorian calendar for dates on or after October 15, 1582.
- Convert the Julian date 2422107.5 to a
Dateinstance.
let d = Date(julianDate: 2422107.5)
// Foundation.Date 1919-05-29 00:00:00 UTC- Convert the Gregorian calendar date 2013-10-31 to a date in the Julian calendar.
let julianYMD = GregorianCalendar.convert(year: 2013, month: 10, day:31, to: JulianCalendar.self)
// (year: 2013, month: 10, day: 18)The latest documentation is hosted by Swift Package Index.
All public classes, structs, and functions should be documented. If you notice a documentation shortcoming please open a new issue.
The following table summarizes the arithmetic limits for Julian day number calculations on platforms where Int is 64 bits.
| Calendar | Minimum JDN | Maximum JDN |
|---|---|---|
| Armenian | Int.min + 341 |
Int.max |
| Baháʼí | Int.min |
Int.max |
| Coptic | Int.min |
Int.max |
| Egyptian | Int.min + 611 |
Int.max |
| Ethiopian | Int.min |
Int.max |
| French Republican | Int.min |
Int.max |
| Gregorian | Int.min |
Int.max |
| Hebrew | Int.min + 106960181 |
355839970905664 |
| Islamic | Int.min |
Int.max |
| Julian | Int.min |
Int.max |
| Khwarizmian | Int.min + 341 |
Int.max |
| Macedonian | Int.min |
Int.max |
| Maya Long Count | Int.min |
Int.max |
| Persian | Int.min + 336 |
Int.max |
| Śaka | Int.min |
Int.max |
| Syrian | Int.min |
Int.max |
JulianDayNumber is released under the MIT License.