question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong klock DateTime conversion.

See original GitHub issue

Overview (Required)

Several klock DateTime conversion code seems wrong…

Superficial problem.

The time when “Go to survey” is displayed is shifted.

  1. Set Android device time like as 2019 Feb. 7, 21:00 (GMT+9:00 (Japan Standard Time))
  2. 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).

screenshot

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
jmatsucommented, Jan 10, 2019

~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

2reactions
nukka123commented, Jan 10, 2019

let me add the timezone information to the api.

nice! But, be careful. If api fix first, dateFormat.parse(startsAt) will be throws Exception. We need tempolary workaround like as

            stime = try {
                stime = dateFormat.parse(startsAt).utc.unixMillisLong
            } catch (e: Exception) {
                DateFormat.FORMAT1.parse(startsAt).utc.unixMillisLong
            }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect Hour Displayed · Issue #65 · korlibs-archive/klock
After formatting a DateTime instance, and printing it out the hour is incorrect (exactly one hour behind): Current Timestamp: ...
Read more >
Re: st: wrong datetime results with clock() -- sometimes - Stata
Re: st: wrong datetime results with clock() -- sometimes ... I am trying to convert a variable with datetime observations currently ...
Read more >
clock returns inaccurate results - Statalist
Hi, I want to convert some string variable to datetime format using the clock() function (Stata 14.2 MP). Here is the code I...
Read more >
Date to timestring conversion one hour wrong - java
oke, found it! Android converses a Date to the timezone of the device. I had to overrule that: This works: public String dateToString(Date ......
Read more >
Getting a correct - time from another timezone | Uniface User
As I want to convert a timestamp to the correct "Zulu" time with global ... v_DATIM_TZ1 ELSE ;convert datetime from TZ1 first from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found