core/time
time
Types
8Benchmark_Error
Benchmark_Error :: enum int {
Okay = 0,
Allocation_Error = 1,
}SourceBenchmark helpers Errors returned by the benchmark() procedure.
Benchmark_Options
Benchmark_Options :: struct {
// The initialization procedure. `benchmark()` will call this before taking measurements.
setup: _,
}SourceOptions for benchmarking.
Duration
Duration :: i64SourceType representing duration, with nanosecond precision. This is the regular Unix timestamp, scaled to nanosecond precision.
Month
Month :: enum int {
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12,
}SourceType representing a month.
Stopwatch
Stopwatch :: struct {
running: bool,
_start_time: Tick,
_accumulation: Duration,
}SourceType representing a stopwatch.
The stopwatch is used for measuring the total time in multiple "runs". When the stopwatch is started, it starts counting time. When the stopwatch is stopped, the difference in time between the last start and the stop is added to the total. When the stopwatch resets, the total is reset.
Tick
Tick :: struct {
_nsec: i64,
}SourceType representing monotonic time, useful for measuring durations.
Time
Time :: struct {
_nsec: i64,
}SourceSpecifies time since the UNIX epoch, with nanosecond precision.
Capable of representing any time within the following range:
min: 1677-09-21 00:12:44.145224192 +0000 UTCmax: 2262-04-11 23:47:16.854775807 +0000 UTC
Weekday
Weekday :: enum int {
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
}SourceType representing a weekday.
Constants
31ABSOLUTE_TO_INTERNAL
ABSOLUTE_TO_INTERNAL :: i64 = i64(-9223371966579724800)Sourcei64((ABSOLUTE_ZERO_YEAR - 1) 365.2425 SECONDS_PER_DAY);
ABSOLUTE_TO_UNIX
ABSOLUTE_TO_UNIX :: _ = -UNIX_TO_ABSOLUTESourceABSOLUTE_ZERO_YEAR
ABSOLUTE_ZERO_YEAR :: i64 = i64(-292277022399)SourceDay is chosen so that 2001-01-01 is Monday in the calculations
DAYS_PER_100_YEARS
DAYS_PER_100_YEARS :: 365*100 + 24SourceDays in 100 years, with leap days.
DAYS_PER_400_YEARS
DAYS_PER_400_YEARS :: 365*400 + 97SourceDays in 400 years, with leap days.
DAYS_PER_4_YEARS
DAYS_PER_4_YEARS :: 365*4 + 1SourceDays in 4 years, with leap days.
Hour
Hour :: _ = 60 * MinuteSourceThe duration equal to one hour (3600 seconds).
INTERNAL_TO_ABSOLUTE
INTERNAL_TO_ABSOLUTE :: i64 = -ABSOLUTE_TO_INTERNALSourceINTERNAL_TO_UNIX
INTERNAL_TO_UNIX :: i64 = -UNIX_TO_INTERNALSourceINTERNAL_TO_WALL
INTERNAL_TO_WALL :: i64 = -WALL_TO_INTERNALSourceIS_SUPPORTED
IS_SUPPORTED :: _IS_SUPPORTEDSourceValue specifying whether the time procedures are supported by the current platform.
MAX_DURATION
MAX_DURATION :: Duration = Duration(1<<63 - 1)SourceMaximum representable duration.
MIN_DURATION
MIN_DURATION :: Duration = Duration(-1 << 63)SourceMinimum representable duration.
MIN_HMS_12_LEN
MIN_HMS_12_LEN :: 11SourceMIN_HMS_LEN
MIN_HMS_LEN :: 8SourceMIN_YYYY_DATE_LEN
MIN_YYYY_DATE_LEN :: 10SourceMIN_YY_DATE_LEN
MIN_YY_DATE_LEN :: 8SourceMicrosecond
Microsecond :: _ = 1000 * NanosecondSourceThe duration equal to one microsecond (1e-6 seconds).
Millisecond
Millisecond :: _ = 1000 * MicrosecondSourceThe duration equal to one millisecond (1e-3 seconds).
Minute
Minute :: _ = 60 * SecondSourceThe duration equal to one minute (60 seconds).
Nanosecond
Nanosecond :: Duration = Duration(1)SourceThe duration equal to one nanosecond (1e-9 seconds).
SECONDS_PER_DAY
SECONDS_PER_DAY :: 24 * SECONDS_PER_HOURSourceNumber of seconds in a day (without leap seconds).
SECONDS_PER_HOUR
SECONDS_PER_HOUR :: 60 * SECONDS_PER_MINUTESourceNumber of seconds in an hour (without leap seconds).
SECONDS_PER_MINUTE
SECONDS_PER_MINUTE :: 60SourceNumber of seconds in a minute (without leap seconds).
SECONDS_PER_WEEK
SECONDS_PER_WEEK :: 7 * SECONDS_PER_DAYSourceNumber of seconds in a week (without leap seconds).
Second
Second :: _ = 1000 * MillisecondSourceThe duration equal to one second.
UNIX_TO_ABSOLUTE
UNIX_TO_ABSOLUTE :: _ = UNIX_TO_INTERNAL + INTERNAL_TO_ABSOLUTESourceUNIX_TO_INTERNAL
UNIX_TO_INTERNAL :: i64 = i64((1969*365 + 1969/4 - 1969/100 + 1969/400) * SECONDS_PER_DAY)SourceWALL_TO_INTERNAL
WALL_TO_INTERNAL :: i64 = i64((1884*365 + 1884/4 - 1884/100 + 1884/400) * SECONDS_PER_DAY)Source_IS_SUPPORTED
_IS_SUPPORTED :: trueSource_IS_SUPPORTED
_IS_SUPPORTED :: trueSourceVariables
1days_before
days_before :: [?]i32 = [?]i32{
0,
31,
31 + 28,
31 + 28 + 31,
31 + 28 + 31 + 30,
31 + 28 + 31 + 30 + 31,
31 + 28 + 31 + 30 + 31 + 30,
31 + 28 + 31 + 30 + 31 + 30 + 31,
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
31 + 28 + 31 + 30 SourceDays before each month in a year, not counting the leap day on february 29th.
Procedures
77SCOPED_TICK_DURATION
SCOPED_TICK_DURATION :: proc(d: ^Duration) -> (Tick)SourceCapture the duration the code in the current scope takes to execute.
_get_tsc_frequency
_get_tsc_frequency :: proc() -> (bool, u64)Source_now
_now :: proc() -> (Time)Source_now
_now :: proc() -> (Time)Source_sleep
_sleep :: proc(d: Duration)Source_sleep
_sleep :: proc(d: Duration)Source_tick_duration_end
_tick_duration_end :: proc(d: ^Duration, t: Tick)Source_tick_now
_tick_now :: proc() -> (Tick)Source_tick_now
_tick_now :: proc() -> (Tick)Source_yield
_yield :: proc()Source_yield
_yield :: proc()Sourceaccurate_sleep
accurate_sleep :: proc(d: Duration)SourceAccurate sleep
This procedure sleeps for the duration specified by d, very accurately.
Note: Implementation borrowed from: this source
Note(linux): The accuracy is within around 4µs (microseconds), in the worst case.
Note(windows): The accuracy depends but is comparable with regular sleep in the worst case. To get the same kind of accuracy as on Linux, have your program call windows.timeBeginPeriod(1) to tell Windows to use a more accurate timer for your process. Additionally your program should call windows.timeEndPeriod(1) once you're done with accurate_sleep.
benchmark
benchmark :: proc(options: ^Benchmark_Options, allocator: mem.Allocator = context.allocator) -> (err: Benchmark_Error)SourceBenchmark a procedure.
This procedure produces a benchmark. The procedure specified in the bench field of the options parameter will be benchmarked. The following metrics can be obtained:
- Run time of the procedure
- Number of elements per second processed on average
- Number of bytes per second this processed on average
In order to obtain these metrics, the bench() procedure writes to options struct the number of elements or bytes it has processed.
clock_from_duration
clock_from_duration :: proc(d: Duration) -> (hour: int, min: int, sec: int)SourceObtain the time components from a duration.
clock_from_seconds
clock_from_seconds :: proc(in_sec: u64) -> (hour: int, min: int, sec: int)SourceObtain the time components from the number of seconds.
clock_from_stopwatch
clock_from_stopwatch :: proc(s: Stopwatch) -> (hour: int, min: int, sec: int)SourceObtain the time components from a stopwatch's total.
clock_from_time
clock_from_time :: proc(t: Time) -> (hour: int, min: int, sec: int)SourceObtain the time components from a time.
components_to_time
components_to_time :: proc(
any_int,
any_int,
any_int,
any_int,
any_int,
second: i64,
nsec: _,
) -> (t: Time, ok: bool)SourceConvert datetime components into time.
This procedure calculates the time from datetime components supplied in the arguments to this procedure. If the datetime components don't represent a valid datetime, the function returns false in the second argument.
compound_to_time
compound_to_time :: proc(datetime: dt.DateTime) -> (t: Time, ok: bool)SourceConvert datetime into time.
If the datetime represents a time outside of a valid range, false is returned as the second return value. See Time for the representable range.
date
date :: proc(t: Time) -> (year: int, month: Month, day: int)SourceParse time into date components.
day
day :: proc(t: Time) -> (day: int)SourceObtain the day of the date specified by time.
diff
diff :: proc(start: Time, end: Time) -> (Duration)SourceCalculate the duration elapsed between two times.
duration_hours
duration_hours :: proc(d: Duration) -> (f64)SourceObtain the number of hours in a duration.
duration_microseconds
duration_microseconds :: proc(d: Duration) -> (f64)SourceObtain the number of microseconds in a duration.
duration_milliseconds
duration_milliseconds :: proc(d: Duration) -> (f64)SourceObtain the number of milliseconds in a duration.
duration_minutes
duration_minutes :: proc(d: Duration) -> (f64)SourceObtain the number of minutes in a duration.
duration_nanoseconds
duration_nanoseconds :: proc(d: Duration) -> (i64)SourceObtain the number of nanoseconds in a duration.
duration_round
duration_round :: proc(d: Duration, m: Duration) -> (Duration)SourceRound a duration to a specific unit
This procedure rounds the duration to a specific unit
Note: Any duration can be supplied as a unit.
Inputs:
- d: The duration to round
- m: The unit to round to
Returns:
- The duration
d, rounded to the unit specified bym
Example:
time.duration_round(my_duration, time.Second)duration_seconds
duration_seconds :: proc(d: Duration) -> (f64)SourceObtain the number of seconds in a duration.
duration_to_string_hms
duration_to_string_hms :: proc(d: Duration, buf: []u8) -> (res: string)SourceFormats a Duration as a 24-hour hh:mm:ss string.
Does not allocate
Inputs:
- d: The Duration to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by buf
Example:
buf: [MIN_HMS_LEN]u8
d := time.since(earlier)
fmt.println(time.to_string_hms(now, buf[:]))duration_truncate
duration_truncate :: proc(d: Duration, m: Duration) -> (Duration)SourceTruncate the duration to the specified unit.
This procedure truncates the duration d to the unit specified by m.
Note: Any duration can be supplied as a unit.
Inputs:
- d: The duration to truncate.
- m: The unit to truncate to.
Returns:
- The duration
d, truncated to the unit specified bym.
Example:
time.duration_round(my_duration, time.Second)from_nanoseconds
from_nanoseconds :: proc(nsec: i64) -> (Time)SourceObtain time from unix nanoseconds.
has_invariant_tsc
has_invariant_tsc :: proc() -> (bool)SourceCheck if the CPU has invariant TSC.
This procedure checks if the CPU contains an invariant TSC (Time stamp counter). Invariant TSC is a feature of modern processors that allows them to run their TSC at a fixed frequency, independent of ACPI state, and CPU frequency.
is_leap_year
is_leap_year :: proc(year: int) -> (leap: bool)SourceCheck if a year is a leap year.
iso8601_to_components
iso8601_to_components :: proc(iso_datetime: string) -> (res: dt.DateTime, utc_offset: int, is_leap: bool, consumed: int)SourceParse an ISO 8601 string into a datetime and a UTC offset in minutes.
This procedure parses an ISO 8601 string of roughly the following format:
YYYY-MM-DD[Tt]HH:mm:ss[.nn][Zz][+-]HH:mmAnd returns datetime, in UTC represented by that string, and the UTC offset, in minutes.
Inputs:
iso_datetime: The string to be parsed
Returns:
res: The parsed datetime, in UTC.utc_offset: The UTC offset, in minutes.is_leap: Specifies whether the moment was a leap second.consumed: The number of bytes consumed by parsing the string.
Notes:
- This procedure performs no validation on whether components are valid,
e.g. it'll return hour = 25 if that's what it's given in the specified string.
iso8601_to_time_and_offset
iso8601_to_time_and_offset :: proc(iso_datetime: string, is_leap: ^bool) -> (res: Time, utc_offset: int, consumed: int)SourceParse an ISO 8601 string into a time and a UTC offset in minutes.
This procedure parses an ISO 8601 string of roughly the following format:
YYYY-MM-DD[Tt]HH:mm:ss[.nn][Zz][+-]HH:mmAnd returns time, in UTC represented by that string, and the UTC offset, in minutes.
Inputs:
iso_datetime: The string to be parsed.is_leap: Optional output parameter, specifying if the moment was a leap second.
Returns:
res: The time in UTC.utc_offset: The UTC offset of the time, in minutes.consumed: Number of bytes consumed by parsing the string.
Notes:
- Only 4-digit years are accepted.
- Leap seconds are smeared into 23:59:59.
iso8601_to_time_utc
iso8601_to_time_utc :: proc(iso_datetime: string, is_leap: ^bool) -> (res: Time, consumed: int)SourceParse an ISO 8601 string into a time with UTC offset applied to it.
This procedure parses an ISO 8601 string of roughly the following format:
YYYY-MM-DD[Tt]HH:mm:ss[.nn][Zz][+-]HH:mmAnd returns time, in UTC represented by that string. In case the timezone offset is specified in the string, that timezone is applied to time.
Inputs:
iso_datetime: The string to be parsed.is_leap: Optional output parameter, specifying if the moment was a leap second.
Returns:
res: The time represented byiso_datetime, with UTC offset applied.consumed: Number of bytes consumed by parsing the string.
Notes:
- Only 4-digit years are accepted.
- Leap seconds are smeared into 23:59:59.
month
month :: proc(t: Time) -> (month: Month)SourceObtain the month of the date specified by time.
now
now :: proc() -> (Time)SourceObtain the current time.
precise_clock_from_duration
precise_clock_from_duration :: proc(d: Duration) -> (hour: int, min: int, sec: int, nanos: int)SourceObtain the time components from a duration, including nanoseconds.
precise_clock_from_stopwatch
precise_clock_from_stopwatch :: proc(s: Stopwatch) -> (hour: int, min: int, sec: int, nanos: int)SourceObtain the time components from a stopwatch's total, including nanoseconds
precise_clock_from_time
precise_clock_from_time :: proc(t: Time) -> (hour: int, min: int, sec: int, nanos: int)SourceObtain the time components from a time, including nanoseconds.
read_cycle_counter
read_cycle_counter :: proc() -> (u64)SourceRead the timestamp counter of the CPU.
rfc3339_to_components
rfc3339_to_components :: proc(rfc_datetime: string) -> (res: dt.DateTime, utc_offset: int, is_leap: bool, consumed: int)SourceParse an RFC 3339 string into a datetime and a UTC offset in minutes.
This procedure parses the specified RFC 3339 strings of roughly the following format:
YYYY-MM-DD[Tt]HH:mm:ss[.nn][Zz][+-]HH:mmAnd returns the datetime, in UTC and the UTC offset, in minutes, that were represented by the RFC 3339 string.
Inputs:
rfc_datetime: The RFC 3339 string to parse.
Returns:
res: The datetime, in UTC, that was parsed from the RFC 3339 string.utc_offset: The UTC offset, in minutes, that was parsed from the RFC 3339
string.
is_leap: Specifies whether the moment was a leap second.consumed: Number of bytes consumed by parsing the string.
Performs no validation on whether components are valid, e.g. it'll return hour = 25 if that's what it's given
rfc3339_to_time_and_offset
rfc3339_to_time_and_offset :: proc(rfc_datetime: string, is_leap: ^bool) -> (res: Time, utc_offset: int, consumed: int)SourceParse an RFC 3339 string into a time and a UTC offset in minutes.
This procedure parses the specified RFC 3339 strings of roughly the following format:
YYYY-MM-DD[Tt]HH:mm:ss[.nn][Zz][+-]HH:mmAnd returns the time, in UTC and a UTC offset, in minutes, that were represented by the RFC 3339 string.
Inputs:
rfc_datetime: The RFC 3339 string to be parsed.is_leap: Optional output parameter specifying whether the moment was a
leap second.
Returns:
res: The time, in UTC, that was parsed from the RFC 3339 string.utc_offset: The UTC offset, in minutes, that was parsed from the RFC 3339
string.
consumed: The number of bytes consumed by parsing the string.
Notes:
- Only 4-digit years are accepted.
- Leap seconds are smeared into 23:59:59.
rfc3339_to_time_utc
rfc3339_to_time_utc :: proc(rfc_datetime: string, is_leap: ^bool) -> (res: Time, consumed: int)SourceParse an RFC 3339 string into time with a UTC offset applied to it.
This procedure parses the specified RFC 3339 strings of roughly the following format:
YYYY-MM-DD[Tt]HH:mm:ss[.nn][Zz][+-]HH:mmAnd returns the time that was represented by the RFC 3339 string, with the UTC offset applied to it.
Inputs:
rfc_datetime: An RFC 3339 string to parse.is_leap: Optional output parameter specifying whether the moment was a leap
second.
Returns:
res: The time, with UTC offset applied, that was parsed from the RFC 3339
string.
consumed: The number of bytes consumed by parsing the RFC 3339 string.
Notes:
- Only 4-digit years are accepted.
- Leap seconds are smeared into 23:59:59.
since
since :: proc(start: Time) -> (Duration)SourceCalculate the duration elapsed since a specific time.
sleep
sleep :: proc(d: Duration)SourceSleep for the specified duration.
stopwatch_duration
stopwatch_duration :: proc(stopwatch: Stopwatch) -> (Duration)SourceObtain the total time, counted by the stopwatch.
This procedure obtains the total time, counted by the stopwatch. If the stopwatch isn't stopped at the time of calling this procedure, the time between the last start and the current time is also accounted for.
stopwatch_reset
stopwatch_reset :: proc(stopwatch: ^Stopwatch)SourceReset the stopwatch.
stopwatch_start
stopwatch_start :: proc(stopwatch: ^Stopwatch)SourceStart the stopwatch.
stopwatch_stop
stopwatch_stop :: proc(stopwatch: ^Stopwatch)SourceStop the stopwatch.
tick_add
tick_add :: proc(t: Tick, d: Duration) -> (Tick)SourceAdd duration to a tick.
tick_diff
tick_diff :: proc(start: Tick, end: Tick) -> (Duration)SourceObtain the difference between ticks.
tick_lap_time
tick_lap_time :: proc(prev: ^Tick) -> (Duration)SourceIncrementally obtain durations since last tick.
This procedure returns the duration between the current tick and the tick stored in prev pointer, and then stores the current tick in location, specified by prev. If the prev pointer contains an zero-initialized tick, then the returned duration is 0.
This procedure is meant to be used in a loop, or in other scenarios, where one might want to obtain time between multiple ticks at specific points.
tick_now
tick_now :: proc() -> (Tick)SourceObtain the current tick.
tick_since
tick_since :: proc(start: Tick) -> (Duration)SourceObtain the duration since last tick.
time_add
time_add :: proc(t: Time, d: Duration) -> (Time)SourceAdd duration to a time.
time_to_compound
time_to_compound :: proc(t: Time) -> (dt.DateTime, bool)SourceAlias for time_to_datetime.
time_to_datetime
time_to_datetime :: proc(t: Time) -> (dt.DateTime, bool)SourceConvert time into datetime.
time_to_rfc3339
time_to_rfc3339 :: proc(time: Time, utc_offset: int, include_nanos: untyped boolean = true, allocator: mem.Allocator = context.allocator) -> (res: string, ok: bool)SourceSerialize the timestamp as a RFC 3339 string.
The boolean ok is false if the time is not a valid datetime, or if allocating the result string fails.
Inputs:
utc_offset: offset in minutes wrt UTC (ie. the timezone)include_nanos: whether to include nanoseconds in the result.
time_to_string_hms
time_to_string_hms :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a 24-hour hh:mm:ss string.
Does not allocate
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by buf
Example:
buf: [MIN_HMS_LEN]u8
now := time.now()
fmt.println(time.to_string_hms(now, buf[:]))time_to_unix
time_to_unix :: proc(t: Time) -> (i64)SourceObtain the Unix timestamp in seconds from a Time.
time_to_unix_nano
time_to_unix_nano :: proc(t: Time) -> (i64)SourceObtain the Unix timestamp in nanoseconds from a Time.
to_string_dd_mm_yy
to_string_dd_mm_yy :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a dd-mm-yy date string.
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by
buf.
Example:
buf: [MIN_YY_DATE_LEN]u8
now := time.now()
fmt.println(time.to_string_dd_mm_yy(now, buf[:]))to_string_dd_mm_yyyy
to_string_dd_mm_yyyy :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a dd-mm-yyyy date string.
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by
buf.
Example:
buf: [MIN_YYYY_DATE_LEN]u8
now := time.now()
fmt.println(time.to_string_dd_mm_yyyy(now, buf[:]))to_string_hms_12
to_string_hms_12 :: proc(t: Time, buf: []u8, ampm: [2]string) -> (res: string)SourceFormats a Time as a 12-hour hh:mm:ss pm string
Does not allocate
Inputs:
- t: The Time to format
- buf: The backing buffer to use
- ampm: An optional pair of am/pm strings to use in place of the default
Returns:
- res: The formatted string, backed by buf
Example:
buf: [64]u8
now := time.now()
fmt.println(time.to_string_hms_12(now, buf[:]))
fmt.println(time.to_string_hms_12(now, buf[:], {"ã", "ã"}))to_string_mm_dd_yy
to_string_mm_dd_yy :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a mm-dd-yy date string.
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by
buf.
Example:
buf: [MIN_YY_DATE_LEN]u8
now := time.now()
fmt.println(time.to_string_mm_dd_yy(now, buf[:]))to_string_mm_dd_yyyy
to_string_mm_dd_yyyy :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a mm-dd-yyyy date string.
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by
buf.
Example:
buf: [MIN_YYYY_DATE_LEN]u8
now := time.now()
fmt.println(time.to_string_mm_dd_yyyy(now, buf[:]))to_string_yy_mm_dd
to_string_yy_mm_dd :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a yy-mm-dd date string.
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by
buf.
Example:
buf: [MIN_YY_DATE_LEN]u8
now := time.now()
fmt.println(time.to_string_yy_mm_dd(now, buf[:]))to_string_yyyy_mm_dd
to_string_yyyy_mm_dd :: proc(t: Time, buf: []u8) -> (res: string)SourceFormats a Time as a yyyy-mm-dd date string.
Inputs:
- t: The Time to format.
- buf: The backing buffer to use.
Returns:
- res: The formatted string, backed by
buf.
Example:
buf: [MIN_YYYY_DATE_LEN]u8
now := time.now()
fmt.println(time.to_string_yyyy_mm_dd(now, buf[:]))to_unix_nanoseconds
to_unix_nanoseconds :: proc(t: Time) -> (i64)SourceAlias for time_to_unix_nano.
to_unix_seconds
to_unix_seconds :: proc(t: Time) -> (i64)SourceAlias for time_to_unix.
tsc_frequency
tsc_frequency :: proc(fallback_sleep = 2 * Second) -> (bool, u64)SourceObtain the CPU's TSC frequency, in hertz.
This procedure tries to obtain the CPU's TSC frequency in hertz. If the CPU doesn't have an invariant TSC, this procedure returns with an error. Otherwise an attempt is made to fetch the TSC frequency from the OS. If this fails, the frequency is obtained by sleeping for the specified amount of time and dividing the readings from TSC by the duration of the sleep.
The duration of sleep can be controlled by fallback_sleep parameter.
unix
unix :: proc(sec: i64, nsec: i64) -> (Time)SourceObtain time from unix seconds and unix nanoseconds.
weekday
weekday :: proc(t: Time) -> (weekday: Weekday)SourceObtain the week day of the date specified by time.
year
year :: proc(t: Time) -> (year: int)SourceObtain the year of the date specified by time.
Procedure Groups
4clock
clock :: proc{clock_from_time, clock_from_duration, clock_from_stopwatch}SourceObtain the time components from a time, a duration or a stopwatch's total.
datetime_to_time
datetime_to_time :: proc{components_to_time, compound_to_time}SourceConvert datetime components into time.
precise_clock
precise_clock :: proc{precise_clock_from_time, precise_clock_from_duration, precise_clock_from_stopwatch}SourceObtain the time components from a time, a duration or a stopwatch's total, including nanoseconds.
to_string_hms
to_string_hms :: proc{time_to_string_hms, duration_to_string_hms}Source