Skip to content

Strange timezone offsets #8

Open

Description

@Anton-Astrouski

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

Activity

  1. sisyphsu commented on Jul 28, 2020

    @sisyphsu
    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.

  2. Anton-Astrouski commented on Aug 4, 2020

    @Anton-Astrouski
    Author

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

  3. andriy-samson commented on May 8, 2021

    @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.

  4. sisyphsu commented on Nov 27, 2021

    @sisyphsu
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions