|
3 | 3 |
|
4 | 4 | %include inflator/time/src/get_time |
5 | 5 | %include inflator/time/src/get_timezone |
6 | | - |
7 | | -# datetime |
8 | | - |
9 | | -struct datetime { |
10 | | - year = 1970, |
11 | | - month = 1, |
12 | | - day = 1, |
13 | | - hour = 0, |
14 | | - minute = 0, |
15 | | - second = 0, |
16 | | - microsecond = 0, |
17 | | - tzh=0, # either timezone hour, or "null". If null, implies there is no timezone data attached. |
18 | | - tzm=0 # timezone minute. If tzh is null, ignore tzm, so default is "00" |
19 | | -} |
20 | | - |
21 | | -%define DATETIME_NOW() datetime{ \ |
22 | | - year: current_year(), \ |
23 | | - month: current_month(), \ |
24 | | - day: current_date(), \ |
25 | | - hour: current_hour(), \ |
26 | | - minute: current_minute(), \ |
27 | | - second: current_second(), \ |
28 | | - microsecond: floor(CURRENT_MILLISECOND() * 1000), \ |
29 | | - tzh: TIMEZONE(),\ |
30 | | - tzm: 0} |
31 | | - |
32 | | -func dt_str(datetime dt) { |
33 | | - local suffix = ""; |
34 | | - if $dt.microsecond != 0 { |
35 | | - # add microseconds if applicable |
36 | | - # according to the Wikipedia page: There is no limit on the number of decimal places for the decimal fraction |
37 | | - suffix &= "." & floor($dt.microsecond); |
38 | | - } |
39 | | - |
40 | | - if $dt.tzh != "null" { |
41 | | - # add optional timezone data |
42 | | - if $dt.tzh == 0 and $dt.tzm == 0 { |
43 | | - # if it's UTC, just add a Z |
44 | | - suffix &= "Z"; |
45 | | - } else { |
46 | | - if $dt.tzh[1] != "-" { |
47 | | - suffix &= "+"; |
48 | | - } |
49 | | - |
50 | | - suffix &= zfill($dt.tzh, 2) & ":" & zfill($dt.tzm, 2); |
51 | | - } |
52 | | - } |
53 | | - |
54 | | - return $dt.year & "-" & zfill($dt.month, 2) & "-" & zfill($dt.day, 2) & |
55 | | - "T" & zfill($dt.hour, 2) & ":" & zfill($dt.minute, 2) & ":" & zfill($dt.second, 2) & |
56 | | - suffix; |
57 | | -} |
0 commit comments