2021-08-18 11:33:37 +03:00
|
|
|
module time
|
|
|
|
|
2023-07-22 21:30:36 +03:00
|
|
|
// parse returns the time from a date string.
|
2021-08-18 11:33:37 +03:00
|
|
|
//
|
|
|
|
// TODO(playX): JS Date expects iso8061 format of strings and other formats
|
2022-12-02 13:51:00 +03:00
|
|
|
// are implementation dependent, we probably want to implement parsing in JS.
|
2021-08-18 11:33:37 +03:00
|
|
|
pub fn parse(s string) Time {
|
|
|
|
mut res := Time{}
|
|
|
|
#let date = new Date(s.str)
|
|
|
|
#res.year.val = date.getFullYear()
|
|
|
|
#res.month.val = date.getMonth()
|
|
|
|
#res.day.val = date.getDay()
|
|
|
|
#res.hour.val = date.getHours()
|
|
|
|
#res.minute.val = date.getMinutes()
|
|
|
|
#res.second.val = date.getSeconds()
|
|
|
|
#res.microsecond.val = date.getMilliseconds() * 1000
|
|
|
|
#res.unix.val = (date.getTime() / 1000).toFixed(0)
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2022-10-26 11:26:28 +03:00
|
|
|
pub fn parse_iso8601(s string) !Time {
|
2021-08-18 11:33:37 +03:00
|
|
|
return parse(s)
|
|
|
|
}
|