Category talk:Wren-date: Difference between revisions
Content added Content deleted
m (→Source code: Typo in comment.) |
(→Source code: Added Date.fromJulian method.) |
||
Line 485: | Line 485: | ||
static fromNumber(num) { Date.fromNumber(num, "UTC") } |
static fromNumber(num) { Date.fromNumber(num, "UTC") } |
||
// Returns the Gregorian Proleptic date equivalent to a Julian date given in y/m/d format. |
|||
// If 'ay' is 1582, the first omitted date is 5th October 1582 or, if 'ay' is 1752, |
|||
// 3rd September 1752. Years are always assumed to begin on 1st January and leap years |
|||
// to contain 29th February. Omitted Julian dates map respectively to 15th October 1582 or |
|||
// 14th September 1752. Subsequent dates are returned unchanged as Gregorian dates. |
|||
// If 'ay' is 2200, conversions continue up to 14th February 2200 but no further. |
|||
static fromJulian(y, m, d, ay) { |
|||
var dt = Date.new(y, m, d) |
|||
if (ay != 1582 && ay != 1752 && ay != 2200) Fiber.abort("Invalid adoption year.") |
|||
if (dt <= Date.new( 1, 1, 2)) Fiber.abort("Unsupported Julian date.") |
|||
if (dt <= Date.new( 100, 3, 1)) return dt.addDays(-2) |
|||
if (dt <= Date.new( 200, 2, 29)) return dt.addDays(-1) |
|||
if (dt <= Date.new( 300, 2, 28)) return dt |
|||
if (dt <= Date.new( 500, 2, 27)) return dt.addDays(1) |
|||
if (dt <= Date.new( 600, 2, 26)) return dt.addDays(2) |
|||
if (dt <= Date.new( 700, 2, 25)) return dt.addDays(3) |
|||
if (dt <= Date.new( 900, 2, 24)) return dt.addDays(4) |
|||
if (dt <= Date.new(1000, 2, 23)) return dt.addDays(5) |
|||
if (dt <= Date.new(1100, 2, 22)) return dt.addDays(6) |
|||
if (dt <= Date.new(1300, 2, 21)) return dt.addDays(7) |
|||
if (dt <= Date.new(1400, 2, 20)) return dt.addDays(8) |
|||
if (dt <= Date.new(1500, 2, 19)) return dt.addDays(9) |
|||
if (dt <= Date.new(1582, 10, 4)) return dt.addDays(10) |
|||
if (dt <= Date.new(1582, 10, 14)) return ay == 1582 ? Date.new(1582, 10, 15) : dt.addDays(10) |
|||
if (ay == 1582) return dt |
|||
if (dt <= Date.new(1700, 2, 18)) return dt.addDays(10) |
|||
if (dt <= Date.new(1752, 9, 2)) return dt.addDays(11) |
|||
if (dt <= Date.new(1752, 9, 13)) return ay == 1752 ? Date.new(1752, 9, 14) : dt.addDays(11) |
|||
if (ay == 1752) return dt |
|||
if (dt <= Date.new(1800, 2, 17)) return dt.addDays(11) |
|||
if (dt <= Date.new(1900, 2, 16)) return dt.addDays(12) |
|||
if (dt <= Date.new(2100, 2, 15)) return dt.addDays(13) |
|||
if (dt <= Date.new(2200, 2, 14)) return dt.addDays(14) |
|||
Fiber.abort("Unsupported Julian date.") |
|||
} |
|||
// As above method but always uses a 1582 adoption year. |
|||
static fromJulian(y, m, d) { fromJulian(y, m, d, 1582) } |
|||
// Gets the component parts of this date, as a list, from its number |
// Gets the component parts of this date, as a list, from its number |