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

Created and LastModified use wrong extend from DateProperty #614

Open
derklaro opened this issue Dec 3, 2022 · 3 comments
Open

Created and LastModified use wrong extend from DateProperty #614

derklaro opened this issue Dec 3, 2022 · 3 comments
Assignees
Labels

Comments

@derklaro
Copy link

derklaro commented Dec 3, 2022

Describe the bug
The classes Created and LastModified are both extending DateProperty<Instant> and UtcProperty which indicates that the return value of getDate should be a Instant representing a UTC timestamp. But in my case the return value of getDate is a ZonedDateTime.
To workaround the issue I am just getting the DateProperty and cast it to a ZonedDateTime:

        DateProperty<Temporal> creationTime = component.getRequiredProperty("CREATED");
        entry.setCreated(((ZonedDateTime) creationTime.getDate()).withZoneSameInstant(ZoneOffset.UTC).toInstant());

To Reproduce
Example VEvent which is causing the issue:

BEGIN:VEVENT
UID:12345@test.de
DTSTART;TZID=Europe/Berlin:20221108T090000
DTEND;TZID=Europe/Berlin:20221108T121500
DTSTAMP;TZID=Europe/Berlin:20221203T100650
LAST-MODIFIED;TZID=Europe/Berlin:20221108T182747
CREATED;TZID=Europe/Berlin:20220821T084513
SUMMARY:Test
DESCRIPTION:Test
LOCATION:Virtual-Room-26
END:VEVENT

Expected behavior
Either the created and LastModified classes are extening correctly from DateProperty or the return value of getDate is actually an Instant.

Screenshots
image
image

Environment (please complete the following information):

  • OS: Windows 11 22H2
  • Java Version 17.0.1 (2021-10-19 LTS)
  • iCal4j Version 4.0.0-beta4
@douglm
Copy link
Contributor

douglm commented Dec 3, 2022 via email

@derklaro
Copy link
Author

derklaro commented Dec 3, 2022

Hm, that kinda makes sense then... But I cannot access the data, I am just getting the exported data and I'm trying to parse it. It seems a bit odd that the time is parsed to something different anyway?

@benfortuna
Copy link
Member

When we parse invalid properties such a CREATED with a non-UTC value, the intention is to try to convert to an equivalent valid value. In this case however, I think we currently just allow the ZonedDateTime to be parsed, but we aren't converting to an Instant value like we should (and also should only allow if RELAXED_PARSING flag is enabled).

I'll have a look to see if we can better enforce the typing for UTC properties.

Also note this related proposal to use ZonedDateTime instead of Instant for UTC properties, however I think there could be wider implications here which require further analysis.

@benfortuna benfortuna self-assigned this Dec 4, 2022
@benfortuna benfortuna added the bug label Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants