time/core

sourcetime/core.sx

Sleep

when windowsprivate
extern (C, header) fn Sleep(ms: u32) void = trust { ... } = "Sleep"

TimeVal

extern type TimeVal = { tv_sec: i64, tv_usec: i64 }

Fields

NameType
tv_seci64
tv_useci64

DateTime

type DateTime = { year: mut i64, month: mut i64, day: mut i64, hour: mut i64, minute: mut i64, second: mut i64, millis: mut i64 }

A DateTime holds a calendar date and wall-clock time.

Fields

NameType
yearmut i64
monthmut i64
daymut i64
hourmut i64
minutemut i64
secondmut i64
millismut i64

new

pub fn (DateTime) new(year: i64, month: i64, day: i64, hour: i64, minute: i64, second: i64, millis: i64) DateTime

Construct and return a new DateTime on the stack. All fields are validated on construction.

now

pub fn (DateTime) now() DateTime

Return the current local time as a DateTime. Wraps the C localtime / gettimeofday pair.

unix_now

pub fn unix_now() i64

Return the current Unix timestamp in seconds since epoch.

unix_now_millis

pub fn unix_now_millis() i64

Return the current Unix timestamp in milliseconds since epoch.

unix_now_micros

pub fn unix_now_micros() i64

Return the current Unix timestamp in microseconds since epoch.

now_ns

pub fn now_ns() i64

Return the current Unix timestamp in nanoseconds since epoch. The time value is kept on the stack; no allocator is required.

sleep_millis

pub fn sleep_millis(ms: i64) void = trust { ... }

Sleep the current thread for approximately ms milliseconds.

year

pub fn (DateTime) year(dt: DateTime) i64

Read the year field.

month

pub fn (DateTime) month(dt: DateTime) i64

Read the month field (1–12).

day

pub fn (DateTime) day(dt: DateTime) i64

Read the day field (1–31).

hour

pub fn (DateTime) hour(dt: DateTime) i64

Read the hour field (0–23).

minute

pub fn (DateTime) minute(dt: DateTime) i64

Read the minute field (0–59).

second

pub fn (DateTime) second(dt: DateTime) i64

Read the second field (0–59).

millis

pub fn (DateTime) millis(dt: DateTime) i64

Read the milliseconds field (0–999).

to_unix

pub fn (DateTime) to_unix(dt: DateTime) i64

Convert a DateTime to a Unix timestamp (seconds since epoch). Does not account for leap seconds.

is_leap_year

pub fn (DateTime) is_leap_year(dt: DateTime) bool

Return true if the year is a leap year.

days_in_month

pub fn (DateTime) days_in_month(dt: DateTime) i64

Return the number of days in the month of this DateTime.

equals

pub fn (DateTime) equals(a: DateTime, b: DateTime) bool

Return true if two DateTimes represent the same instant (ignoring millis).

before

pub fn (DateTime) before(a: DateTime, b: DateTime) bool

Return true if a is strictly before b.

after

pub fn (DateTime) after(a: DateTime, b: DateTime) bool

Return true if a is strictly after b.

diff_seconds

pub fn (DateTime) diff_seconds(a: DateTime, b: DateTime) i64

Return the difference in seconds between two DateTimes (a - b).