Date manipulation: Difference between revisions

Content deleted Content added
Rob-codes (talk | contribs)
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">val .input = "March 7 2009 7:30pm -05:00"
<syntaxhighlight lang="langur">
val .iformat = "January 2 2006 3:04pm -07:00"
val input = "March 7 2009 7:30pm -05:00"
val .oformat = "January 2 2006 3:04pm MST"
val iformat = "January 2 2006 3:04pm -07:00"
val oformat = "January 2 2006 3:04pm MST"


val .d1 = datetime .input, .iformat
val d1 = datetime(input, iformat)
val .d2 = .d1 + dr/PT12H/
val d2 = d1 + dr/T12h/
val .d3 = datetime .d2, "US/Arizona"
val d3 = datetime(d2, "US/Arizona")
val .d4 = datetime .d2, zls
val d4 = datetime(d2, zls)
val .d5 = datetime .d2, "Z"
val d5 = datetime(d2, "Z")
val .d6 = datetime .d2, "+02:30"
val d6 = datetime(d2, "+02:30")
val .d7 = datetime .d2, "EST"
val d7 = datetime(d2, "EST")


writeln "input string: ", .input
writeln "input string: ", input
writeln "input format string: ", .iformat
writeln "input format string: ", iformat
writeln "output format string: ", .oformat
writeln "output format string: ", oformat
writeln()
writeln()


writeln $"original: \.d1; (\.d1:dt oformat;)"
writeln "original: {{d1}} ({{d1:dt oformat}})"
writeln $"+12 hours: \.d2; (\.d2:dt oformat;)"
writeln "+12 hours: {{d2}} ({{d2:dt oformat}})"
writeln $"in Arizona: \.d3; (\.d3:dt oformat;)"
writeln "in Arizona: {{d3}} ({{d3:dt oformat}})"
writeln $"in local time zone: \.d4; (\.d4:dt oformat;)"
writeln "in local time zone: {{d4}} ({{d4:dt oformat}})"
writeln $"in UTC: \.d5; (\.d5:dt oformat;)"
writeln "in UTC: {{d5}} ({{d5:dt oformat}})"
writeln $"+02:30 time zone: \.d6; (\.d6:dt oformat;)"
writeln "+02:30 time zone: {{d6}} ({{d6:dt oformat}})"
writeln $"in EST: \.d7; (\.d7:dt oformat;)"</syntaxhighlight>
writeln "in EST: {{d7}} ({{d7:dt oformat}})"
</syntaxhighlight>


{{out}}
{{out}}