You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2020/06/30 18:00:50 UTC
[camel-quarkus] 01/02: Fix #838 TimeZone-less DTSTART and DTEND not
changed to GMT
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 93b2de2e9a511950dce169f08da5c90375034a61
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Tue Jun 30 18:21:58 2020 +0200
Fix #838 TimeZone-less DTSTART and DTEND not changed to GMT
in native mode with GraalVM 20.1.0+
---
.../quarkus/component/dataformat/it/ICalUtils.java | 18 +++---------------
.../component/dataformat/it/DataformatTest.java | 22 +++++++++++++++++++---
.../dataformat/src/test/resources/test.ics | 6 +++---
3 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java b/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java
index 7cfc018..b13ec41 100644
--- a/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java
+++ b/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java
@@ -22,11 +22,9 @@ import java.time.ZonedDateTime;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.PropertyList;
-import net.fortuna.ical4j.model.TimeZone;
import net.fortuna.ical4j.model.TimeZoneRegistry;
import net.fortuna.ical4j.model.TimeZoneRegistryFactory;
import net.fortuna.ical4j.model.component.VEvent;
-import net.fortuna.ical4j.model.component.VTimeZone;
import net.fortuna.ical4j.model.parameter.Cn;
import net.fortuna.ical4j.model.parameter.Role;
import net.fortuna.ical4j.model.property.Attendee;
@@ -36,6 +34,7 @@ import net.fortuna.ical4j.model.property.DtStamp;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.model.property.ProdId;
import net.fortuna.ical4j.model.property.Summary;
+import net.fortuna.ical4j.model.property.TzId;
import net.fortuna.ical4j.model.property.Uid;
import net.fortuna.ical4j.model.property.Version;
@@ -45,8 +44,6 @@ public class ICalUtils {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
String tzId = start.getZone().getId();
- TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId);
- VTimeZone tz = timezone.getVTimeZone();
// Create the event
PropertyList propertyList = new PropertyList();
@@ -59,7 +56,7 @@ public class ICalUtils {
VEvent meeting = new VEvent(propertyList);
// add timezone info..
- meeting.getProperties().add(tz.getTimeZoneId());
+ meeting.getProperties().add(new TzId(tzId));
// generate unique identifier..
meeting.getProperties().add(new Uid("00000000"));
@@ -82,16 +79,7 @@ public class ICalUtils {
}
static DateTime toDateTime(ZonedDateTime zonedDateTime, TimeZoneRegistry registry) {
- final String tzId = zonedDateTime.getZone().getId();
- final TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId);
- // workaround for https://github.com/apache/camel-quarkus/issues/838
- final DateTime result = new DateTime();
- result.setTimeZone(timezone);
- result.setTime(zonedDateTime.toInstant().toEpochMilli());
- // To reproduce https://github.com/apache/camel-quarkus/issues/838 comment the above, enable the following
- // and remove the TZ from DTSTART and DTEND in src/test/resources/test.ics
- // final DateTime result = new DateTime(zonedDateTime.toInstant().toEpochMilli());
- return result;
+ return new DateTime(zonedDateTime.toInstant().toEpochMilli());
}
}
diff --git a/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java b/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java
index 147cb35..5556571 100644
--- a/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java
+++ b/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java
@@ -19,7 +19,10 @@ package org.apache.camel.quarkus.component.dataformat.it;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.stream.Stream;
import io.quarkus.test.junit.QuarkusTest;
@@ -59,10 +62,15 @@ class DataformatTest {
@Test
public void ical() throws ParseException, IOException {
- final ZonedDateTime START = ZonedDateTime.parse("2007-12-03T10:15:30+01:00[Europe/Paris]");
- final ZonedDateTime END = ZonedDateTime.parse("2007-12-03T11:16:31+01:00[Europe/Paris]");
+ final ZonedDateTime START = LocalDateTime.of(2007, 12, 3, 10, 15, 30).atZone(ZoneId.systemDefault());
+ final ZonedDateTime END = LocalDateTime.of(2007, 12, 03, 11, 16, 31).atZone(ZoneId.systemDefault());
- final String icalString = IOUtils.toString(getClass().getResourceAsStream("/test.ics"), StandardCharsets.UTF_8);
+ final String icsTemplate = IOUtils.toString(getClass().getResourceAsStream("/test.ics"), StandardCharsets.UTF_8);
+ final String icalString = String.format(
+ icsTemplate,
+ toFormatedLocalDateTime(START),
+ toFormatedLocalDateTime(END),
+ START.getZone().getId());
final String actualIcal = RestAssured
.given()
@@ -87,4 +95,12 @@ class DataformatTest {
Assertions.assertEquals(icalString, body.replace("\r", ""));
}
+ static String toFormatedLocalDateTime(ZonedDateTime zonedDateTime) {
+ String result = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'hhmmss"));
+ if (zonedDateTime.getZone().getId().equals("Etc/UTC")) {
+ result += "Z";
+ }
+ return result;
+ }
+
}
diff --git a/integration-tests/dataformat/src/test/resources/test.ics b/integration-tests/dataformat/src/test/resources/test.ics
index 6bb9d71..c730b9a 100644
--- a/integration-tests/dataformat/src/test/resources/test.ics
+++ b/integration-tests/dataformat/src/test/resources/test.ics
@@ -4,10 +4,10 @@ PRODID:-//Events Calendar//iCal4j 1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:19700101T000000Z
-DTSTART;TZID=Europe/Paris:20071203T101530
-DTEND;TZID=Europe/Paris:20071203T111631
+DTSTART:%s
+DTEND:%s
SUMMARY:Progress Meeting
-TZID:Europe/Paris
+TZID:%s
UID:00000000
ATTENDEE;ROLE=REQ-PARTICIPANT;CN=dev1@mycompany:mailto:dev1@mycompany
END:VEVENT