A relative time formatting library for MoonBit, following the whenwords specification
moon add mizchi/whenwords// Relative time formatting
@whenwords.timeago(1705190400L, reference=1705276800L) // "1 day ago"
@whenwords.timeago(1705280400L, reference=1705276800L) // "in 1 hour"
// Duration formatting
@whenwords.duration(9000L) // "2 hours, 30 minutes"
@whenwords.duration(9000L, options={ compact: true, max_units: 2 }) // "2h 30m"
// Duration parsing
@whenwords.parse_duration("2h 30m") // 9000
@whenwords.parse_duration("2:30:00") // 9000
@whenwords.parse_duration("2.5 hours") // 9000
// Human-readable dates
@whenwords.human_date(1705190400L, reference=1705276800L) // "Yesterday"
@whenwords.human_date(1705363200L, reference=1705276800L) // "Tomorrow"
@whenwords.human_date(1704844800L, reference=1705276800L) // "Last Wednesday"
// Date ranges
@whenwords.date_range(1705276800L, 1705449600L) // "January 15-17, 2024"moon testpub suberror ParseDurationError {
ParseDurationError(String)
}pub(all) struct DurationOptions {
compact : Bool
max_units : Int
}fn date_range(start : Int64, end : Int64) -> Stringfn human_date(timestamp : Int64, reference~ : Int64) -> Stringfn timeago(timestamp : Int64, reference~ : Int64) -> StringA relative time formatting library for MoonBit, following the whenwords specification