About
Date and time in the Mys programming language.
Example
Just print dates and times.
from time.system import now as system_now
from time.steady import now as steady_now
from time import LocalDateTime
from time import UtcDateTime
func main():
print("system_now(): ", system_now())
print("steady_now(): ", steady_now())
print("LocalDateTime(): ", LocalDateTime())
print("UtcDateTime(): ", UtcDateTime())
Build and run.
❯ mys run
✔ Reading package configuration (0 seconds)
✔ Building (0.22 seconds)
system_now(): Time(seconds=1617085725, nanoseconds=591346000)
steady_now(): Time(seconds=2147009, nanoseconds=643340000)
LocalDateTime(): 2021-03-30 08:28:45
UtcDateTime(): 2021-03-30 06:28:45 UTC
API
Time
class TimeError(Error):
message: string
class Time:
Time in seconds and nanoseconds.
seconds: i64
nanoseconds: i32
func !=(self, other: Time) -> bool:
func >(self, other: Time) -> bool:
func >=(self, other: Time) -> bool:
func <=(self, other: Time) -> bool:
func +=(self, other: Time):
func -=(self, other: Time):
func +(self, seconds: i64) -> Time:
func -(self, seconds: i64) -> Time:
class LocalDateTime:
Date and time in the local time zone.
year: i32
month: u8
day: u8
hour: u8
minute: u8
second: u8
is_daylight_saving_time: bool
func __init__(self, time_since_epoch: Time? = None):
Create a local date time object from given time since epoch. Uses
current system time if time_since_epoch is None.
func to_time_since_epoch(self) -> Time:
Return this date and time as time since epoch.
class UtcDateTime:
Date and time in UTC.
year: i32
month: u8
day: u8
hour: u8
minute: u8
second: u8
func __init__(self, time_since_epoch: Time? = None):
Create a UTC date time object from given time since epoch. Uses
current system time if time_since_epoch is None.
func to_time_since_epoch(self) -> Time:
Return this date and time as time since epoch.
System time
func now() -> Time:
Get the current time of system clock. This is commonly referred to
as Unix time.
This clock is affected by discontinuous jumps.
Steady time
func now() -> Time:
Get the current time of steady (monotonic) clock.
This clock is not affected by discontinuous jumps.