Last active
September 5, 2019 22:28
-
-
Save buildlackey/1ce4228f8223bab321da2e8a3316c18b to your computer and use it in GitHub Desktop.
badtimesInPst
This file contains hidden or 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
import java.util.TimeZone | |
def updateTimeZone(zone: String) = { | |
System.setProperty("user.timezone", zone); | |
TimeZone.setDefault(TimeZone.getTimeZone(zone)) | |
} | |
// Set timezone to Pacific Standard, where -- at least for now -- | |
// daylight savings is in effect | |
updateTimeZone("PST") | |
java.sql.Timestamp.valueOf("2019-03-10 01:00:00") | |
// should result in: java.sql.Timestamp = 2019-03-10 01:00:00.0 | |
java.sql.Timestamp.valueOf("2019-03-09 02:00:00") // 2 AM | |
// should result in: java.sql.Timestamp = 2019-03-09 02:00:00.0 | |
java.sql.Timestamp.valueOf("2019-03-10 02:00:00") | |
// should result in: java.sql.Timestamp = 2019-03-10 03:00:00.0 - 3 AM, not 2 AM as per input ! | |
// Let's now move to Japan time, where day light savings rules are not followed | |
updateTimeZone("Asia/Tokyo") | |
java.sql.Timestamp.valueOf("2019-03-10 01:00:00") | |
// should result in: java.sql.Timestamp = 2019-03-10 01:00:00.0 | |
java.sql.Timestamp.valueOf("2019-03-09 02:00:00") // 2 AM | |
// should result in: java.sql.Timestamp = 2019-03-09 02:00:00.0 | |
java.sql.Timestamp.valueOf("2019-03-10 02:00:00") | |
// should result in: java.sql.Timestamp = 2019-03-10 03:00:00.0 - Doesn't skip 1 hour to 3 AM ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment