const (
nanosecond = Duration(1)
microsecond = Duration(1000 * nanosecond)
millisecond = Duration(1000 * microsecond)
second = Duration(1000 * millisecond)
minute = Duration(60 * second)
hour = Duration(60 * minute)
infinite = Duration(-1)
)
fn day_of_week(y int, m int, d int) int
day_of_week returns the current day of a given year, month, and day, as an integer.
fn days_in_month(month int, year int) ?int
days_in_month returns a number of days in a given month.
fn is_leap_year(year int) bool
is_leap_year checks if a given a year is a leap year.
fn new_stopwatch(opts StopWatchOptions) StopWatch
new_stopwatch initializes a new StopWatch with the current time as start.
fn new_time(t Time) Time
new_time returns a time struct with calculated Unix time.
fn now() Time
fn offset() int
offset returns time zone UTC offset in seconds.
fn parse(s string) ?Time
parse returns time from a date string in "YYYY-MM-DD HH:MM:SS" format.
fn parse_iso8601(s string) ?Time
parse_iso8601 parses rfc8601 time format yyyy-MM-ddTHH:mm:ss.dddddd+dd:dd as local time the fraction part is difference in milli seconds and the last part is offset from UTC time and can be both +/- HH:mm remarks: not all iso8601 is supported also checks and support for leapseconds should be added in future PR
fn parse_rfc2822(s string) ?Time
parse_rfc2822 returns time from a date string in RFC 2822 datetime format.
fn sleep(seconds int)
sleep makes the calling thread sleep for a given number of seconds.
fn sleep_ms(milliseconds int)
sleep_ms makes the calling thread sleep for a given number of milliseconds.
fn sys_mono_now() u64
fn ticks() i64
ticks returns a number of milliseconds elapsed since system start.
fn unix(abs int) Time
unix returns a time struct from Unix time.
fn unix2(abs int, microsecond int) Time
unix2 returns a time struct from Unix time and microsecond value
fn usleep(microseconds int)
usleep makes the calling thread sleep for a given number of microseconds.
fn utc() Time
utc returns the current UTC time.
fn win_now() Time
dummy to compile with all compilers
fn win_utc() Time
dummy to compile with all compilers
fn zero_timespec() C.timespec
return timespec of 1970/1/1
type Duration = i64
A lot of these are taken from the Go library.
fn (d Duration) hours() f64
hours returns the duration as a floating point number of hours.
fn (d Duration) microseconds() i64
microseconds returns the duration as an integer number of microseconds.
fn (d Duration) milliseconds() i64
milliseconds returns the duration as an integer number of milliseconds.
fn (d Duration) minutes() f64
minutes returns the duration as a floating point number of minutes.
fn (d Duration) nanoseconds() i64
nanoseconds returns the duration as an integer number of nanoseconds.
fn (d Duration) seconds() f64
The following functions return floating point numbers because it's common to consider all of them in sub-one intervals seconds returns the duration as a floating point number of seconds.
fn (d Duration) timespec() C.timespec
return absolute timespec for now()+d
enum FormatDate {
ddmmyy
ddmmyyyy
mmddyy
mmddyyyy
mmmd
mmmdd
mmmddyyyy
no_date
yyyymmdd
}
FormatDelimiter contains different date formats.
enum FormatDelimiter {
dot
hyphen
slash
space
no_delimiter
}
FormatDelimiter contains different time/date delimiters.
enum FormatTime {
hhmm12
hhmm24
hhmmss12
hhmmss24
hhmmss24_milli
hhmmss24_micro
no_time
}
FormatDelimiter contains different time formats.
struct C.timeval {
tv_sec u64
tv_usec u64
}
C.timeval represents a C time value.
struct StopWatch {
mut:
elapsed u64
pub mut:
start u64
end u64
}
StopWatch is used to measure elapsed time.
fn (mut t StopWatch) start()
start starts the stopwatch. If the timer was paused, restarts counting.
fn (mut t StopWatch) restart()
restart restarts the stopwatch. If the timer was paused, restarts counting.
fn (mut t StopWatch) stop()
stop stops the timer, by setting the end time to the current time.
fn (mut t StopWatch) pause()
pause resets the start
time and adds the current elapsed time to elapsed
.
fn (t StopWatch) elapsed() Duration
elapsed returns the Duration since the last start call
struct StopWatchOptions {
auto_start bool = true
}
struct Time {
pub:
year int
month int
day int
hour int
minute int
second int
microsecond int
unix u64
}
Time contains various time units for a point in time.
fn (t1 Time) != (t2 Time) bool
operator !=
returns true if provided time is not equal to time
fn (lhs Time) - (rhs Time) Duration
Time subtract using operator overloading.
fn (t1 Time) < (t2 Time) bool
operator <
returns true if provided time is less than time
fn (t1 Time) <= (t2 Time) bool
operator <=
returns true if provided time is less or equal to time
fn (t1 Time) == (t2 Time) bool
operator ==
returns true if provided time is equal to time
fn (t1 Time) > (t2 Time) bool
operator >
returns true if provided time is greater than time
fn (t1 Time) >= (t2 Time) bool
operator >=
returns true if provided time is greater or equal to time
fn (t Time) add(d Duration) Time
add returns a new time that duration is added
fn (t Time) add_days(days int) Time
add_days returns a new time struct with an added number of days.
fn (t Time) add_seconds(seconds int) Time
add_seconds returns a new time struct with an added number of seconds.
fn (t Time) clean() string
clean returns a date string in a following format: - a date string in "HH:MM" format (24h) for current day - a date string in "MMM D HH:MM" format (24h) for date of current year - a date string formatted with format function for other dates
fn (t Time) clean12() string
clean12 returns a date string in a following format: - a date string in "HH:MM" format (12h) for current day - a date string in "MMM D HH:MM" format (12h) for date of current year - a date string formatted with format function for other dates
fn (t Time) day_of_week() int
day_of_week returns the current day as an integer.
fn (t Time) ddmmy() string
ddmmy returns a date string in "DD.MM.YYYY" format.
fn (t Time) format() string
format returns a date string in "YYYY-MM-DD HH:MM" format (24h).
fn (t Time) format_ss() string
format_ss returns a date string in "YYYY-MM-DD HH:MM:SS" format (24h).
fn (t Time) format_ss_micro() string
format_ss_micro returns a date string in "YYYY-MM-DD HH:MM:SS.123456" format (24h).
fn (t Time) format_ss_milli() string
format_ss_milli returns a date string in "YYYY-MM-DD HH:MM:SS.123" format (24h).
fn (t Time) get_fmt_date_str(fmt_dlmtr FormatDelimiter, fmt_date FormatDate) string
get_fmt_time_str returns a date string with specified FormatDelimiter and FormatDate type.
fn (t Time) get_fmt_str(fmt_dlmtr FormatDelimiter, fmt_time FormatTime, fmt_date FormatDate) string
get_fmt_str returns a date string with specified FormatDelimiter, FormatTime type, and FormatDate type.
fn (t Time) get_fmt_time_str(fmt_time FormatTime) string
get_fmt_time_str returns a date string with specified FormatTime type.
fn (t Time) hhmm() string
hhmm returns a date string in "HH:MM" format (24h).
fn (t Time) hhmm12() string
hhmm12 returns a date string in "HH:MM" format (12h).
fn (t Time) hhmmss() string
hhmmss returns a date string in "HH:MM:SS" format (24h).
fn (t Time) local() Time
local returns t with the location set to local time.
fn (t Time) long_weekday_str() string
weekday_str returns the current day as a string.
fn (t Time) md() string
md returns a date string in "MMM D" format.
fn (t Time) relative() string
relative returns a string representation of the difference between t and the current time.
fn (t Time) relative_short() string
relative_short returns a string saying how long ago a time occured as follows: 0-30 seconds: "now"
; 30-60 seconds: "1m"
; anything else is rounded to the nearest minute, hour or day; anything higher than 10000 days (about 27 years) years returns an empty string. Some Examples: 0s -> 'now'
; 20s -> 'now'
; 47s -> '1m'
; 456s -> '7m'
; 1234s -> '20m'
; 16834s -> '4h'
; 1687440s -> '33d'
; 15842354871s -> ''
fn (t Time) smonth() string
smonth returns month name.
fn (t Time) str() string
str returns time in the same format as parse
expects ("YYYY-MM-DD HH:MM:SS").
fn (t Time) unix_time() int
unix_time returns Unix time.
fn (t Time) unix_time_milli() u64
unix_time_milli returns Unix time with millisecond resolution.
fn (t Time) utc_string() string
This is just a TEMPORARY function for cookies and their expire dates
fn (t Time) weekday_str() string
weekday_str returns the current day as a string.
fn (t Time) ymmdd() string
ymmdd returns a date string in "YYYY-MM-DD" format.