blob: 9d08e08aa5f7d130afd38abf97a21eda65c7e708 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
module time
pub fn now() Time {
mut res := Time{}
#let date = new Date()
#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
}
pub fn utc() Time {
mut res := Time{}
#let date = new Date()
#res.year.val = date.getUTCFullYear()
#res.month.val = date.getUTCMonth()
#res.day.val = date.getUTCDay()
#res.hour.val = date.getUTCHours()
#res.minute.val = date.getUTCMinutes()
#res.second.val = date.getUTCSeconds()
#res.microsecond.val = date.getUTCMilliseconds() * 1000
#res.unix.val = (date.getTime() / 1000).toFixed(0)
return res
}
/// Returns local time
pub fn (t Time) local() Time {
// TODO: Does this actually correct? JS clock is always set to timezone or no?
// if it is not we should try to use Intl for getting local time.
return t
}
|