[ 
https://issues.apache.org/jira/browse/SLING-11546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17581752#comment-17581752
 ] 

Henry Kuijpers commented on SLING-11546:
----------------------------------------

Failing test case here: 
https://github.com/henrykuijpers/sling-org-apache-sling-api/commit/c8c82d2a1966e76d493da90355aa296d097bc618


{code}
    @Test
    public void testCalendarWithTimeZone() throws Exception {
        final Calendar calendar = 
Calendar.getInstance(TimeZone.getTimeZone("GMT+2"));
        calendar.set(2022, Calendar.AUGUST, 19, 11, 46, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        assertEquals("2022-08-19T11:46:00.000+02:00", 
ObjectConverter.convert(calendar, String.class));
    }
{code}

Gives:
{code}
org.junit.ComparisonFailure: 
Expected :2022-08-19T11:46:00.000+02:00
Actual   :2022-08-19T09:46:00Z
{code}

> ValueMap.get("calendar", String.class) conversion loses timezone information
> ----------------------------------------------------------------------------
>
>                 Key: SLING-11546
>                 URL: https://issues.apache.org/jira/browse/SLING-11546
>             Project: Sling
>          Issue Type: Bug
>          Components: API, ResourceResolver
>    Affects Versions: API 2.21.0, Resource Resolver 1.6.16
>            Reporter: Jelle Bouwmans
>            Priority: Major
>         Attachments: image-2022-08-19-10-41-27-129.png, 
> image-2022-08-19-10-45-25-409.png
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> When doing a ValueMap.get("calendar", String.class) conversion, before 
> SLING-8116, 
> ISO8601.format() was used. Now, Calendar.toInstant().toString() is used. This 
> gives a different result, because the ISO8601 gives the correct timezone, but 
> toInstant() gives the Zulu time.
> toInstant() does the following:
> {quote}public final Instant toInstant() \{ return 
> Instant.ofEpochMilli(getTimeInMillis()); }
> {quote}
> Timezones and offsets are completely ignored.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to