Skip to content

Commit ac125d1

Browse files
author
Zihlu Wang
committed
feat: added feature
1 parent 75e858c commit ac125d1

26 files changed

+201
-149
lines changed

webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

webcal/src/main/java/com/onixbyte/icalendar/component/Event.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class Event extends CalendarComponent {
5151
/**
5252
*
5353
*/
54-
private DateTimeStamp dtStart;
54+
// private DateTimeStamp dtStart;
5555

5656
/*
5757
* The following properties are OPTIONAL, but MUST NOT occur more than once.

webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private Categories(List<String> value) {
3131
}
3232

3333
public static class Builder {
34-
private List<String> categories;
34+
private final List<String> categories;
3535

3636
private Builder() {
3737
categories = new ArrayList<>();

webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20-
import com.onixbyte.icalendar.CalendarUtil;
2120
import com.onixbyte.icalendar.property.parameter.AlternateRepresentation;
2221
import com.onixbyte.icalendar.property.parameter.Language;
2322

24-
import java.util.Objects;
25-
import java.util.Optional;
26-
2723
public record Comment(AlternateRepresentation altRep,
2824
Language language,
2925
String value) implements TextProperty, ComponentProperty {
@@ -32,6 +28,6 @@ public record Comment(AlternateRepresentation altRep,
3228

3329
@Override
3430
public String resolve() {
35-
return composeResolution(PROPERTY_NAME, altRep, language, value);
31+
return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, value);
3632
}
3733
}

webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20-
import com.onixbyte.icalendar.CalendarUtil;
20+
import com.onixbyte.icalendar.core.DateTimeFormatters;
2121

2222
import java.time.LocalDateTime;
2323
import java.time.ZoneId;
@@ -31,6 +31,6 @@ public String resolve() {
3131
return PROPERTY_NAME + ":" + value
3232
.atZone(ZoneId.systemDefault())
3333
.withZoneSameInstant(ZoneId.of("UTC"))
34-
.format(DateTimeProperty.utcDateTimeFormatter());
34+
.format(DateTimeFormatters.utcDateTimeFormatter()) + "\n";
3535
}
3636
}

webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20+
import com.onixbyte.icalendar.core.DateTimeFormatters;
21+
22+
import java.time.LocalDateTime;
23+
import java.time.ZoneId;
24+
2025
/**
2126
* DateTimeCreated
2227
*
2328
* @author Zihlu WANG
2429
*/
25-
public final class DateTimeCreated {
30+
public record DateTimeCreated(LocalDateTime created) implements ComponentProperty {
31+
32+
private static final String PROPERTY_NAME = "CREATED";
33+
34+
@Override
35+
public String resolve() {
36+
return PROPERTY_NAME + ":" + created
37+
.atZone(ZoneId.systemDefault())
38+
.withZoneSameInstant(ZoneId.of("UTC"))
39+
.format(DateTimeFormatters.utcDateTimeFormatter()) + "\n";
40+
}
2641
}

webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20-
import com.onixbyte.icalendar.CalendarUtil;
2120
import com.onixbyte.icalendar.property.parameter.ValueDataType;
2221

2322
import java.time.LocalDateTime;
24-
import java.util.List;
2523
import java.util.Objects;
26-
import java.util.Optional;
2724

2825
public record DateTimeDue(ValueDataType valueDataType,
2926
LocalDateTime localDateTime) implements DateTimeProperty, ComponentProperty {

webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20-
import com.onixbyte.icalendar.CalendarUtil;
20+
import com.onixbyte.icalendar.core.DateTimeFormatters;
2121
import com.onixbyte.icalendar.property.parameter.ValueDataType;
2222

2323
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425
import java.time.format.DateTimeFormatter;
2526
import java.util.List;
26-
import java.util.Objects;
2727
import java.util.Optional;
2828

2929
public interface DateTimeProperty {
@@ -33,18 +33,6 @@ public interface DateTimeProperty {
3333
ValueDataType.DATE_TIME
3434
);
3535

36-
DateTimeFormatter utcDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'");
37-
38-
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
39-
40-
static DateTimeFormatter utcDateTimeFormatter() {
41-
return utcDateTimeFormatter;
42-
}
43-
44-
static DateTimeFormatter dateFormatter() {
45-
return dateFormatter;
46-
}
47-
4836
static String composeResolution(String propertyName,
4937
ValueDataType valueDataType,
5038
LocalDateTime localDateTime) {
@@ -57,12 +45,16 @@ static String composeResolution(String propertyName,
5745
var dateTimeFormatter = switch (Optional.ofNullable(valueDataType)
5846
.filter(SUPPORTED_VALUES::contains)
5947
.orElse(ValueDataType.DATE_TIME)) {
60-
case DATE -> dateFormatter;
48+
case DATE -> DateTimeFormatters.dateFormatter();
6149
case BINARY, UTC_OFFSET, BOOLEAN, CAL_ADDRESS, DURATION, FLOAT, INTEGER, PERIOD,
62-
RECURRENCE_RULE, TEXT, URI, DATE_TIME -> utcDateTimeFormatter;
50+
RECURRENCE_RULE, TEXT, URI, DATE_TIME -> DateTimeFormatters.utcDateTimeFormatter();
6351
};
6452

65-
dateTimeEndBuilder.append(":").append(localDateTime.format(dateTimeFormatter)).append("\n");
53+
dateTimeEndBuilder.append(":")
54+
.append(localDateTime.atZone(ZoneId.systemDefault())
55+
.withZoneSameInstant(ZoneId.of("UTC"))
56+
.format(dateTimeFormatter))
57+
.append("\n");
6658
return dateTimeEndBuilder.toString();
6759
}
6860

webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package com.onixbyte.icalendar.component.property;
1919

2020
import com.onixbyte.icalendar.calendar.property.Method;
21-
import com.onixbyte.icalendar.config.Formatters;
21+
import com.onixbyte.icalendar.core.DateTimeFormatters;
2222

2323
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425

2526
/**
2627
* In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that
@@ -50,7 +51,15 @@
5051
*
5152
* @author Zihlu WANG
5253
*/
53-
// public final class DateTimeStamp implements DateTimeProperty, ComponentProperty {
54-
//
55-
//
56-
// }
54+
public record DateTimeStamp(LocalDateTime dateTimeStamp) implements DateTimeProperty, ComponentProperty {
55+
56+
private static final String PROPERTY_NAME = "DTSTAMP";
57+
58+
@Override
59+
public String resolve() {
60+
return PROPERTY_NAME + ":" + dateTimeStamp
61+
.atZone(ZoneId.systemDefault())
62+
.withZoneSameInstant(ZoneId.of("UTC"))
63+
.format(DateTimeFormatters.utcDateTimeFormatter()) + "\n";
64+
}
65+
}

webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20-
import com.onixbyte.icalendar.CalendarUtil;
2120
import com.onixbyte.icalendar.property.parameter.AlternateRepresentation;
2221
import com.onixbyte.icalendar.property.parameter.Language;
2322

@@ -29,7 +28,7 @@ public record Description(AlternateRepresentation altRep,
2928

3029
@Override
3130
public String resolve() {
32-
return composeResolution(PROPERTY_NAME, altRep, language, value);
31+
return TextProperty.composeResolution(PROPERTY_NAME, altRep, language, value);
3332
}
3433

3534
}

0 commit comments

Comments
 (0)