API
#time
Xu 0.8.8 API
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
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
Purpose
microsecond; returns int.
Parameters
none
Returns
int — a value of this type
millisecond
Purpose
millisecond; returns int.
Parameters
none
Returns
int — a value of this type
second
Purpose
second; returns int.
Parameters
none
Returns
int — a value of this type
minute
Purpose
minute; returns int.
Parameters
none
Returns
int — a value of this type
hour
Purpose
hour; returns int.
Parameters
none
Returns
int — a value of this type
now
Purpose
Current time.
Parameters
none
Returns
int — a value of this type
sleep
Purpose
Block for a duration.
Parameters
d int- d (int)
since
Purpose
since; returns int.
Parameters
t int- t (int)
Returns
int — a value of this type
struct Time
pub struct Time {
pub sec int
pub nsec int
}
Purpose
Public struct `Time`.
Parameters
sec int- field (int)
nsec int- field (int)
unix
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
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
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
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
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
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
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
pub fn unix_milli(ms int) Time
Purpose
Unix milli.
Parameters
ms int- ms (int)
Returns
Time — a value of this type
unix_micro
pub fn unix_micro(us int) Time
Purpose
Unix micro.
Parameters
us int- us (int)
Returns
Time — a value of this type
(Time) add
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
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
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
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
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
Purpose
Now time.
Parameters
none
Returns
Time — a value of this type
parse_duration
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
pub fn format_duration(d int) string
Purpose
Format as duration.
Parameters
d int- d (int)
Returns
string — result string
(Time) format_rfc3339
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Purpose
until; returns int.
Parameters
t Time- t (Time)
Returns
int — a value of this type
struct Timer
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
pub fn new_timer(d int) Timer
Purpose
Construct timer.
Parameters
d int- d (int)
Returns
Timer — a value of this type
(Timer) stop
Purpose
Call `stop` on `Timer`.
Parameters
t Timer- receiver Timer (value receiver)
struct Ticker
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
pub fn new_ticker(d int) Ticker
Purpose
Construct ticker.
Parameters
d int- d (int)
Returns
Ticker — a value of this type
(Ticker) stop
Purpose
Call `stop` on `Ticker`.
Parameters
t Ticker- receiver Ticker (value receiver)
struct Location
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
Purpose
utc; returns Location.
Parameters
none
Returns
Location — a value of this type
fixed_zone
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
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
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
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
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
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
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
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
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