Date manipulation: Difference between revisions

(improved variable names, added comments, added second example)
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.
 
<syntaxhighlight lang="langur">val .input = "March 7 2009 7:30pm -05:00"
val .iformatinput = "JanuaryMarch 27 20062009 37:04pm30pm -0705:00"
val .oformatiformat = "January 2 2006 3:04pm MST-07:00"
val oformat = "January 2 2006 3:04pm MST"
 
val .d1 = datetime .(input, .iformat)
val .d2 = .d1 + dr/PT12HT12h/
val .d3 = datetime .(d2, "US/Arizona")
val .d4 = datetime .(d2, zls)
val .d5 = datetime .(d2, "Z")
val .d6 = datetime .(d2, "+02:30")
val .d7 = datetime .(d2, "EST")
 
writeln "input string: ", .input
writeln "input format string: ", .iformat
writeln "output format string: ", .oformat
writeln()
 
writeln $"original: \.{{d1;}} (\.{{d1:dt oformat;}})"
writeln $"+12 hours: \.{{d2;}} (\.{{d2:dt oformat;}})"
writeln $"in Arizona: \.{{d3;}} (\.{{d3:dt oformat;}})"
writeln $"in local time zone: \.{{d4;}} (\.{{d4:dt oformat;}})"
writeln $"in UTC: \.{{d5;}} (\.{{d5:dt oformat;}})"
writeln $"+02:30 time zone: \.{{d6;}} (\.{{d6:dt oformat;}})"
writeln $"in EST: \.{{d7;}} (\.{{d7:dt oformat;}})"</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
1,007

edits