Category talk:Wren-date: Difference between revisions

Content added Content deleted
m (→‎Source code: Now uses Wren S/H lexer.)
(→‎Source code: Clarified position re non-integral increments when using 'add' methods.)
 
Line 473: Line 473:
if (num < 0 || num > Date.maximum.number) Fiber.abort("Number is out of range.")
if (num < 0 || num > Date.maximum.number) Fiber.abort("Number is out of range.")
if (!(tz = Date.isValidTz_(tz))) Fiber.abort("Invalid time zone designator.")
if (!(tz = Date.isValidTz_(tz))) Fiber.abort("Invalid time zone designator.")
_num = num
_num = num.floor
_tz = tz
_tz = tz
}
}
Line 578: Line 578:
millisec { parts[6] }
millisec { parts[6] }


// Return a new Date object after adding positive (or negative) increments.
// Return a new Date object after adding positive (or negative) integral increments.
addYears(y) { Date.new(year + y, month, day, hour, minute, second, millisec, _tz) }
addYears(y) { Date.new(year + y, month, day, hour, minute, second, millisec, _tz) }


Line 595: Line 595:
}
}


// Increments for these methods need not be integral
// but will be rounded to the lower millisecond where necessary.
addWeeks(w) { Date.fromNumber(_num + w * 86400000 * 7, _tz) }
addWeeks(w) { Date.fromNumber(_num + w * 86400000 * 7, _tz) }
addDays(d) { Date.fromNumber(_num + d * 86400000, _tz) }
addDays(d) { Date.fromNumber(_num + d * 86400000, _tz) }