A date and time library for MoonBit
| Package | Import alias | Description |
|---|---|---|
| connect0459/almanac | @almanac | Re-exports of the everyday types: Weekday, Month, NaiveDate, NaiveTime, NaiveDateTime, TimeDelta, TimeZone, Utc, FixedOffset, Location, DateTime, MappedLocalTime |
| connect0459/almanac/core | @core | Calendar and clock primitives with no time zone: NaiveDate, NaiveTime, NaiveDateTime, TimeDelta, Weekday, WeekdaySet, Month, IsoWeek, NaiveWeek |
| connect0459/almanac/tz | @tz | Time zones: the TimeZone trait, Utc, FixedOffset, FixedZone, Location (embedded IANA tz database), PosixTz, DateTime[Tz], MappedLocalTime, and Local on the native backend only |
| connect0459/almanac/format | @format | strftime-style formatting and parsing, RFC 3339, RFC 2822 and HTTP dates, plus the default-layout and duration parsers |
| connect0459/almanac/cron | @cron | Cron expressions: Cron::parse, then matches and next over a zoned DateTime[Tz] |
moon add connect0459/almanacimport {
"connect0459/almanac", // everyday types
"connect0459/almanac/format", // formatting and parsing
// "connect0459/almanac/core",
// "connect0459/almanac/tz",
// "connect0459/almanac/cron",
}///|
test {
let tokyo = @tz.Location::load("Asia/Tokyo").unwrap()
let dt = @tz.DateTime::from_ymd_hms(2024, 3, 8, 9, 40, 0, tokyo)
.single()
.unwrap()
assert_eq(@format.to_rfc3339(dt), "2024-03-08T09:40:00+09:00")
let weekdays = @cron.Cron::parse("30 9 * * mon-fri")
let next = weekdays.next(dt).unwrap()
assert_eq(@format.to_rfc3339(next), "2024-03-11T09:30:00+09:00")
}| Package | Import | Contents |
|---|---|---|
| connect0459/almanac | @almanac | Re-exports of the everyday types (see below) |
| connect0459/almanac/core | @core | Calendar and clock primitives with no time zone: Weekday, WeekdaySet, Month, IsoWeek, NaiveDate, NaiveWeek, NaiveTime, TimeDelta, NaiveDateTime, RoundingError |
| connect0459/almanac/tz | @tz | Time zones: the TimeZone trait, Utc, FixedOffset, FixedZone, Location (IANA tzdata), PosixTz, DateTime[Tz], MappedLocalTime, and on the native backend only, Local (the host's zone) |
| connect0459/almanac/format | @format | strftime-style formatting and parsing, RFC 2822 and RFC 3339, plus the default-layout and duration parsers |
| connect0459/almanac/cron | @cron | Cron expressions: Cron::parse, then matches and next over a zoned DateTime[Tz] |
///|
test {
let date = @almanac.NaiveDate::from_ymd(2024, 3, 5).unwrap()
let time = @almanac.NaiveTime::from_hms(9, 5, 7).unwrap()
let naive = @almanac.NaiveDateTime::new(date, time)
assert_eq(naive.to_string(), "2024-03-05 09:05:07")
let tokyo = @almanac.FixedOffset::east(9 * 3600).unwrap()
let dt = @almanac.DateTime::from_timestamp(0L, 0, tokyo).unwrap()
assert_eq(dt.hour(), 9)
}import {
"connect0459/almanac/core" @almanac_core,
"connect0459/almanac/tz" @almanac_tz,
}Install
Download zipA date and time library for MoonBit