https://kotlinlang.org logo
#codereview
Title
# codereview
g

Georgi Naumov

01/29/2020, 8:38 AM
I am stuck with Date assertion in different timezones. May someone give me a hint? https://gist.github.com/gonaumov/cc60cc8fafc74da937f8291a6efeda70
I tried to calculate the offset and managed to do it but I didn't find working solutions to detect daylight saving time switching.
k

kqr

01/29/2020, 8:45 AM
hi, honestly I am not sure what you are trying to do, but I would try to convert dates to timestamps and compare them. not sure what is your source of data, because
2019-08-23 15:50:00
is not exact timestamp without timezone, so if you change timezone you change timestamp
👍 1
g

Georgi Naumov

01/29/2020, 10:29 AM
This was my trying to fix it. Sorry for gists but I don't have Slack on the PC: https://gist.github.com/gonaumov/6c9816cc251c2fec73234b585e2986b8 Probably the question is a but stupid but how to add a time zone to the string in way parser to understand it?
k

kqr

01/29/2020, 12:08 PM
where does never.created come from? whats in it? that datetime in string should be in which time zone? how did you created formatter? did you set timezone to formatter?
👍 1
Copy code
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" 	2001-07-04T12:08:56.235-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" 	2001-07-04T12:08:56.235-07:00
👍 1
c

corneil

01/29/2020, 1:59 PM
Or use
"yyyy-MM-dd'T'HH:mm:ssZ"
as the formatter and append
Z
to the time that has no timezone then the result will be a UTC time.
👍 1
m

myanmarking

01/29/2020, 4:18 PM
just convert both dates to the same timezone and compare them?
👍 1
idk what is the problem
👍 1
g

Georgi Naumov

01/29/2020, 4:20 PM
Would you give me an example? :)
m

myanmarking

01/29/2020, 4:21 PM
give me a test that will fail and should pass. maybe that's better to understand the point
98 Views