Last active
August 13, 2016 04:55
-
-
Save ItGumby/436b1b8dc25706579e42edbc8e57594b to your computer and use it in GitHub Desktop.
Scanning odd timezones via java.time.* (Java8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inspired by https://kousenit.org/2016/07/16/fun-with-time-zones-in-java-8/ | |
import java.time.* | |
import java.time.format.* | |
final boolean shouldIncludeHourOffsets = false | |
LocalDateTime now = LocalDateTime.now() | |
List<ZonedDateTime> zdts = ZoneId.availableZoneIds | |
.collect { now.atZone(ZoneId.of(it)) } | |
.findAll { shouldIncludeHourOffsets || it.offset.totalSeconds % (60*60) != 0 } | |
.sort { it.offset.totalSeconds } | |
ZonedDateTime current = now.atZone(ZoneId.systemDefault()) | |
println "current time = ${current}" | |
printf "%10s %20s %13s%n", 'Offset', 'ZoneId', 'Time' | |
final dtfFormat = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) | |
zdts.each { | |
ZonedDateTime zdt = current.withZoneSameInstant(it.zone) | |
printf "%10s %25s %10s%n", zdt.offset, it.zone, zdt.format(dtfFormat) | |
} | |
println "#zones:\t${zdts.size()}" // 26 if filtered; else 589 | |
// includes 5 zones off by 15/45 minutes; other 21 are 30 min offsets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment