-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1589698: Fix roundtripping of timezone offsets in dates #392
Conversation
e4bc903
to
e92f1e8
Compare
Codecov Report
@@ Coverage Diff @@
## master #392 +/- ##
============================================
+ Coverage 71.57% 75.75% +4.17%
Complexity 308 308
============================================
Files 72 95 +23
Lines 4078 5320 +1242
Branches 629 629
============================================
+ Hits 2919 4030 +1111
- Misses 696 827 +131
Partials 463 463
Continue to review full report at Codecov.
|
// the timezone specified in the Calendar.getInstance constructor. Here, we parse | ||
// the offset suffix of the string to get a TimeZone object and apply that to the | ||
// Calendar instance being created. | ||
val offset = "GMT" + correctedDate.substring(correctedDate.length - 5, correctedDate.length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, but I also hate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that for datetimes in GMT the string ends in "+0000"? Should be easy to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran this test:
@Test
fun `test that timestamps in GMT are read correctly`() {
TimeZone.setDefault(TimeZone.getTimeZone("GMT"))
val cal = Calendar.getInstance()
cal.set(Calendar.YEAR, 2019)
cal.set(Calendar.MONTH, 8) // September
cal.set(Calendar.DAY_OF_MONTH, 13)
assertEquals("2019-09-13+00:00", getISOTimeString(cal, GleanTimeUnit.Day))
}
All green. Testing in Fenix next.
This is a possible fix to 1589698. I say "possible" because I didn't manage to make a Fenix release with this fix to confirm.
However, I do think there's a real bug here regardless...
The Calendar object returned from
parseISOTimeStringAsCalendar
was always returning the result in UTC, which is the right thing wrt not having DST affect things, but doesn't preserve the original timezone of the input. It seems that while SimpleDateFormat.parse does handle the offset correctly, it converts it to the desired timezone, rather than setting it as the timezone. Seems the workaround is to parse the end as a timezone first, use that as the desired timezone, and then parse everything into that.