diff --git a/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java b/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java deleted file mode 100644 index 7427203..0000000 --- a/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2024-2024 OnixByte. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.onixbyte.icalendar; - -import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; -import com.onixbyte.icalendar.property.parameter.Language; - -import java.time.format.DateTimeFormatter; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Supplier; - -/** - * CalendarUtil - * - * @author Zihlu WANG - */ -public final class CalendarUtil { - - private CalendarUtil() { - } - - - -} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java b/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java index bf88742..0f537db 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java @@ -51,7 +51,7 @@ public class Event extends CalendarComponent { /** * */ - private DateTimeStamp dtStart; + // private DateTimeStamp dtStart; /* * The following properties are OPTIONAL, but MUST NOT occur more than once. diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java index 1c4aace..0a0c91f 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java @@ -31,7 +31,7 @@ public final class Categories implements ComponentProperty { } public static class Builder { - private List categories; + private final List categories; private Builder() { categories = new ArrayList<>(); diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java index e13bd62..f7c6e0f 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java @@ -17,13 +17,9 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.CalendarUtil; import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; import com.onixbyte.icalendar.property.parameter.Language; -import java.util.Objects; -import java.util.Optional; - public record Comment(AlternateRepresentation altRep, Language language, String value) implements TextProperty, ComponentProperty { @@ -32,6 +28,6 @@ public record Comment(AlternateRepresentation altRep, @Override public String resolve() { - return composeResolution(PROPERTY_NAME, altRep, language, value); + return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, value); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java index 7fb6bd2..71b2481 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.core.DateTimeFormatters; import java.time.LocalDateTime; import java.time.ZoneId; @@ -31,6 +31,6 @@ public record DateTimeCompleted(LocalDateTime value) implements DateTimeProperty return PROPERTY_NAME + ":" + value .atZone(ZoneId.systemDefault()) .withZoneSameInstant(ZoneId.of("UTC")) - .format(DateTimeProperty.utcDateTimeFormatter()); + .format(DateTimeFormatters.utcDateTimeFormatter()) + "\n"; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java index e2b4e34..53a873c 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java @@ -17,10 +17,25 @@ package com.onixbyte.icalendar.component.property; +import com.onixbyte.icalendar.core.DateTimeFormatters; + +import java.time.LocalDateTime; +import java.time.ZoneId; + /** * DateTimeCreated * * @author Zihlu WANG */ -public final class DateTimeCreated { +public record DateTimeCreated(LocalDateTime created) implements ComponentProperty { + + private static final String PROPERTY_NAME = "CREATED"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + created + .atZone(ZoneId.systemDefault()) + .withZoneSameInstant(ZoneId.of("UTC")) + .format(DateTimeFormatters.utcDateTimeFormatter()) + "\n"; + } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java index fb56b8a..7bfca58 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java @@ -17,13 +17,10 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.CalendarUtil; import com.onixbyte.icalendar.property.parameter.ValueDataType; import java.time.LocalDateTime; -import java.util.List; import java.util.Objects; -import java.util.Optional; public record DateTimeDue(ValueDataType valueDataType, LocalDateTime localDateTime) implements DateTimeProperty, ComponentProperty { diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java index 0d019d6..12768e4 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java @@ -17,13 +17,13 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.core.DateTimeFormatters; import com.onixbyte.icalendar.property.parameter.ValueDataType; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.List; -import java.util.Objects; import java.util.Optional; public interface DateTimeProperty { @@ -33,18 +33,6 @@ public interface DateTimeProperty { ValueDataType.DATE_TIME ); - DateTimeFormatter utcDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"); - - DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - - static DateTimeFormatter utcDateTimeFormatter() { - return utcDateTimeFormatter; - } - - static DateTimeFormatter dateFormatter() { - return dateFormatter; - } - static String composeResolution(String propertyName, ValueDataType valueDataType, LocalDateTime localDateTime) { @@ -57,12 +45,16 @@ public interface DateTimeProperty { var dateTimeFormatter = switch (Optional.ofNullable(valueDataType) .filter(SUPPORTED_VALUES::contains) .orElse(ValueDataType.DATE_TIME)) { - case DATE -> dateFormatter; + case DATE -> DateTimeFormatters.dateFormatter(); case BINARY, UTC_OFFSET, BOOLEAN, CAL_ADDRESS, DURATION, FLOAT, INTEGER, PERIOD, - RECURRENCE_RULE, TEXT, URI, DATE_TIME -> utcDateTimeFormatter; + RECURRENCE_RULE, TEXT, URI, DATE_TIME -> DateTimeFormatters.utcDateTimeFormatter(); }; - dateTimeEndBuilder.append(":").append(localDateTime.format(dateTimeFormatter)).append("\n"); + dateTimeEndBuilder.append(":") + .append(localDateTime.atZone(ZoneId.systemDefault()) + .withZoneSameInstant(ZoneId.of("UTC")) + .format(dateTimeFormatter)) + .append("\n"); return dateTimeEndBuilder.toString(); } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java index 9dd7ba0..3c20d27 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java @@ -18,9 +18,10 @@ package com.onixbyte.icalendar.component.property; import com.onixbyte.icalendar.calendar.property.Method; -import com.onixbyte.icalendar.config.Formatters; +import com.onixbyte.icalendar.core.DateTimeFormatters; import java.time.LocalDateTime; +import java.time.ZoneId; /** * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that @@ -50,7 +51,15 @@ import java.time.LocalDateTime; * * @author Zihlu WANG */ -// public final class DateTimeStamp implements DateTimeProperty, ComponentProperty { -// -// -// } +public record DateTimeStamp(LocalDateTime dateTimeStamp) implements DateTimeProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "DTSTAMP"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + dateTimeStamp + .atZone(ZoneId.systemDefault()) + .withZoneSameInstant(ZoneId.of("UTC")) + .format(DateTimeFormatters.utcDateTimeFormatter()) + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java index 317c07b..fced46c 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java @@ -17,7 +17,6 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.CalendarUtil; import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; import com.onixbyte.icalendar.property.parameter.Language; @@ -29,7 +28,7 @@ public record Description(AlternateRepresentation altRep, @Override public String resolve() { - return composeResolution(PROPERTY_NAME, altRep, language, value); + return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, value); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java index 027e400..43e2549 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java @@ -49,7 +49,7 @@ public final class FreeBusyTime implements ComponentProperty { private FreeBusyTimeType freeBusyType; - private List freeBusyValue; + private final List freeBusyValue; private Builder() { this.freeBusyValue = new ArrayList<>(); @@ -70,7 +70,8 @@ public final class FreeBusyTime implements ComponentProperty { freeBusyBuilder.append(":").append(String.join(",", freeBusyValue .stream() .map(Period::resolve) - .toList())); + .toList())) + .append("\n"); return freeBusyBuilder.toString(); } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java index 21b3ddd..b243ffd 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java @@ -17,10 +17,24 @@ package com.onixbyte.icalendar.component.property; +import com.onixbyte.icalendar.core.DateTimeFormatters; + +import java.time.LocalDateTime; +import java.time.ZoneId; + /** * LastModified * * @author Zihlu WANG */ -public final class LastModified { +public record LastModified(LocalDateTime value) implements ComponentProperty { + + private static final String PROPERTY_NAME = "LAST-MODIFIED"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + value.atZone(ZoneId.systemDefault()) + .withZoneSameInstant(ZoneId.of("UTC")) + .format(DateTimeFormatters.utcDateTimeFormatter()) + "\n"; + } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java index d50f0d4..eebdf9a 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java @@ -17,7 +17,6 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.CalendarUtil; import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; import com.onixbyte.icalendar.property.parameter.Language; @@ -29,6 +28,6 @@ public record Location(AlternateRepresentation altRep, @Override public String resolve() { - return composeResolution(PROPERTY_NAME, altRep, language, value); + return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, value); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java index ddc05a5..3e8fe8a 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java @@ -40,7 +40,7 @@ public final class Resources implements TextProperty, ComponentProperty { } public static class Builder { - private List value; + private final List value; private AlternateRepresentation altRep; @@ -81,6 +81,6 @@ public final class Resources implements TextProperty, ComponentProperty { @Override public String resolve() { - return composeResolution(PROPERTY_NAME, altRep, language, () -> String.join(",", value)); + return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, () -> String.join(",", value)); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/SequenceNumber.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/SequenceNumber.java new file mode 100644 index 0000000..4722dea --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/SequenceNumber.java @@ -0,0 +1,11 @@ +package com.onixbyte.icalendar.component.property; + +public record SequenceNumber(Integer sequence) implements ComponentProperty { + + private static final String PROPERTY_NAME = "SEQUENCE"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + sequence + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java index 04e8d71..53e4bf6 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java @@ -28,6 +28,6 @@ public record Summary(AlternateRepresentation altRep, @Override public String resolve() { - return composeResolution(PROPERTY_NAME, altRep, language, value); + return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, value); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java index 50d12f8..ad45e3e 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java @@ -26,7 +26,7 @@ import java.util.function.Supplier; public interface TextProperty { - default String composeResolution(String propertyName, + static String composeResolution(String propertyName, AlternateRepresentation altRep, Language language, String value) { @@ -49,7 +49,7 @@ public interface TextProperty { return resolutionBuilder.toString(); } - default String composeResolution(String propertyName, + static String composeResolution(String propertyName, AlternateRepresentation altRep, Language language, Supplier valueSupplier) { diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeTransparency.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeTransparency.java new file mode 100644 index 0000000..f353610 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeTransparency.java @@ -0,0 +1,15 @@ +package com.onixbyte.icalendar.component.property; + +public enum TimeTransparency implements ComponentProperty { + + OPAQUE, + TRANSPARENT, + ; + + private static final String PROPERTY_NAME = "TRANSP"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + name() + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneIdentifier.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneIdentifier.java new file mode 100644 index 0000000..eeed356 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneIdentifier.java @@ -0,0 +1,19 @@ +package com.onixbyte.icalendar.component.property; + +import java.time.ZoneId; + +public final class TimeZoneIdentifier implements ComponentProperty { + + private static final String PROPERTY_NAME = "TZID"; + + private final ZoneId timeZoneIdentifier; + + public TimeZoneIdentifier(String timeZoneIdentifier) { + this.timeZoneIdentifier = ZoneId.of(timeZoneIdentifier); + } + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + timeZoneIdentifier + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneName.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneName.java new file mode 100644 index 0000000..8294566 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneName.java @@ -0,0 +1,24 @@ +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.property.parameter.Language; + +import java.util.Optional; + +public record TimeZoneName(Language language, String value) implements ComponentProperty { + + private static final String PROPERTY_NAME = "TZNAME"; + + @Override + public String resolve() { + var builder = new StringBuilder(PROPERTY_NAME); + + Optional.ofNullable(language) + .ifPresent((lang) -> builder.append(";").append(lang.resolve())); + + builder.append(":") + .append(value) + .append("\n"); + + return builder.toString(); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneOffsetFrom.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneOffsetFrom.java new file mode 100644 index 0000000..14d7668 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TimeZoneOffsetFrom.java @@ -0,0 +1,4 @@ +package com.onixbyte.icalendar.component.property; + +public record TimeZoneOffsetFrom() { +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java b/webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java deleted file mode 100644 index ec1cc48..0000000 --- a/webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2024-2024 OnixByte. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.onixbyte.icalendar.config; - -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.Objects; - -/** - * A formatter to format {@link java.time.LocalDateTime}. - * - * @author Zihlu Wang - */ -public final class Formatters { - - /** - * Get the {@link java.time.format.DateTimeFormatter datetime formatter} - * with UTC pattern and timezone. - * - * @return the {@link java.time.format.DateTimeFormatter datetime formatter} - * with UTC pattern and timezone - */ - public static DateTimeFormatter getUtcDatetimeFormatter() { - if (Objects.isNull(utcDateTimeFormatter)) { - utcDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC); - } - - return utcDateTimeFormatter; - } - - private static DateTimeFormatter utcDateTimeFormatter; - - /** - * Private constructor to prevent this class being initialised. - */ - private Formatters() { - } - -} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java b/webcal/src/main/java/com/onixbyte/icalendar/core/CalendarUtil.java similarity index 80% rename from webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java rename to webcal/src/main/java/com/onixbyte/icalendar/core/CalendarUtil.java index 2091569..392c4dd 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/core/CalendarUtil.java @@ -15,9 +15,18 @@ * limitations under the License. */ +package com.onixbyte.icalendar.core; + /** - * + * CalendarUtil * - * @since 1.0.0 + * @author Zihlu WANG */ -package com.onixbyte.icalendar.config; \ No newline at end of file +public final class CalendarUtil { + + private CalendarUtil() { + } + + + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/core/DateTimeFormatters.java b/webcal/src/main/java/com/onixbyte/icalendar/core/DateTimeFormatters.java new file mode 100644 index 0000000..258f57d --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/core/DateTimeFormatters.java @@ -0,0 +1,42 @@ +package com.onixbyte.icalendar.core; + +import com.onixbyte.icalendar.property.parameter.ValueDataType; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Objects; +import java.util.Optional; + +public final class DateTimeFormatters { + + private DateTimeFormatters() { + } + + private static DateTimeFormatter utcDateTimeFormatter; + + private static DateTimeFormatter dateFormatter; + + private static DateTimeFormatter localDateTimeFormatter; + + public static DateTimeFormatter utcDateTimeFormatter() { + if (Objects.isNull(utcDateTimeFormatter)) { + utcDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"); + } + return utcDateTimeFormatter; + } + + public static DateTimeFormatter dateFormatter() { + if (Objects.isNull(dateFormatter)) { + dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + } + return dateFormatter; + } + + public static DateTimeFormatter localDateTimeFormatter() { + if (Objects.isNull(localDateTimeFormatter)) { + localDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss"); + } + return localDateTimeFormatter; + } + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java index a1c829e..e9325f1 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java @@ -17,8 +17,7 @@ package com.onixbyte.icalendar.datatype; -import com.onixbyte.icalendar.component.property.DateTimeProperty; -import com.onixbyte.icalendar.property.Resolvable; +import com.onixbyte.icalendar.core.DateTimeFormatters; import java.time.LocalDateTime; @@ -38,7 +37,7 @@ public final class PeriodExplicit implements Period { @Override public String resolve() { - return startTime.format(DateTimeProperty.utcDateTimeFormatter()) + "/" + - endTime.format(DateTimeProperty.utcDateTimeFormatter()); + return startTime.format(DateTimeFormatters.utcDateTimeFormatter()) + "/" + + endTime.format(DateTimeFormatters.utcDateTimeFormatter()); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java index 3f02ace..835e5ed 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java @@ -18,6 +18,7 @@ package com.onixbyte.icalendar.datatype; import com.onixbyte.icalendar.component.property.DateTimeProperty; +import com.onixbyte.icalendar.core.DateTimeFormatters; import java.time.Duration; import java.time.LocalDateTime; @@ -30,6 +31,6 @@ public final class PeriodStart implements Period { @Override public String resolve() { - return start.format(DateTimeProperty.utcDateTimeFormatter()) + "/" + duration; + return start.format(DateTimeFormatters.utcDateTimeFormatter()) + "/" + duration; } }