Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange timezone offsets #8

Open
Anton-Astrouski opened this issue Jul 24, 2020 · 4 comments
Open

Strange timezone offsets #8

Anton-Astrouski opened this issue Jul 24, 2020 · 4 comments

Comments

@Anton-Astrouski
Copy link

Anton-Astrouski commented Jul 24, 2020

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
Copy link
Owner

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
Copy link
Author

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

@andriy-samson
Copy link

andriy-samson commented May 8, 2021

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants