Module std.time.datetime

UTC calendar views of precise wall-clock timestamps.

Calendar conversion uses Chrono's proleptic Gregorian range, years -262143 through +262142. A timestamp outside that range remains a valid timestamp but calendar operations fail with Range. Unix time does not represent leap seconds; parsing rejects them. Explicit offsets normalize to UTC.

Use timestamp.now() for wall time and instant.now() for elapsed time.

Contents

Functions

Function format

pub fn format(value: timestamp, pattern: string) -> string fails DateTimeError

Format a timestamp using Chrono's strftime directives, including fractional seconds with %.f or %.9f. Calendar output uses UTC.

Function parse

pub fn parse(text: string, pattern: string) -> timestamp fails DateTimeError

Parse strftime-formatted text. A missing offset means UTC; an explicit offset is converted to UTC. Fractional seconds retain nanosecond precision.

Function components

pub fn components(value: timestamp) -> Components fails DateTimeError

Extract the UTC civil fields of a timestamp.

Function from_parts

pub fn from_parts(year: i64, month: i64, day: i64, hour: i64, minute: i64, second: i64, nanosecond: u32) -> timestamp fails DateTimeError

Construct a UTC timestamp from civil fields, checking their ranges.

Function year

pub fn year(value: timestamp) -> i64 fails DateTimeError

Extract the UTC year.

Function month

pub fn month(value: timestamp) -> i64 fails DateTimeError

Extract the UTC month (1–12).

Function day

pub fn day(value: timestamp) -> i64 fails DateTimeError

Extract the UTC day of month.

Function hour

pub fn hour(value: timestamp) -> i64 fails DateTimeError

Extract the UTC hour (0–23).

Function minute

pub fn minute(value: timestamp) -> i64 fails DateTimeError

Extract the UTC minute (0–59).

Function second

pub fn second(value: timestamp) -> i64 fails DateTimeError

Extract the UTC second (0–59).

Function weekday

pub fn weekday(value: timestamp) -> i64 fails DateTimeError

Return the UTC weekday (Monday = 0, Sunday = 6).

Function add_days

pub fn add_days(value: timestamp, days: i64) -> timestamp

Add elapsed 24-hour days, with ordinary checked duration arithmetic.

Function add_hours

pub fn add_hours(value: timestamp, hours: i64) -> timestamp

Add elapsed hours.

Function diff_secs

pub fn diff_secs(a: timestamp, b: timestamp) -> i64

Return whole elapsed seconds, truncating towards zero.

Function to_iso8601

pub fn to_iso8601(value: timestamp) -> string fails DateTimeError

Format UTC ISO 8601, preserving the nonzero nanosecond fraction.

Function parse_iso8601

pub fn parse_iso8601(text: string) -> timestamp fails DateTimeError

Parse ISO 8601 with Z or a numeric offset, preserving fractional seconds.

Types

Enum DateTimeError

Checked failures at the UTC calendar boundary.

Variants

Range(string)
Format(string)
Parse(string)

Struct Components

A UTC calendar view. Monday is weekday zero; Sunday is six.

Fields

year: i64
month: i64
day: i64
hour: i64
minute: i64
second: i64
nanosecond: u32
weekday: i64
days_in_month: i64