std:time リファレンス
@import 'std:time' で取得する日時モジュール。Date / Time / Instant / Duration の 4 型と、現在時刻の取得・構築・解析を提供する。
Friday
Friday Friday: Weekday
曜日を表す Variant 値 (金曜)。
>>> time.Friday Friday
Monday
Monday Monday: Weekday
曜日を表す Variant 値 (月曜)。
>>> time.Monday Monday
Saturday
Saturday Saturday: Weekday
曜日を表す Variant 値 (土曜)。
>>> time.Saturday Saturday
Sunday
Sunday Sunday: Weekday
曜日を表す Variant 値 (日曜)。
>>> time.Sunday Sunday
Thursday
Thursday Thursday: Weekday
曜日を表す Variant 値 (木曜)。
>>> time.Thursday Thursday
Tuesday
Tuesday Tuesday: Weekday
曜日を表す Variant 値 (火曜)。
>>> time.Tuesday Tuesday
Wednesday
Wednesday Wednesday: Weekday
曜日を表す Variant 値 (水曜)。
>>> time.Wednesday Wednesday
date
date(rec)
date: { { year, month, day |} | Result(Date) }
{year, month, day} から Date を構築する。
>>> time.date({ year := 2024, month := 1, day := 1 |}) Ok(2024-01-01)
days
days(n)
days: { Int | Duration }
n 日 (24h 固定) の Duration を返す。
>>> time.days(1) Duration(24h0m0s)
from_epoch_ms
from_epoch_ms(n)
from_epoch_ms: { Int | Instant }
epoch ミリ秒 Integer から Instant を構築する。
>>> time.from_epoch_ms(0) 1970-01-01T00:00:00Z
hours
hours(n)
hours: { Int | Duration }
n 時間の Duration を返す。
>>> time.hours(2) Duration(2h0m0s)
millis
millis(n)
millis: { Int | Duration }
n ミリ秒の Duration を返す。
>>> time.millis(1500) Duration(0h0m1s500ms)
minutes
minutes(n)
minutes: { Int | Duration }
n 分の Duration を返す。
>>> time.minutes(5) Duration(0h5m0s)
now
now() now: { Instant }
現在時刻 (UTC) を Instant で返す。
of
of(rec)
of: { { year, month, day |} | Result(Instant) }
UTC 暦レコードから Instant を構築する。
>>> time.of({ year := 2024, month := 1, day := 1 |}) Ok(2024-01-01T00:00:00Z)
parse
parse(layout, text)
parse: { String, String | Result(Instant) }
strftime 風レイアウトで text を解析し Instant を返す。
>>> time.parse("%Y-%m-%d", "2024-01-01") Ok(2024-01-01T00:00:00Z)
parse_date
parse_date(text)
parse_date: { String | Result(Date) }
ISO YYYY-MM-DD を解析し Date を返す。
>>> time.parse_date("2024-01-01") Ok(2024-01-01)
parse_iso
parse_iso(text)
parse_iso: { String | Result(Instant) }
RFC3339 文字列を解析し絶対時刻 (Instant) へ畳む。
>>> time.parse_iso("2024-01-01T00:00:00Z") Ok(2024-01-01T00:00:00Z)
parse_time
parse_time(text)
parse_time: { String | Result(Time) }
ISO HH:MM:SS[.SSS] を解析し Time を返す。
>>> time.parse_time("05:30:00") Ok(05:30:00)
seconds
seconds(n)
seconds: { Int | Duration }
n 秒の Duration を返す。
>>> time.seconds(90) Duration(0h1m30s)
time_of
time_of(rec)
time_of: { { hour |} | Result(Time) }
{hour, minute?, second?, milli?} から Time を構築する。
>>> time.time_of({ hour := 5, minute := 30 |}) Ok(05:30:00)
today
today()
today: { Date }
現在の UTC 日付を Date で返す。
Date メソッド
add_days
date.add_days(n) add_days: { Int | Date }
n 日加算した Date。
add_months
date.add_months(n) add_months: { Int | Date }
n ヶ月加算 (月末クランプ)。
>>> d := time.date({ year := 2024, month := 3, day := 15 |}).unwrap! >>> d.add_months(1) 2024-04-15
add_years
date.add_years(n) add_years: { Int | Date }
n 年加算 (月末クランプ)。
at
date.at(time) at: { Time | Instant }
time (Time) と結合し UTC で Instant にする。
>>> d := time.date({ year := 2024, month := 3, day := 15 |}).unwrap! >>> tm := time.time_of({ hour := 9, minute := 30 |}).unwrap! >>> d.at(tm) 2024-03-15T09:30:00Z
compare
date.compare(other) compare: { Date | Ordering }
日付の全順序。
>>> d := time.date({ year := 2024, month := 3, day := 15 |}).unwrap! >>> d2 := time.date({ year := 2024, month := 3, day := 20 |}).unwrap! >>> d.compare(d2) Less
day
date.day! day: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
day_of_year
date.day_of_year! day_of_year: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> d := time.date({ year := 2024, month := 3, day := 15 |}).unwrap! >>> d.day_of_year! 75
format
date.format(layout) format: { String | String }
strftime 風に整形する。
>>> d := time.date({ year := 2024, month := 3, day := 15 |}).unwrap! >>> d.format("%Y/%m/%d") "2024/03/15"
month
date.month! month: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
to_iso
date.to_iso! to_iso: { String }
YYYY-MM-DD で整形する。
weekday
date.weekday! weekday: { Weekday }
曜日タグ (Monday..Sunday)。
year
date.year! year: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
Duration メソッド
add
dur.add(o) add: { Duration | Duration }
期間どうしの加算。
as_days
dur.as_days! as_days: { Int }
期間の総量 (Integer、0 方向 truncate)。
as_hours
dur.as_hours! as_hours: { Int }
期間の総量 (Integer、0 方向 truncate)。
as_millis
dur.as_millis! as_millis: { Int }
期間の総量 (Integer、0 方向 truncate)。
as_minutes
dur.as_minutes! as_minutes: { Int }
期間の総量 (Integer、0 方向 truncate)。
>>> dur := time.hours(2) >>> dur.as_minutes! 120
as_seconds
dur.as_seconds! as_seconds: { Int }
期間の総量 (Integer、0 方向 truncate)。
>>> dur := time.hours(2) >>> dur.as_seconds! 7200
compare
dur.compare(other) compare: { Duration | Ordering }
期間の全順序。
negate
dur.negate! negate: { Duration }
符号反転した Duration。
sub
dur.sub(o) sub: { Duration | Duration }
期間どうしの減算。
Instant メソッド
add
inst.add(dur) add: { Duration | Instant }
dur (Duration) を加算した Instant。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.add(time.hours(1)) 2024-03-15T11:20:30.250Z
add_days
inst.add_days(n) add_days: { Int | Instant }
n 日加算した Instant。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.add_days(1) 2024-03-16T10:20:30.250Z
add_months
inst.add_months(n) add_months: { Int | Instant }
n ヶ月加算 (日は月末クランプ)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.add_months(1) 2024-04-15T10:20:30.250Z
add_years
inst.add_years(n) add_years: { Int | Instant }
n 年加算 (月末クランプ)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.add_years(1) 2025-03-15T10:20:30.250Z
compare
inst.compare(other) compare: { Instant | Ordering }
epoch ミリ秒の全順序。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst2 := time.of({ year := 2024, month := 3, day := 16 |}).unwrap! >>> inst.compare(inst2) Less
date
inst.date! date: { Date }
日付部 (UTC) を Date で返す。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.date! 2024-03-15
day
inst.day! day: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.day! 15
day_of_year
inst.day_of_year! day_of_year: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.day_of_year! 75
diff
inst.diff(other) diff: { Instant | Duration }
self − other を Duration で返す。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst2 := time.of({ year := 2024, month := 3, day := 16 |}).unwrap! >>> inst2.diff(inst) Duration(13h39m29s750ms)
epoch_ms
inst.epoch_ms! epoch_ms: { Int }
epoch ミリ秒。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.epoch_ms! 1710498030250
format
inst.format(layout) format: { String | String }
strftime 風に整形する (UTC)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.format("%Y/%m/%d") "2024/03/15"
format_at
inst.format_at(layout, offset_min) format_at: { String, Int | String }
オフセット適用後の壁掛け時刻で整形する。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.format_at("%Y-%m-%d %H:%M", 540) "2024-03-15 19:20"
hour
inst.hour! hour: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.hour! 10
millisecond
inst.millisecond! millisecond: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.millisecond! 250
minute
inst.minute! minute: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.minute! 20
month
inst.month! month: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.month! 3
second
inst.second! second: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.second! 30
sub
inst.sub(dur) sub: { Duration | Instant }
dur (Duration) を減算した Instant。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.sub(time.hours(1)) 2024-03-15T09:20:30.250Z
time
inst.time! time: { Time }
時刻部 (UTC) を Time で返す。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.time! 10:20:30.250
to_iso
inst.to_iso! to_iso: { String }
RFC3339・UTC・末尾 Z で整形する。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.to_iso! "2024-03-15T10:20:30.250Z"
to_iso_at
inst.to_iso_at(offset_min) to_iso_at: { Int | String }
RFC3339・末尾 ±HH:MM (固定オフセット)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.to_iso_at(540) "2024-03-15T19:20:30.250+09:00"
weekday
inst.weekday! weekday: { Weekday }
曜日タグ (Monday..Sunday)。
year
inst.year! year: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> inst := time.of({ year := 2024, month := 3, day := 15, hour := 10, minute := 20, second := 30, milli := 250 |}).unwrap! >>> inst.year! 2024
Time メソッド
compare
tm.compare(other) compare: { Time | Ordering }
時刻の全順序。
>>> tm := time.time_of({ hour := 9, minute := 30 |}).unwrap! >>> tm2 := time.time_of({ hour := 10 |}).unwrap! >>> tm.compare(tm2) Less
format
tm.format(layout) format: { String | String }
strftime 風に整形する (時刻ディレクティブ)。
hour
tm.hour! hour: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
millisecond
tm.millisecond! millisecond: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
>>> tm := time.time_of({ hour := 9, minute := 30 |}).unwrap! >>> tm.millisecond! 0
minute
tm.minute! minute: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
second
tm.second! second: { Int }
UTC 解釈の暦/時刻フィールド (Integer)。
to_iso
tm.to_iso! to_iso: { String }
HH:MM:SS[.SSS] で整形する。