XU XUv0.8.8
中文

API

#time

import: #time

counts: 26 fns, 36 methods, 7 types, 0 consts, 0 ifaces

Duration is int nanoseconds. now/sleep, Time, Timer/Ticker (xu+chan+sleep). No IANA zones.

nanosecond

XuAPI
pub fn nanosecond() int

Purpose

Duration is an int count of nanoseconds. now/since use the monotonic clock now_time/until use wall_time_ns (Unix epoch). sleep wraps the hosted sleep primitive. Freestanding rejects all hosted clock builtins at check time. Location is UTC or a fixed offset (`fixed_zone`). There is no IANA tzdata or DST. `load_location` accepts "", "UTC", "GMT", and `UTC±H[H][:MM]` `GMT±H[H][:MM]`. Time itself stays Unix UTC; `*_in(loc)` `format_rfc3339_in` apply offset.

Parameters

none

Returns

int — a value of this type

microsecond

XuAPI
pub fn microsecond() int

Purpose

microsecond; returns int.

Parameters

none

Returns

int — a value of this type

millisecond

XuAPI
pub fn millisecond() int

Purpose

millisecond; returns int.

Parameters

none

Returns

int — a value of this type

second

XuAPI
pub fn second() int

Purpose

second; returns int.

Parameters

none

Returns

int — a value of this type

minute

XuAPI
pub fn minute() int

Purpose

minute; returns int.

Parameters

none

Returns

int — a value of this type

hour

XuAPI
pub fn hour() int

Purpose

hour; returns int.

Parameters

none

Returns

int — a value of this type

now

XuAPI
pub fn now() int

Purpose

Current time.

Parameters

none

Returns

int — a value of this type

sleep

XuAPI
pub fn sleep(d int)

Purpose

Block for a duration.

Parameters

d int
d (int)

since

XuAPI
pub fn since(t int) int

Purpose

since; returns int.

Parameters

t int
t (int)

Returns

int — a value of this type

struct Time

XuAPI
pub struct Time {
    pub sec int
    pub nsec int
}

Purpose

Public struct `Time`.

Parameters

sec int
field (int)
nsec int
field (int)

unix

XuAPI
pub fn unix(sec int, nsec int) Time

Purpose

unix; returns Time.

Parameters

sec int
sec (int)
nsec int
nsec (int)

Returns

Time — a value of this type

unix_from_ns

XuAPI
pub fn unix_from_ns(ns int) Time

Purpose

Unix from ns.

Parameters

ns int
ns (int)

Returns

Time — a value of this type

(Time) unix

XuAPI
pub fn (t Time) unix() int

Purpose

Call `unix` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) is_zero

XuAPI
pub fn (t Time) is_zero() bool

Purpose

Method on `Time`: whether it is zero.

Parameters

t Time
receiver Time (value receiver)

Returns

bool — true or false

(Time) unix_nano

XuAPI
pub fn (t Time) unix_nano() int

Purpose

Method on `Time`: unix nano.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) unix_milli

XuAPI
pub fn (t Time) unix_milli() int

Purpose

Method on `Time`: unix milli.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) unix_micro

XuAPI
pub fn (t Time) unix_micro() int

Purpose

Method on `Time`: unix micro.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

unix_milli

XuAPI
pub fn unix_milli(ms int) Time

Purpose

Unix milli.

Parameters

ms int
ms (int)

Returns

Time — a value of this type

unix_micro

XuAPI
pub fn unix_micro(us int) Time

Purpose

Unix micro.

Parameters

us int
us (int)

Returns

Time — a value of this type

(Time) add

XuAPI
pub fn (t Time) add(d int) Time

Purpose

Method on `Time`: add.

Parameters

t Time
receiver Time (value receiver)
d int
d (int)

Returns

Time — a value of this type

(Time) sub

XuAPI
pub fn (t Time) sub(u Time) int

Purpose

Method on `Time`: subtract.

Parameters

t Time
receiver Time (value receiver)
u Time
u (Time)

Returns

int — a value of this type

(Time) before

XuAPI
pub fn (t Time) before(u Time) bool

Purpose

Call `before` on `Time`.

Parameters

t Time
receiver Time (value receiver)
u Time
u (Time)

Returns

bool — true or false

(Time) after

XuAPI
pub fn (t Time) after(u Time) bool

Purpose

Call `after` on `Time`.

Parameters

t Time
receiver Time (value receiver)
u Time
u (Time)

Returns

bool — true or false

(Time) equal

XuAPI
pub fn (t Time) equal(u Time) bool

Purpose

Method on `Time`: report whether the two values are equal.

Parameters

t Time
receiver Time (value receiver)
u Time
u (Time)

Returns

bool — true or false

now_time

XuAPI
pub fn now_time() Time

Purpose

Now time.

Parameters

none

Returns

Time — a value of this type

parse_duration

XuAPI
pub fn parse_duration(s &string) int

Purpose

Parse as duration. Throws on failure.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)

Returns

int — a value of this type

format_duration

XuAPI
pub fn format_duration(d int) string

Purpose

Format as duration.

Parameters

d int
d (int)

Returns

string — result string

(Time) format_rfc3339

XuAPI
pub fn (t Time) format_rfc3339() string

Purpose

Method on `Time`: format as rfc3339.

Parameters

t Time
receiver Time (value receiver)

Returns

string — result string

(Time) format_log

XuAPI
pub fn (t Time) format_log(date int, tod int, micro int) string

Purpose

log header shape: "2006/01/02 15:04:05[.micros]" (UTC). No trailing space. date/tod/micro are 0 or 1 switches.

Parameters

t Time
receiver Time (value receiver)
date int
date (int)
tod int
tod (int)
micro int
micro (int)

Returns

string — result string

parse_rfc3339

XuAPI
pub fn parse_rfc3339(s &string) Time

Purpose

Parse as rfc3339. Throws on failure.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)

Returns

Time — a value of this type

(Time) add_date

XuAPI
pub fn (t Time) add_date(years int, months int, days int) Time

Purpose

Method on `Time`: add date.

Parameters

t Time
receiver Time (value receiver)
years int
years (int)
months int
months (int)
days int
days (int)

Returns

Time — a value of this type

date

XuAPI
pub fn date(year int, month int, day int, hour int, min int, sec int, nsec int) Time

Purpose

date; returns Time.

Parameters

year int
year (int)
month int
month (int)
day int
day (int)
hour int
hour (int)
min int
minimum (int)
sec int
sec (int)
nsec int
nsec (int)

Returns

Time — a value of this type

(Time) year

XuAPI
pub fn (t Time) year() int

Purpose

Call `year` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) month

XuAPI
pub fn (t Time) month() int

Purpose

Call `month` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) day

XuAPI
pub fn (t Time) day() int

Purpose

Call `day` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) year_day

XuAPI
pub fn (t Time) year_day() int

Purpose

year_day is Time.YearDay: 1..365 (366 in a leap year).

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

struct Clock

XuAPI
pub struct Clock {
    pub hour int
    pub min int
    pub sec int
}

Purpose

Public struct `Clock`.

Parameters

hour int
field (int)
min int
minimum
sec int
field (int)

(Time) clock

XuAPI
pub fn (t Time) clock() Clock

Purpose

Call `clock` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

Clock — a value of this type

(Time) nanosecond

XuAPI
pub fn (t Time) nanosecond() int

Purpose

Call `nanosecond` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

struct DateParts

XuAPI
pub struct DateParts {
    pub year int
    pub month int
    pub day int
}

Purpose

date_parts is Time.Date's three results (year, month, day) as a struct.

Parameters

year int
field (int)
month int
field (int)
day int
field (int)

(Time) date_parts

XuAPI
pub fn (t Time) date_parts() DateParts

Purpose

Method on `Time`: date parts.

Parameters

t Time
receiver Time (value receiver)

Returns

DateParts — a value of this type

(Time) hour

XuAPI
pub fn (t Time) hour() int

Purpose

Call `hour` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) minute

XuAPI
pub fn (t Time) minute() int

Purpose

Call `minute` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

(Time) second

XuAPI
pub fn (t Time) second() int

Purpose

Call `second` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

struct ISOWeek

XuAPI
pub struct ISOWeek {
    pub year int
    pub week int
}

Purpose

Public struct `ISOWeek`.

Parameters

year int
field (int)
week int
field (int)

(Time) iso_week

XuAPI
pub fn (t Time) iso_week() ISOWeek

Purpose

Method on `Time`: iso week.

Parameters

t Time
receiver Time (value receiver)

Returns

ISOWeek — a value of this type

(Time) weekday

XuAPI
pub fn (t Time) weekday() int

Purpose

Call `weekday` on `Time`.

Parameters

t Time
receiver Time (value receiver)

Returns

int — a value of this type

weekday_name

XuAPI
pub fn weekday_name(d int) string

Purpose

weekday_name is time.Weekday.String (English, all platforms).

Parameters

d int
d (int)

Returns

string — result string

month_name

XuAPI
pub fn month_name(m int) string

Purpose

month_name is time.Month.String (English, 1..12; else "").

Parameters

m int
m (int)

Returns

string — result string

(Time) truncate

XuAPI
pub fn (t Time) truncate(d int) Time

Purpose

Call `truncate` on `Time`.

Parameters

t Time
receiver Time (value receiver)
d int
d (int)

Returns

Time — a value of this type

(Time) round

XuAPI
pub fn (t Time) round(d int) Time

Purpose

Call `round` on `Time`.

Parameters

t Time
receiver Time (value receiver)
d int
d (int)

Returns

Time — a value of this type

until

XuAPI
pub fn until(t Time) int

Purpose

until; returns int.

Parameters

t Time
t (Time)

Returns

int — a value of this type

struct Timer

XuAPI
pub struct Timer {
    pub c chan int
    pub stop chan int
}

Purpose

Public struct `Timer`.

Parameters

c chan int
byte or character code
stop chan int
field (channel; type chan int)

new_timer

XuAPI
pub fn new_timer(d int) Timer

Purpose

Construct timer.

Parameters

d int
d (int)

Returns

Timer — a value of this type

(Timer) stop

XuAPI
pub fn (t Timer) stop()

Purpose

Call `stop` on `Timer`.

Parameters

t Timer
receiver Timer (value receiver)

struct Ticker

XuAPI
pub struct Ticker {
    pub c chan int
    pub stop chan int
}

Purpose

Public struct `Ticker`.

Parameters

c chan int
byte or character code
stop chan int
field (channel; type chan int)

new_ticker

XuAPI
pub fn new_ticker(d int) Ticker

Purpose

Construct ticker.

Parameters

d int
d (int)

Returns

Ticker — a value of this type

(Ticker) stop

XuAPI
pub fn (t Ticker) stop()

Purpose

Call `stop` on `Ticker`.

Parameters

t Ticker
receiver Ticker (value receiver)

struct Location

XuAPI
pub struct Location {
    pub name string
    pub offset_sec int
    pub dst_offset_sec int
    pub has_dst int
    pub dst_sm int
    pub dst_sn int
    pub dst_sd int
    pub dst_st int
    pub dst_em int
    pub dst_en int
    pub dst_ed int
    pub dst_et int
    pub before_off int
    pub trans_sec []int
    pub trans_off []int
}

Purpose

Location is a named UTC offset in seconds east of UTC, plus optional POSIX DST rules and TZif transition tables. IANA names are loaded from usr/share/zoneinfo (Unix TZif v2 64-bit transitions + POSIX footer). No bundled tzdata; Windows has no zoneinfo path in v1.

Parameters

name string
name
offset_sec int
field (int)
dst_offset_sec int
field (int)
has_dst int
field (int)
dst_sm int
field (int)
dst_sn int
field (int)
dst_sd int
field (int)
dst_st int
field (int)
dst_em int
field (int)
dst_en int
field (int)
dst_ed int
field (int)
dst_et int
field (int)
before_off int
field (int)
trans_sec []int
field ([]int)
trans_off []int
field ([]int)

utc

XuAPI
pub fn utc() Location

Purpose

utc; returns Location.

Parameters

none

Returns

Location — a value of this type

fixed_zone

XuAPI
pub fn fixed_zone(name string, offset_sec int) Location

Purpose

Fixed zone.

Parameters

name string
name (string)
offset_sec int
offset_sec (int)

Returns

Location — a value of this type

load_location

XuAPI
pub fn load_location(name string) Location

Purpose

Load location. Throws on failure.

Parameters

name string
name (string)

Returns

Location — a value of this type

(Time) year_in

XuAPI
pub fn (t Time) year_in(loc &Location) int

Purpose

Method on `Time`: year in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

int — a value of this type

(Time) month_in

XuAPI
pub fn (t Time) month_in(loc &Location) int

Purpose

Method on `Time`: month in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

int — a value of this type

(Time) day_in

XuAPI
pub fn (t Time) day_in(loc &Location) int

Purpose

Method on `Time`: day in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

int — a value of this type

(Time) hour_in

XuAPI
pub fn (t Time) hour_in(loc &Location) int

Purpose

Method on `Time`: hour in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

int — a value of this type

(Time) minute_in

XuAPI
pub fn (t Time) minute_in(loc &Location) int

Purpose

Method on `Time`: minute in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

int — a value of this type

(Time) second_in

XuAPI
pub fn (t Time) second_in(loc &Location) int

Purpose

Method on `Time`: second in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

int — a value of this type

(Time) format_rfc3339_in

XuAPI
pub fn (t Time) format_rfc3339_in(loc &Location) string

Purpose

Method on `Time`: format as rfc3339 in.

Parameters

t Time
receiver Time (value receiver)
loc &Location
loc (borrowed; caller keeps it; type &Location)

Returns

string — result string