sisyphsu / dateparser

dateparser is a smart and high-performance date parser library, it supports hundreds of different formats, nearly all format that we may used. And this is also a showcase for "retree" algorithm.
MIT License
95 stars 24 forks source link

Strange timezone offsets #8

Open Anton-Astrouski opened 4 years ago

Anton-Astrouski commented 4 years ago

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

sisyphsu commented 4 years ago

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.

Anton-Astrouski commented 4 years ago

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

andriy-samson commented 3 years ago

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.

sisyphsu commented 2 years ago

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.