Date manipulation: Difference between revisions
Content deleted Content added
improved variable names, added comments, added second example |
Langurmonkey (talk | contribs) |
||
Line 1,904: | Line 1,904: | ||
Langur currently uses the Go time package. Testing with Go 1.14.1 on Linux, the time package doesn't seem to parse "EST" correctly, and it seems to fail silently. Given these conditions, I use "-05:00" instead of "EST" in the input string. |
Langur currently uses the Go time package. Testing with Go 1.14.1 on Linux, the time package doesn't seem to parse "EST" correctly, and it seems to fail silently. Given these conditions, I use "-05:00" instead of "EST" in the input string. |
||
<syntaxhighlight lang="langur"> |
<syntaxhighlight lang="langur"> |
||
val |
val input = "March 7 2009 7:30pm -05:00" |
||
val |
val iformat = "January 2 2006 3:04pm -07:00" |
||
val oformat = "January 2 2006 3:04pm MST" |
|||
val |
val d1 = datetime(input, iformat) |
||
val |
val d2 = d1 + dr/T12h/ |
||
val |
val d3 = datetime(d2, "US/Arizona") |
||
val |
val d4 = datetime(d2, zls) |
||
val |
val d5 = datetime(d2, "Z") |
||
val |
val d6 = datetime(d2, "+02:30") |
||
val |
val d7 = datetime(d2, "EST") |
||
writeln "input string: ", |
writeln "input string: ", input |
||
writeln "input format string: ", |
writeln "input format string: ", iformat |
||
writeln "output format string: ", |
writeln "output format string: ", oformat |
||
writeln() |
writeln() |
||
writeln |
writeln "original: {{d1}} ({{d1:dt oformat}})" |
||
writeln |
writeln "+12 hours: {{d2}} ({{d2:dt oformat}})" |
||
writeln |
writeln "in Arizona: {{d3}} ({{d3:dt oformat}})" |
||
writeln |
writeln "in local time zone: {{d4}} ({{d4:dt oformat}})" |
||
writeln |
writeln "in UTC: {{d5}} ({{d5:dt oformat}})" |
||
writeln |
writeln "+02:30 time zone: {{d6}} ({{d6:dt oformat}})" |
||
writeln |
writeln "in EST: {{d7}} ({{d7:dt oformat}})" |
||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |