///|
test {
// creates a UTC+8 fixed time zone.
let zone = @time.fixed_zone("Asia/Shanghai", 8 * 60 * 60)
// creates a ZonedDateTime from unix second and time zone.
let date_time = @time.unix(1714227729L, nanosecond=1000, zone~)
inspect(date_time, content="2024-04-27T22:22:09.000001+08:00[Asia/Shanghai]")
}| Policy | Repeated reading (overlap) | Skipped reading (gap) |
|---|---|---|
| Compatible (default) | Choose the earlier instant | Shift forward by the gap |
| Earlier | Choose the earlier instant | Shift backward by the gap |
| Later | Choose the later instant | Shift forward by the gap |
| Reject | Raise an error | Raise an error |
| Offset policy | Treatment of the original offset at the edited local time |
|---|---|
| Prefer (default) | Use it if valid; otherwise resolve using the zone and disambiguation |
| Ignore | Resolve using the zone and disambiguation, ignoring the original offset |
| Use | Compute the instant using the original offset, then project it into the zone; local fields can change |
| Reject | Use it if valid; otherwise raise, even if the edited local time is unambiguous |
///|
test {
let plain = @time.PlainDateTime::of(2040, 1, 1, hour=1)
let zone = @time.fixed_zone("Example", 3600)
let value = @time.ZonedDateTime::from_plain(
plain,
zone~,
disambiguation=Reject,
)
// A fixed zone has exactly one matching instant for every local reading.
inspect(value, content="2040-01-01T01:00:00+01:00[Example]")
let offset : @time.OffsetPolicy = Ignore
debug_inspect(
value.with_hour(2, offset~, disambiguation=Reject).to_string(),
content="\"2040-01-01T02:00:00+01:00[Example]\"",
)
}pub suberror LocalZoneError {
LocalZoneError(UInt, context~ : String, message~ : String)
}impl Show for LocalZoneError#deprecated("`Disambiguation::equal` is deprecated, use `Eq::equal` instead.")
fn Disambiguation::equal(Disambiguation, Disambiguation) -> Bool#deprecated("`Disambiguation::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn Disambiguation::not_equal(x : Disambiguation, y : Disambiguation) -> Bool#deprecated("`Disambiguation::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn Disambiguation::to_repr(Disambiguation) -> Repr#deprecated("`OffsetPolicy::equal` is deprecated, use `Eq::equal` instead.")
fn OffsetPolicy::equal(OffsetPolicy, OffsetPolicy) -> Bool#deprecated("`OffsetPolicy::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn OffsetPolicy::not_equal(x : OffsetPolicy, y : OffsetPolicy) -> Bool#deprecated("`OffsetPolicy::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn OffsetPolicy::to_repr(OffsetPolicy) -> Repr#deprecated("`PlainDate::from_json` is deprecated, use `@moonbitlang/core/json.FromJson::from_json` instead.")
fn PlainDate::from_json(json : Json, path : JsonPath) -> PlainDate raise JsonDecodeErrorimpl Show for PlainDateTimeimpl FromStr for PlainDateTime#deprecated("`PlainDateTime::compare` is deprecated, use `Compare::compare` instead.")
fn PlainDateTime::compare(PlainDateTime, PlainDateTime) -> Int#deprecated("`PlainDateTime::equal` is deprecated, use `Eq::equal` instead.")
fn PlainDateTime::equal(PlainDateTime, PlainDateTime) -> Bool#deprecated("`PlainDateTime::from_json` is deprecated, use `@moonbitlang/core/json.FromJson::from_json` instead.")
fn PlainDateTime::from_json(Json, JsonPath) -> PlainDateTime raise JsonDecodeError#deprecated("`PlainDateTime::from_str` is deprecated, use `@moonbitlang/core/string.FromStr::from_str` instead.")
fn PlainDateTime::from_str(str : StringView) -> PlainDateTime raise#deprecated("Use `PlainDateTime::from_str` instead")
fn PlainDateTime::from_string(str : String) -> PlainDateTime raisefn PlainDateTime::from_unix_second(second : Int64, nanosecond : Int, offset : ZoneOffset) -> PlainDateTime raise#deprecated("`PlainDateTime::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn PlainDateTime::not_equal(x : PlainDateTime, y : PlainDateTime) -> Boolfn PlainDateTime::of(year : Int, month : Int, day : Int, hour? : Int, minute? : Int, second? : Int, nanosecond? : Int) -> PlainDateTime raise#deprecated("`PlainDateTime::op_ge` is deprecated, use `Compare::op_ge` instead.")
fn PlainDateTime::op_ge(x : PlainDateTime, y : PlainDateTime) -> Bool#deprecated("`PlainDateTime::op_gt` is deprecated, use `Compare::op_gt` instead.")
fn PlainDateTime::op_gt(x : PlainDateTime, y : PlainDateTime) -> Bool#deprecated("`PlainDateTime::op_le` is deprecated, use `Compare::op_le` instead.")
fn PlainDateTime::op_le(x : PlainDateTime, y : PlainDateTime) -> Bool#deprecated("`PlainDateTime::op_lt` is deprecated, use `Compare::op_lt` instead.")
fn PlainDateTime::op_lt(x : PlainDateTime, y : PlainDateTime) -> Bool#deprecated("`PlainDateTime::output` is deprecated, use `Show::output` instead.")
fn PlainDateTime::output(self : PlainDateTime, logger : &Logger) -> Unit#deprecated("`PlainDateTime::to_json` is deprecated, use `ToJson::to_json` instead.")
fn PlainDateTime::to_json(PlainDateTime) -> Json#deprecated("`PlainDateTime::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn PlainDateTime::to_repr(PlainDateTime) -> Repr#deprecated("`PlainTime::from_json` is deprecated, use `@moonbitlang/core/json.FromJson::from_json` instead.")
fn PlainTime::from_json(json : Json, path : JsonPath) -> PlainTime raise JsonDecodeError#deprecated("Zone equality cannot establish equivalent timezone rules. Compare labels or offsets at a specific instant instead, according to your intent.")
#deprecated("Zone equality cannot establish equivalent timezone rules. Compare labels or offsets at a specific instant instead, according to your intent.")
fn Zone::equal(self : Zone, other : Zone) -> Bool#deprecated("Zone equality cannot establish equivalent timezone rules. Compare labels or offsets at a specific instant instead, according to your intent.")
#deprecated("Zone equality cannot establish equivalent timezone rules. Compare labels or offsets at a specific instant instead, according to your intent.")
fn Zone::not_equal(x : Zone, y : Zone) -> Boolimpl Compare for ZoneOffsetimpl Eq for ZoneOffsetimpl Show for ZoneOffset#deprecated("`ZoneOffset::compare` is deprecated, use `Compare::compare` instead.")
fn ZoneOffset::compare(self : ZoneOffset, other : ZoneOffset) -> Int#deprecated("`ZoneOffset::equal` is deprecated, use `Eq::equal` instead.")
fn ZoneOffset::equal(self : ZoneOffset, other : ZoneOffset) -> Bool#deprecated("`ZoneOffset::not_equal` is deprecated, use `Eq::not_equal` instead.")
fn ZoneOffset::not_equal(x : ZoneOffset, y : ZoneOffset) -> Boolfn ZoneOffset::of(hours? : Int, minutes? : Int, seconds? : Int, abbrev? : String, dst? : Bool) -> ZoneOffset raise#deprecated("`ZoneOffset::op_ge` is deprecated, use `Compare::op_ge` instead.")
fn ZoneOffset::op_ge(x : ZoneOffset, y : ZoneOffset) -> Bool#deprecated("`ZoneOffset::op_gt` is deprecated, use `Compare::op_gt` instead.")
fn ZoneOffset::op_gt(x : ZoneOffset, y : ZoneOffset) -> Bool#deprecated("`ZoneOffset::op_le` is deprecated, use `Compare::op_le` instead.")
fn ZoneOffset::op_le(x : ZoneOffset, y : ZoneOffset) -> Bool#deprecated("`ZoneOffset::op_lt` is deprecated, use `Compare::op_lt` instead.")
fn ZoneOffset::op_lt(x : ZoneOffset, y : ZoneOffset) -> Bool#deprecated("`ZoneOffset::output` is deprecated, use `Show::output` instead.")
fn ZoneOffset::output(self : ZoneOffset, logger : &Logger) -> Unit#deprecated("`ZoneOffset::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn ZoneOffset::to_repr(ZoneOffset) -> Reprimpl Show for ZonedDateTimefn ZonedDateTime::from_plain(datetime : PlainDateTime, zone? : Zone, disambiguation? : Disambiguation) -> ZonedDateTime raise#deprecated("Use `ZonedDateTime::from_plain` to choose a disambiguation policy")
fn ZonedDateTime::from_plain_datetime(datetime : PlainDateTime, zone? : Zone) -> ZonedDateTimefn ZonedDateTime::from_unix_second(second : Int64, nanosecond? : Int, zone? : Zone) -> ZonedDateTime raisefn ZonedDateTime::of(year : Int, month : Int, day : Int, hour? : Int, minute? : Int, second? : Int, nanosecond? : Int, zone? : Zone, disambiguation? : Disambiguation) -> ZonedDateTime raise#deprecated("`ZonedDateTime::output` is deprecated, use `Show::output` instead.")
fn ZonedDateTime::output(self : ZonedDateTime, logger : &Logger) -> Unit#deprecated("`ZonedDateTime::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
fn ZonedDateTime::to_repr(ZonedDateTime) -> Reprfn ZonedDateTime::with_day(self : ZonedDateTime, day : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_hour(self : ZonedDateTime, hour : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_minute(self : ZonedDateTime, minute : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_month(self : ZonedDateTime, month : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_nanosecond(self : ZonedDateTime, nanosecond : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_ordinal(self : ZonedDateTime, ordinal : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_second(self : ZonedDateTime, second : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn ZonedDateTime::with_year(self : ZonedDateTime, year : Int, offset? : OffsetPolicy, disambiguation? : Disambiguation) -> ZonedDateTime raisefn date_time(year : Int, month : Int, day : Int, hour? : Int, minute? : Int, second? : Int, nanosecond? : Int, zone? : Zone, disambiguation? : Disambiguation) -> ZonedDateTime raise