Skip to content
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

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

mdboom
Copy link
Contributor

@mdboom mdboom commented Oct 20, 2019

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.

@mdboom mdboom force-pushed the datetime-round-trip branch from e4bc903 to e92f1e8 Compare October 20, 2019 22:43
@codecov-io
Copy link

codecov-io commented Oct 20, 2019

Codecov Report

Merging #392 into master will increase coverage by 4.17%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...in/java/mozilla/telemetry/glean/utils/DateUtils.kt 77.27% <100%> (+1.08%) 0 <0> (ø) ⬇️
...etry/glean/private/MemoryDistributionMetricType.kt 92.68% <0%> (-0.35%) 11% <0%> (ø)
glean-core/ios/Glean/Utils/Unreachable.swift 0% <0%> (ø) 0% <0%> (?)
...e/ios/Glean/Scheduler/GleanLifecycleObserver.swift 58.33% <0%> (ø) 0% <0%> (?)
glean-core/ios/Glean/Metrics/StringMetric.swift 97.5% <0%> (ø) 0% <0%> (?)
glean-core/ios/Glean/Glean.swift 92.4% <0%> (ø) 0% <0%> (?)
glean-core/ios/Glean/Metrics/Ping.swift 90.9% <0%> (ø) 0% <0%> (?)
glean-core/ios/Glean/Config/Configuration.swift 100% <0%> (ø) 0% <0%> (?)
glean-core/ios/Glean/Dispatchers.swift 98.75% <0%> (ø) 0% <0%> (?)
...e/ios/Glean/Metrics/TimingDistributionMetric.swift 98.57% <0%> (ø) 0% <0%> (?)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c471c3...e92f1e8. Read the comment docs.

// 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)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

@badboy badboy merged commit cf7a1ea into mozilla:master Oct 21, 2019
@mdboom mdboom deleted the datetime-round-trip branch April 2, 2020 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants