2929import java .nio .charset .Charset ;
3030import java .nio .charset .StandardCharsets ;
3131import java .text .NumberFormat ;
32+ import java .time .ZonedDateTime ;
3233import java .time .format .DateTimeFormatter ;
3334import java .time .format .FormatStyle ;
3435import java .time .temporal .TemporalAccessor ;
@@ -85,16 +86,19 @@ private static class FormatModifier implements Modifier {
8586 static final String MEDIUM_DATE = "mediumDate" ;
8687 static final String LONG_DATE = "longDate" ;
8788 static final String FULL_DATE = "fullDate" ;
89+ static final String ISO_DATE = "isoDate" ;
8890
8991 static final String SHORT_TIME = "shortTime" ;
9092 static final String MEDIUM_TIME = "mediumTime" ;
9193 static final String LONG_TIME = "longTime" ;
9294 static final String FULL_TIME = "fullTime" ;
95+ static final String ISO_TIME = "isoTime" ;
9396
9497 static final String SHORT_DATE_TIME = "shortDateTime" ;
9598 static final String MEDIUM_DATE_TIME = "mediumDateTime" ;
9699 static final String LONG_DATE_TIME = "longDateTime" ;
97100 static final String FULL_DATE_TIME = "fullDateTime" ;
101+ static final String ISO_DATE_TIME = "isoDateTime" ;
98102
99103 enum DateTimeType {
100104 DATE ,
@@ -133,6 +137,10 @@ public Object apply(Object value, String argument, Locale locale, TimeZone timeZ
133137 return format (value , DateTimeType .DATE , FormatStyle .FULL , locale , timeZone );
134138 }
135139
140+ case ISO_DATE : {
141+ return format (value , DateTimeType .DATE , null , null , timeZone );
142+ }
143+
136144 case SHORT_TIME : {
137145 return format (value , DateTimeType .TIME , FormatStyle .SHORT , locale , timeZone );
138146 }
@@ -149,6 +157,10 @@ public Object apply(Object value, String argument, Locale locale, TimeZone timeZ
149157 return format (value , DateTimeType .TIME , FormatStyle .FULL , locale , timeZone );
150158 }
151159
160+ case ISO_TIME : {
161+ return format (value , DateTimeType .TIME , null , null , timeZone );
162+ }
163+
152164 case SHORT_DATE_TIME : {
153165 return format (value , DateTimeType .DATE_TIME , FormatStyle .SHORT , locale , timeZone );
154166 }
@@ -165,6 +177,10 @@ public Object apply(Object value, String argument, Locale locale, TimeZone timeZ
165177 return format (value , DateTimeType .DATE_TIME , FormatStyle .FULL , locale , timeZone );
166178 }
167179
180+ case ISO_DATE_TIME : {
181+ return format (value , DateTimeType .DATE_TIME , null , null , timeZone );
182+ }
183+
168184 default : {
169185 return String .format (locale , argument , value );
170186 }
@@ -177,22 +193,34 @@ static String format(Object value, DateTimeType dateTimeType, FormatStyle format
177193 }
178194
179195 if (value instanceof Date ) {
180- value = (( Date )value ).toInstant (). atZone ( timeZone .toZoneId ()). toLocalDateTime ( );
196+ value = ZonedDateTime . ofInstant ((( Date )value ).toInstant (), timeZone .toZoneId ());
181197 }
182198
183199 TemporalAccessor temporalAccessor = (TemporalAccessor )value ;
184200
185201 switch (dateTimeType ) {
186202 case DATE : {
187- return DateTimeFormatter .ofLocalizedDate (formatStyle ).withLocale (locale ).format (temporalAccessor );
203+ if (formatStyle != null ) {
204+ return DateTimeFormatter .ofLocalizedDate (formatStyle ).withLocale (locale ).format (temporalAccessor );
205+ } else {
206+ return DateTimeFormatter .ISO_OFFSET_DATE .format (ZonedDateTime .from (temporalAccessor ));
207+ }
188208 }
189209
190210 case TIME : {
191- return DateTimeFormatter .ofLocalizedTime (formatStyle ).withLocale (locale ).format (temporalAccessor );
211+ if (formatStyle != null ) {
212+ return DateTimeFormatter .ofLocalizedTime (formatStyle ).withLocale (locale ).format (temporalAccessor );
213+ } else {
214+ return DateTimeFormatter .ISO_OFFSET_TIME .format (ZonedDateTime .from (temporalAccessor ));
215+ }
192216 }
193217
194218 case DATE_TIME : {
195- return DateTimeFormatter .ofLocalizedDateTime (formatStyle ).withLocale (locale ).format (temporalAccessor );
219+ if (formatStyle != null ) {
220+ return DateTimeFormatter .ofLocalizedDateTime (formatStyle ).withLocale (locale ).format (temporalAccessor );
221+ } else {
222+ return DateTimeFormatter .ISO_OFFSET_DATE_TIME .format (ZonedDateTime .from (temporalAccessor ));
223+ }
196224 }
197225
198226 default : {
0 commit comments