Skip to content

Instantly share code, notes, and snippets.

@blouerat
Created August 8, 2022 15:07
Show Gist options
  • Save blouerat/a77602ebb398398e541ade0f3a823934 to your computer and use it in GitHub Desktop.
Save blouerat/a77602ebb398398e541ade0f3a823934 to your computer and use it in GitHub Desktop.
The "Etc/GMT+3" time zone ID actually refers to "-03:00", as demonstrated here
import java.time.ZoneId
import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.TemporalQueries
def parseZoneId(input: String): ZoneId =
new DateTimeFormatterBuilder()
.appendZoneId
.toFormatter
.parse(input)
.query(TemporalQueries.zoneId)
val plus3 = parseZoneId("+03:00")
// val plus3: java.time.ZoneId = +03:00
plus3.normalized
// val res0: java.time.ZoneId = +03:00
val gmtPlus3 = parseZoneId("GMT+03:00")
// val gmtPlus3: java.time.ZoneId = GMT+03:00
gmtPlus3.normalized
// val res1: java.time.ZoneId = +03:00
val etcGmtPlus3 = parseZoneId("Etc/GMT+3")
// val etcGmtPlus3: java.time.ZoneId = Etc/GMT+3
etcGmtPlus3.normalized
// val res2: java.time.ZoneId = -03:00
/*
"In order to conform with the POSIX style,
those zone names beginning with "Etc/GMT" have their sign reversed from the standard ISO 8601 convention."
https://en.wikipedia.org/wiki/Tz_database#Area
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment