Wrong klock DateTime conversion.
See original GitHub issueOverview (Required)
Several klock DateTime
conversion code seems wrong…
Superficial problem.
The time when “Go to survey” is displayed is shifted.
- Set Android device time like as 2019 Feb. 7, 21:00 (GMT+9:00 (Japan Standard Time))
- launch droidkaigi app.
we expected following behavior. All Day1 Session is finished. (“Go to survey” is displayed).
but actual result is as follows. The session since lunch has not finished yet. (“Go to survey” is NOT displayed).
Code problem.
SessionDataMapperExt.kt
stime = dateFormat.parse(startsAt).utc.unixMillisLong,
etime = dateFormat.parse(endsAt).utc.unixMillisLong,
When endsAt
is “2019-02-07T11:50:00”, etime
indicate 2019 Feb 07 11:50:00 (GMT+0:00).
But, the true meaning of “2019-02-07T11:50:00” in droidkaigi api response is 2019 Feb 07 11:50:00 (GMT+9:00).
Session.kt
val isFinished: Boolean
get() = DateTime.nowUnixLong() > endTime.unixMillisLong
When endsAt
is “2019-02-07T11:50:00”, endTime
indicate 2019 Feb 07 11:50:00 (GMT+0:00).
This time same as 2019 Feb 07 20:50:00 (GMT+9:00 (Japan Standard Time)).
append(startTime.format("hh:mm"))
append(" - ")
append(endTime.format("hh:mm"))
And more, “hh” means 12-hour notation. (see Session Detail screen) If we expect 24-hour notation, specify “HH”.
Appendix: Basic test code.
val t1a: DateTimeTz =
DateFormat("""yyyy-MM-dd'T'HH:mm:ss""").parse("2019-02-07T11:50:00")
assertEquals(TimezoneOffset(0.0), t1a.offset)
assertEquals(11, t1a.hours)
assertEquals("11:50", t1a.format("HH:mm"))
assertEquals(1549540200000, t1a.utc.unixMillisLong)
val t1b: DateTime = t1a.utc
assertEquals(11, t1b.hours)
assertEquals("11:50", t1b.format("HH:mm"))
val t1c: DateTimeTz = t1b.toOffset(TimezoneOffset((9*60*60*1000).toDouble()))
assertEquals(TimezoneOffset((9*60*60*1000).toDouble()), t1c.offset)
assertEquals(20, t1c.hours)
assertEquals("08:50", t1c.format("hh:mm"))
assertEquals("20:50", t1c.format("HH:mm"))
assertEquals(t1a.utc.unixMillisLong, t1c.utc.unixMillisLong)
val t2a: DateTimeTz =
DateFormat("""yyyy-MM-dd'T'HH:mm:ssxxx""").parse("2019-02-07T11:50:00+09:00")
assertEquals(TimezoneOffset((9*60*60*1000).toDouble()), t2a.offset)
assertEquals(11, t2a.hours)
assertEquals("11:50", t2a.format("HH:mm"))
assertEquals(1549507800000, t2a.utc.unixMillisLong)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (11 by maintainers)
Top GitHub Comments
~I’ve added those TZ-aware fields to Session entities. Please check it out from https://droidkaigi2019-dev.appspot.com/api/timetable~
~Oops, sorry, was half asleep. I found a bug… let me address it.~
Fixed 🙇 I’ve added those TZ-aware fields to Session entities. Please check it out from https://droidkaigi2019-dev.appspot.com/api/timetable
nice! But, be careful. If api fix first,
dateFormat.parse(startsAt)
will be throws Exception. We need tempolary workaround like as