dateparser icon indicating copy to clipboard operation
dateparser copied to clipboard

Strange timezone offsets

Open Anton-Astrouski opened this issue 5 years ago • 4 comments

Hi,

public static void main(String[] args) { final DateParser dp = DateParser.newBuilder().build(); final String date = "2020-06-08T13:45:05-00:00"; System.out.println(dp.parseDate(date).toString()); System.out.println(dp.parseDateTime(date).toString()); System.out.println(dp.parseOffsetDateTime(date).toString()); }

The code above gives me the results:

Mon Jun 08 14:45:05 CEST 2020 2020-06-08T14:45:05 2020-06-08T13:45:05Z

My local time was 13:45:05 I'm using GMT+2. I expected to get something like 15:45:05 (13:45:05 + 2 hours) Am I doing something wrong?

Version 1.0.2-1.0.4

Version 1.0.0-1.0.1 Gives me the following:

Mon Jun 08 15:45:05 CEST 2020 2020-06-08T15:45:05 2020-06-08T13:45:05Z

Anton-Astrouski avatar Jul 24 '20 15:07 Anton-Astrouski

Could you append the below code into your main, and rerun it?

System.out.println(OffsetDateTime.now());

it could print the JVM's ZoneOffset, like this: 2020-07-28T17:16:43.257+08:00.

sisyphsu avatar Jul 28 '20 09:07 sisyphsu

2020-08-04T09:14:42.263+02:00

Anton-Astrouski avatar Aug 04 '20 07:08 Anton-Astrouski

I have a similar problem when parsed time with time zone offset is shown with 1h difference between parsed time and expected time. The difference seems to be related toDST. For example the date "2015-02-18 00:12:00 +0000 GMT" is parsed as 17 Feb 2015 23:12:00 GMT but it is expected to be 18 Feb 2015 00:12:00 GMT

I think the problem is in local time zone. Actually my time zone is in Daylight saving time (DST). Normally my local time zone is -05:00 (standard time), but in summer we have 1h shift for DST(Daylight saving time). So during summer my local time zone is -04:00. The problem is that when date with time zone is parsed, my local time zone is applied in dateTime.toEpochSecond(DEFAULT_OFFSET); when parsed result is converted to Date object (in DateBuilder.java) I think when time zone is present in parsed date, then default_offset has to be used without local DST.

If I disable DST in my system, then the parsed result has expected value.

andriy-samson avatar May 08 '21 01:05 andriy-samson

I have a similar problem when parsed time with time zone offset is shown with 1h difference between parsed time and expected time. The difference seems to be related toDST. For example the date "2015-02-18 00:12:00 +0000 GMT" is parsed as 17 Feb 2015 23:12:00 GMT but it is expected to be 18 Feb 2015 00:12:00 GMT

I think the problem is in local time zone. Actually my time zone is in Daylight saving time (DST). Normally my local time zone is -05:00 (standard time), but in summer we have 1h shift for DST(Daylight saving time). So during summer my local time zone is -04:00. The problem is that when date with time zone is parsed, my local time zone is applied in dateTime.toEpochSecond(DEFAULT_OFFSET); when parsed result is converted to Date object (in DateBuilder.java) I think when time zone is present in parsed date, then default_offset has to be used without local DST.

If I disable DST in my system, then the parsed result has expected value.

Thanks for your explanation and the PR.

I have merged your PullRequest#22 and deploy an new version 1.0.8, i think it could work correctly with DST timezone.

sisyphsu avatar Nov 27 '21 11:11 sisyphsu