1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.time.format;
17
18 import java.util.Collection;
19 import java.util.HashSet;
20 import java.util.Set;
21
22 import org.joda.time.DateTimeFieldType;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public class ISODateTimeFormat {
60
61
62 private static DateTimeFormatter
63 ye,
64 mye,
65 dme,
66 we,
67 wwe,
68 dwe,
69 dye,
70 hde,
71 mhe,
72 sme,
73 fse,
74 ze,
75 lte,
76
77
78 ym,
79 ymd,
80
81
82 ww,
83 wwd,
84
85
86 hm,
87 hms,
88 hmsl,
89 hmsf,
90
91 dh,
92 dhm,
93 dhms,
94 dhmsl,
95 dhmsf,
96
97
98 t,
99 tx,
100 tt,
101 ttx,
102 dt,
103 dtx,
104
105
106 wdt,
107 wdtx,
108
109 od,
110 odt,
111 odtx,
112
113 bd,
114 bt,
115 btx,
116 btt,
117 bttx,
118 bdt,
119 bdtx,
120
121 bod,
122 bodt,
123 bodtx,
124
125 bwd,
126 bwdt,
127 bwdtx,
128
129 dpe,
130 tpe,
131 dp,
132 ldp,
133 tp,
134 ltp,
135 dtp,
136 dotp,
137 ldotp;
138
139
140
141
142
143
144 protected ISODateTimeFormat() {
145 super();
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 public static DateTimeFormatter forFields(
226 Collection<DateTimeFieldType> fields,
227 boolean extended,
228 boolean strictISO) {
229
230 if (fields == null || fields.size() == 0) {
231 throw new IllegalArgumentException("The fields must not be null or empty");
232 }
233 Set<DateTimeFieldType> workingFields = new HashSet<DateTimeFieldType>(fields);
234 int inputSize = workingFields.size();
235 boolean reducedPrec = false;
236 DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
237
238 if (workingFields.contains(DateTimeFieldType.monthOfYear())) {
239 reducedPrec = dateByMonth(bld, workingFields, extended, strictISO);
240 } else if (workingFields.contains(DateTimeFieldType.dayOfYear())) {
241 reducedPrec = dateByOrdinal(bld, workingFields, extended, strictISO);
242 } else if (workingFields.contains(DateTimeFieldType.weekOfWeekyear())) {
243 reducedPrec = dateByWeek(bld, workingFields, extended, strictISO);
244 } else if (workingFields.contains(DateTimeFieldType.dayOfMonth())) {
245 reducedPrec = dateByMonth(bld, workingFields, extended, strictISO);
246 } else if (workingFields.contains(DateTimeFieldType.dayOfWeek())) {
247 reducedPrec = dateByWeek(bld, workingFields, extended, strictISO);
248 } else if (workingFields.remove(DateTimeFieldType.year())) {
249 bld.append(yearElement());
250 reducedPrec = true;
251 } else if (workingFields.remove(DateTimeFieldType.weekyear())) {
252 bld.append(weekyearElement());
253 reducedPrec = true;
254 }
255 boolean datePresent = (workingFields.size() < inputSize);
256
257
258 time(bld, workingFields, extended, strictISO, reducedPrec, datePresent);
259
260
261 if (bld.canBuildFormatter() == false) {
262 throw new IllegalArgumentException("No valid format for fields: " + fields);
263 }
264
265
266
267 try {
268 fields.retainAll(workingFields);
269 } catch (UnsupportedOperationException ex) {
270
271 }
272 return bld.toFormatter();
273 }
274
275
276
277
278
279
280
281
282
283
284
285
286
287 private static boolean dateByMonth(
288 DateTimeFormatterBuilder bld,
289 Collection<DateTimeFieldType> fields,
290 boolean extended,
291 boolean strictISO) {
292
293 boolean reducedPrec = false;
294 if (fields.remove(DateTimeFieldType.year())) {
295 bld.append(yearElement());
296 if (fields.remove(DateTimeFieldType.monthOfYear())) {
297 if (fields.remove(DateTimeFieldType.dayOfMonth())) {
298
299 appendSeparator(bld, extended);
300 bld.appendMonthOfYear(2);
301 appendSeparator(bld, extended);
302 bld.appendDayOfMonth(2);
303 } else {
304
305 bld.appendLiteral('-');
306 bld.appendMonthOfYear(2);
307 reducedPrec = true;
308 }
309 } else {
310 if (fields.remove(DateTimeFieldType.dayOfMonth())) {
311
312 checkNotStrictISO(fields, strictISO);
313 bld.appendLiteral('-');
314 bld.appendLiteral('-');
315 bld.appendDayOfMonth(2);
316 } else {
317
318 reducedPrec = true;
319 }
320 }
321
322 } else if (fields.remove(DateTimeFieldType.monthOfYear())) {
323 bld.appendLiteral('-');
324 bld.appendLiteral('-');
325 bld.appendMonthOfYear(2);
326 if (fields.remove(DateTimeFieldType.dayOfMonth())) {
327
328 appendSeparator(bld, extended);
329 bld.appendDayOfMonth(2);
330 } else {
331
332 reducedPrec = true;
333 }
334 } else if (fields.remove(DateTimeFieldType.dayOfMonth())) {
335
336 bld.appendLiteral('-');
337 bld.appendLiteral('-');
338 bld.appendLiteral('-');
339 bld.appendDayOfMonth(2);
340 }
341 return reducedPrec;
342 }
343
344
345
346
347
348
349
350
351
352
353
354
355 private static boolean dateByOrdinal(
356 DateTimeFormatterBuilder bld,
357 Collection<DateTimeFieldType> fields,
358 boolean extended,
359 boolean strictISO) {
360
361 boolean reducedPrec = false;
362 if (fields.remove(DateTimeFieldType.year())) {
363 bld.append(yearElement());
364 if (fields.remove(DateTimeFieldType.dayOfYear())) {
365
366 appendSeparator(bld, extended);
367 bld.appendDayOfYear(3);
368 } else {
369
370 reducedPrec = true;
371 }
372
373 } else if (fields.remove(DateTimeFieldType.dayOfYear())) {
374
375 bld.appendLiteral('-');
376 bld.appendDayOfYear(3);
377 }
378 return reducedPrec;
379 }
380
381
382
383
384
385
386
387
388
389
390
391
392 private static boolean dateByWeek(
393 DateTimeFormatterBuilder bld,
394 Collection<DateTimeFieldType> fields,
395 boolean extended,
396 boolean strictISO) {
397
398 boolean reducedPrec = false;
399 if (fields.remove(DateTimeFieldType.weekyear())) {
400 bld.append(weekyearElement());
401 if (fields.remove(DateTimeFieldType.weekOfWeekyear())) {
402 appendSeparator(bld, extended);
403 bld.appendLiteral('W');
404 bld.appendWeekOfWeekyear(2);
405 if (fields.remove(DateTimeFieldType.dayOfWeek())) {
406
407 appendSeparator(bld, extended);
408 bld.appendDayOfWeek(1);
409 } else {
410
411 reducedPrec = true;
412 }
413 } else {
414 if (fields.remove(DateTimeFieldType.dayOfWeek())) {
415
416 checkNotStrictISO(fields, strictISO);
417 appendSeparator(bld, extended);
418 bld.appendLiteral('W');
419 bld.appendLiteral('-');
420 bld.appendDayOfWeek(1);
421 } else {
422
423 reducedPrec = true;
424 }
425 }
426
427 } else if (fields.remove(DateTimeFieldType.weekOfWeekyear())) {
428 bld.appendLiteral('-');
429 bld.appendLiteral('W');
430 bld.appendWeekOfWeekyear(2);
431 if (fields.remove(DateTimeFieldType.dayOfWeek())) {
432
433 appendSeparator(bld, extended);
434 bld.appendDayOfWeek(1);
435 } else {
436
437 reducedPrec = true;
438 }
439 } else if (fields.remove(DateTimeFieldType.dayOfWeek())) {
440
441 bld.appendLiteral('-');
442 bld.appendLiteral('W');
443 bld.appendLiteral('-');
444 bld.appendDayOfWeek(1);
445 }
446 return reducedPrec;
447 }
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462 private static void time(
463 DateTimeFormatterBuilder bld,
464 Collection<DateTimeFieldType> fields,
465 boolean extended,
466 boolean strictISO,
467 boolean reducedPrec,
468 boolean datePresent) {
469
470 boolean hour = fields.remove(DateTimeFieldType.hourOfDay());
471 boolean minute = fields.remove(DateTimeFieldType.minuteOfHour());
472 boolean second = fields.remove(DateTimeFieldType.secondOfMinute());
473 boolean milli = fields.remove(DateTimeFieldType.millisOfSecond());
474 if (!hour && !minute && !second && !milli) {
475 return;
476 }
477 if (hour || minute || second || milli) {
478 if (strictISO && reducedPrec) {
479 throw new IllegalArgumentException("No valid ISO8601 format for fields because Date was reduced precision: " + fields);
480 }
481 if (datePresent) {
482 bld.appendLiteral('T');
483 }
484 }
485 if (hour && minute && second || (hour && !second && !milli)) {
486
487 } else {
488 if (strictISO && datePresent) {
489 throw new IllegalArgumentException("No valid ISO8601 format for fields because Time was truncated: " + fields);
490 }
491 if (!hour && (minute && second || (minute && !milli) || second)) {
492
493 } else {
494 if (strictISO) {
495 throw new IllegalArgumentException("No valid ISO8601 format for fields: " + fields);
496 }
497 }
498 }
499 if (hour) {
500 bld.appendHourOfDay(2);
501 } else if (minute || second || milli) {
502 bld.appendLiteral('-');
503 }
504 if (extended && hour && minute) {
505 bld.appendLiteral(':');
506 }
507 if (minute) {
508 bld.appendMinuteOfHour(2);
509 } else if (second || milli) {
510 bld.appendLiteral('-');
511 }
512 if (extended && minute && second) {
513 bld.appendLiteral(':');
514 }
515 if (second) {
516 bld.appendSecondOfMinute(2);
517 } else if (milli) {
518 bld.appendLiteral('-');
519 }
520 if (milli) {
521 bld.appendLiteral('.');
522 bld.appendMillisOfSecond(3);
523 }
524 }
525
526
527
528
529
530
531
532
533
534 private static void checkNotStrictISO(Collection<DateTimeFieldType> fields, boolean strictISO) {
535 if (strictISO) {
536 throw new IllegalArgumentException("No valid ISO8601 format for fields: " + fields);
537 }
538 }
539
540
541
542
543
544
545
546
547
548 private static void appendSeparator(DateTimeFormatterBuilder bld, boolean extended) {
549 if (extended) {
550 bld.appendLiteral('-');
551 }
552 }
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568 public static DateTimeFormatter dateParser() {
569 if (dp == null) {
570 DateTimeParser tOffset = new DateTimeFormatterBuilder()
571 .appendLiteral('T')
572 .append(offsetElement()).toParser();
573 dp = new DateTimeFormatterBuilder()
574 .append(dateElementParser())
575 .appendOptional(tOffset)
576 .toFormatter();
577 }
578 return dp;
579 }
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594 public static DateTimeFormatter localDateParser() {
595 if (ldp == null) {
596 ldp = dateElementParser().withZoneUTC();
597 }
598 return ldp;
599 }
600
601
602
603
604
605
606
607
608
609
610
611
612 public static DateTimeFormatter dateElementParser() {
613 if (dpe == null) {
614 dpe = new DateTimeFormatterBuilder()
615 .append(null, new DateTimeParser[] {
616 new DateTimeFormatterBuilder()
617 .append(yearElement())
618 .appendOptional
619 (new DateTimeFormatterBuilder()
620 .append(monthElement())
621 .appendOptional(dayOfMonthElement().getParser())
622 .toParser())
623 .toParser(),
624 new DateTimeFormatterBuilder()
625 .append(weekyearElement())
626 .append(weekElement())
627 .appendOptional(dayOfWeekElement().getParser())
628 .toParser(),
629 new DateTimeFormatterBuilder()
630 .append(yearElement())
631 .append(dayOfYearElement())
632 .toParser()
633 })
634 .toFormatter();
635 }
636 return dpe;
637 }
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653 public static DateTimeFormatter timeParser() {
654 if (tp == null) {
655 tp = new DateTimeFormatterBuilder()
656 .appendOptional(literalTElement().getParser())
657 .append(timeElementParser())
658 .appendOptional(offsetElement().getParser())
659 .toFormatter();
660 }
661 return tp;
662 }
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679 public static DateTimeFormatter localTimeParser() {
680 if (ltp == null) {
681 ltp = new DateTimeFormatterBuilder()
682 .appendOptional(literalTElement().getParser())
683 .append(timeElementParser())
684 .toFormatter().withZoneUTC();
685 }
686 return ltp;
687 }
688
689
690
691
692
693
694
695
696
697
698
699
700
701 public static DateTimeFormatter timeElementParser() {
702 if (tpe == null) {
703
704 DateTimeParser decimalPoint = new DateTimeFormatterBuilder()
705 .append(null, new DateTimeParser[] {
706 new DateTimeFormatterBuilder()
707 .appendLiteral('.')
708 .toParser(),
709 new DateTimeFormatterBuilder()
710 .appendLiteral(',')
711 .toParser()
712 })
713 .toParser();
714
715 tpe = new DateTimeFormatterBuilder()
716
717 .append(hourElement())
718 .append
719 (null, new DateTimeParser[] {
720 new DateTimeFormatterBuilder()
721
722 .append(minuteElement())
723 .append
724 (null, new DateTimeParser[] {
725 new DateTimeFormatterBuilder()
726
727 .append(secondElement())
728
729 .appendOptional(new DateTimeFormatterBuilder()
730 .append(decimalPoint)
731 .appendFractionOfSecond(1, 9)
732 .toParser())
733 .toParser(),
734
735 new DateTimeFormatterBuilder()
736 .append(decimalPoint)
737 .appendFractionOfMinute(1, 9)
738 .toParser(),
739 null
740 })
741 .toParser(),
742
743 new DateTimeFormatterBuilder()
744 .append(decimalPoint)
745 .appendFractionOfHour(1, 9)
746 .toParser(),
747 null
748 })
749 .toFormatter();
750 }
751 return tpe;
752 }
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774 public static DateTimeFormatter dateTimeParser() {
775 if (dtp == null) {
776
777
778 DateTimeParser time = new DateTimeFormatterBuilder()
779 .appendLiteral('T')
780 .append(timeElementParser())
781 .appendOptional(offsetElement().getParser())
782 .toParser();
783 dtp = new DateTimeFormatterBuilder()
784 .append(null, new DateTimeParser[] {time, dateOptionalTimeParser().getParser()})
785 .toFormatter();
786 }
787 return dtp;
788 }
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809 public static DateTimeFormatter dateOptionalTimeParser() {
810 if (dotp == null) {
811 DateTimeParser timeOrOffset = new DateTimeFormatterBuilder()
812 .appendLiteral('T')
813 .appendOptional(timeElementParser().getParser())
814 .appendOptional(offsetElement().getParser())
815 .toParser();
816 dotp = new DateTimeFormatterBuilder()
817 .append(dateElementParser())
818 .appendOptional(timeOrOffset)
819 .toFormatter();
820 }
821 return dotp;
822 }
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844 public static DateTimeFormatter localDateOptionalTimeParser() {
845 if (ldotp == null) {
846 DateTimeParser time = new DateTimeFormatterBuilder()
847 .appendLiteral('T')
848 .append(timeElementParser())
849 .toParser();
850 ldotp = new DateTimeFormatterBuilder()
851 .append(dateElementParser())
852 .appendOptional(time)
853 .toFormatter().withZoneUTC();
854 }
855 return ldotp;
856 }
857
858
859
860
861
862
863
864
865 public static DateTimeFormatter date() {
866 return yearMonthDay();
867 }
868
869
870
871
872
873
874
875
876
877
878 public static DateTimeFormatter time() {
879 if (t == null) {
880 t = new DateTimeFormatterBuilder()
881 .append(hourMinuteSecondFraction())
882 .append(offsetElement())
883 .toFormatter();
884 }
885 return t;
886 }
887
888
889
890
891
892
893
894
895
896 public static DateTimeFormatter timeNoMillis() {
897 if (tx == null) {
898 tx = new DateTimeFormatterBuilder()
899 .append(hourMinuteSecond())
900 .append(offsetElement())
901 .toFormatter();
902 }
903 return tx;
904 }
905
906
907
908
909
910
911
912
913
914
915 public static DateTimeFormatter tTime() {
916 if (tt == null) {
917 tt = new DateTimeFormatterBuilder()
918 .append(literalTElement())
919 .append(time())
920 .toFormatter();
921 }
922 return tt;
923 }
924
925
926
927
928
929
930
931
932
933
934 public static DateTimeFormatter tTimeNoMillis() {
935 if (ttx == null) {
936 ttx = new DateTimeFormatterBuilder()
937 .append(literalTElement())
938 .append(timeNoMillis())
939 .toFormatter();
940 }
941 return ttx;
942 }
943
944
945
946
947
948
949
950
951
952 public static DateTimeFormatter dateTime() {
953 if (dt == null) {
954 dt = new DateTimeFormatterBuilder()
955 .append(date())
956 .append(tTime())
957 .toFormatter();
958 }
959 return dt;
960 }
961
962
963
964
965
966
967
968
969
970 public static DateTimeFormatter dateTimeNoMillis() {
971 if (dtx == null) {
972 dtx = new DateTimeFormatterBuilder()
973 .append(date())
974 .append(tTimeNoMillis())
975 .toFormatter();
976 }
977 return dtx;
978 }
979
980
981
982
983
984
985
986
987 public static DateTimeFormatter ordinalDate() {
988 if (od == null) {
989 od = new DateTimeFormatterBuilder()
990 .append(yearElement())
991 .append(dayOfYearElement())
992 .toFormatter();
993 }
994 return od;
995 }
996
997
998
999
1000
1001
1002
1003
1004
1005
1006 public static DateTimeFormatter ordinalDateTime() {
1007 if (odt == null) {
1008 odt = new DateTimeFormatterBuilder()
1009 .append(ordinalDate())
1010 .append(tTime())
1011 .toFormatter();
1012 }
1013 return odt;
1014 }
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025 public static DateTimeFormatter ordinalDateTimeNoMillis() {
1026 if (odtx == null) {
1027 odtx = new DateTimeFormatterBuilder()
1028 .append(ordinalDate())
1029 .append(tTimeNoMillis())
1030 .toFormatter();
1031 }
1032 return odtx;
1033 }
1034
1035
1036
1037
1038
1039
1040
1041 public static DateTimeFormatter weekDate() {
1042 return weekyearWeekDay();
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053 public static DateTimeFormatter weekDateTime() {
1054 if (wdt == null) {
1055 wdt = new DateTimeFormatterBuilder()
1056 .append(weekDate())
1057 .append(tTime())
1058 .toFormatter();
1059 }
1060 return wdt;
1061 }
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071 public static DateTimeFormatter weekDateTimeNoMillis() {
1072 if (wdtx == null) {
1073 wdtx = new DateTimeFormatterBuilder()
1074 .append(weekDate())
1075 .append(tTimeNoMillis())
1076 .toFormatter();
1077 }
1078 return wdtx;
1079 }
1080
1081
1082
1083
1084
1085
1086
1087
1088 public static DateTimeFormatter basicDate() {
1089 if (bd == null) {
1090 bd = new DateTimeFormatterBuilder()
1091 .appendYear(4, 4)
1092 .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
1093 .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
1094 .toFormatter();
1095 }
1096 return bd;
1097 }
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108 public static DateTimeFormatter basicTime() {
1109 if (bt == null) {
1110 bt = new DateTimeFormatterBuilder()
1111 .appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2)
1112 .appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2)
1113 .appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2)
1114 .appendLiteral('.')
1115 .appendFractionOfSecond(3, 9)
1116 .appendTimeZoneOffset("Z", false, 2, 2)
1117 .toFormatter();
1118 }
1119 return bt;
1120 }
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130 public static DateTimeFormatter basicTimeNoMillis() {
1131 if (btx == null) {
1132 btx = new DateTimeFormatterBuilder()
1133 .appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2)
1134 .appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2)
1135 .appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2)
1136 .appendTimeZoneOffset("Z", false, 2, 2)
1137 .toFormatter();
1138 }
1139 return btx;
1140 }
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151 public static DateTimeFormatter basicTTime() {
1152 if (btt == null) {
1153 btt = new DateTimeFormatterBuilder()
1154 .append(literalTElement())
1155 .append(basicTime())
1156 .toFormatter();
1157 }
1158 return btt;
1159 }
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170 public static DateTimeFormatter basicTTimeNoMillis() {
1171 if (bttx == null) {
1172 bttx = new DateTimeFormatterBuilder()
1173 .append(literalTElement())
1174 .append(basicTimeNoMillis())
1175 .toFormatter();
1176 }
1177 return bttx;
1178 }
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188 public static DateTimeFormatter basicDateTime() {
1189 if (bdt == null) {
1190 bdt = new DateTimeFormatterBuilder()
1191 .append(basicDate())
1192 .append(basicTTime())
1193 .toFormatter();
1194 }
1195 return bdt;
1196 }
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206 public static DateTimeFormatter basicDateTimeNoMillis() {
1207 if (bdtx == null) {
1208 bdtx = new DateTimeFormatterBuilder()
1209 .append(basicDate())
1210 .append(basicTTimeNoMillis())
1211 .toFormatter();
1212 }
1213 return bdtx;
1214 }
1215
1216
1217
1218
1219
1220
1221
1222
1223 public static DateTimeFormatter basicOrdinalDate() {
1224 if (bod == null) {
1225 bod = new DateTimeFormatterBuilder()
1226 .appendYear(4, 4)
1227 .appendFixedDecimal(DateTimeFieldType.dayOfYear(), 3)
1228 .toFormatter();
1229 }
1230 return bod;
1231 }
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242 public static DateTimeFormatter basicOrdinalDateTime() {
1243 if (bodt == null) {
1244 bodt = new DateTimeFormatterBuilder()
1245 .append(basicOrdinalDate())
1246 .append(basicTTime())
1247 .toFormatter();
1248 }
1249 return bodt;
1250 }
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261 public static DateTimeFormatter basicOrdinalDateTimeNoMillis() {
1262 if (bodtx == null) {
1263 bodtx = new DateTimeFormatterBuilder()
1264 .append(basicOrdinalDate())
1265 .append(basicTTimeNoMillis())
1266 .toFormatter();
1267 }
1268 return bodtx;
1269 }
1270
1271
1272
1273
1274
1275
1276
1277 public static DateTimeFormatter basicWeekDate() {
1278 if (bwd == null) {
1279 bwd = new DateTimeFormatterBuilder()
1280 .appendWeekyear(4, 4)
1281 .appendLiteral('W')
1282 .appendFixedDecimal(DateTimeFieldType.weekOfWeekyear(), 2)
1283 .appendFixedDecimal(DateTimeFieldType.dayOfWeek(), 1)
1284 .toFormatter();
1285 }
1286 return bwd;
1287 }
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297 public static DateTimeFormatter basicWeekDateTime() {
1298 if (bwdt == null) {
1299 bwdt = new DateTimeFormatterBuilder()
1300 .append(basicWeekDate())
1301 .append(basicTTime())
1302 .toFormatter();
1303 }
1304 return bwdt;
1305 }
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315 public static DateTimeFormatter basicWeekDateTimeNoMillis() {
1316 if (bwdtx == null) {
1317 bwdtx = new DateTimeFormatterBuilder()
1318 .append(basicWeekDate())
1319 .append(basicTTimeNoMillis())
1320 .toFormatter();
1321 }
1322 return bwdtx;
1323 }
1324
1325
1326
1327
1328
1329
1330
1331 public static DateTimeFormatter year() {
1332 return yearElement();
1333 }
1334
1335
1336
1337
1338
1339
1340
1341 public static DateTimeFormatter yearMonth() {
1342 if (ym == null) {
1343 ym = new DateTimeFormatterBuilder()
1344 .append(yearElement())
1345 .append(monthElement())
1346 .toFormatter();
1347 }
1348 return ym;
1349 }
1350
1351
1352
1353
1354
1355
1356
1357 public static DateTimeFormatter yearMonthDay() {
1358 if (ymd == null) {
1359 ymd = new DateTimeFormatterBuilder()
1360 .append(yearElement())
1361 .append(monthElement())
1362 .append(dayOfMonthElement())
1363 .toFormatter();
1364 }
1365 return ymd;
1366 }
1367
1368
1369
1370
1371
1372
1373 public static DateTimeFormatter weekyear() {
1374 return weekyearElement();
1375 }
1376
1377
1378
1379
1380
1381
1382
1383 public static DateTimeFormatter weekyearWeek() {
1384 if (ww == null) {
1385 ww = new DateTimeFormatterBuilder()
1386 .append(weekyearElement())
1387 .append(weekElement())
1388 .toFormatter();
1389 }
1390 return ww;
1391 }
1392
1393
1394
1395
1396
1397
1398
1399 public static DateTimeFormatter weekyearWeekDay() {
1400 if (wwd == null) {
1401 wwd = new DateTimeFormatterBuilder()
1402 .append(weekyearElement())
1403 .append(weekElement())
1404 .append(dayOfWeekElement())
1405 .toFormatter();
1406 }
1407 return wwd;
1408 }
1409
1410
1411
1412
1413
1414
1415 public static DateTimeFormatter hour() {
1416 return hourElement();
1417 }
1418
1419
1420
1421
1422
1423
1424
1425 public static DateTimeFormatter hourMinute() {
1426 if (hm == null) {
1427 hm = new DateTimeFormatterBuilder()
1428 .append(hourElement())
1429 .append(minuteElement())
1430 .toFormatter();
1431 }
1432 return hm;
1433 }
1434
1435
1436
1437
1438
1439
1440
1441 public static DateTimeFormatter hourMinuteSecond() {
1442 if (hms == null) {
1443 hms = new DateTimeFormatterBuilder()
1444 .append(hourElement())
1445 .append(minuteElement())
1446 .append(secondElement())
1447 .toFormatter();
1448 }
1449 return hms;
1450 }
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460 public static DateTimeFormatter hourMinuteSecondMillis() {
1461 if (hmsl == null) {
1462 hmsl = new DateTimeFormatterBuilder()
1463 .append(hourElement())
1464 .append(minuteElement())
1465 .append(secondElement())
1466 .appendLiteral('.')
1467 .appendFractionOfSecond(3, 3)
1468 .toFormatter();
1469 }
1470 return hmsl;
1471 }
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481 public static DateTimeFormatter hourMinuteSecondFraction() {
1482 if (hmsf == null) {
1483 hmsf = new DateTimeFormatterBuilder()
1484 .append(hourElement())
1485 .append(minuteElement())
1486 .append(secondElement())
1487 .append(fractionElement())
1488 .toFormatter();
1489 }
1490 return hmsf;
1491 }
1492
1493
1494
1495
1496
1497
1498
1499 public static DateTimeFormatter dateHour() {
1500 if (dh == null) {
1501 dh = new DateTimeFormatterBuilder()
1502 .append(date())
1503 .append(literalTElement())
1504 .append(hour())
1505 .toFormatter();
1506 }
1507 return dh;
1508 }
1509
1510
1511
1512
1513
1514
1515
1516 public static DateTimeFormatter dateHourMinute() {
1517 if (dhm == null) {
1518 dhm = new DateTimeFormatterBuilder()
1519 .append(date())
1520 .append(literalTElement())
1521 .append(hourMinute())
1522 .toFormatter();
1523 }
1524 return dhm;
1525 }
1526
1527
1528
1529
1530
1531
1532
1533
1534 public static DateTimeFormatter dateHourMinuteSecond() {
1535 if (dhms == null) {
1536 dhms = new DateTimeFormatterBuilder()
1537 .append(date())
1538 .append(literalTElement())
1539 .append(hourMinuteSecond())
1540 .toFormatter();
1541 }
1542 return dhms;
1543 }
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553 public static DateTimeFormatter dateHourMinuteSecondMillis() {
1554 if (dhmsl == null) {
1555 dhmsl = new DateTimeFormatterBuilder()
1556 .append(date())
1557 .append(literalTElement())
1558 .append(hourMinuteSecondMillis())
1559 .toFormatter();
1560 }
1561 return dhmsl;
1562 }
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572 public static DateTimeFormatter dateHourMinuteSecondFraction() {
1573 if (dhmsf == null) {
1574 dhmsf = new DateTimeFormatterBuilder()
1575 .append(date())
1576 .append(literalTElement())
1577 .append(hourMinuteSecondFraction())
1578 .toFormatter();
1579 }
1580 return dhmsf;
1581 }
1582
1583
1584 private static DateTimeFormatter yearElement() {
1585 if (ye == null) {
1586 ye = new DateTimeFormatterBuilder()
1587 .appendYear(4, 9)
1588 .toFormatter();
1589 }
1590 return ye;
1591 }
1592
1593 private static DateTimeFormatter monthElement() {
1594 if (mye == null) {
1595 mye = new DateTimeFormatterBuilder()
1596 .appendLiteral('-')
1597 .appendMonthOfYear(2)
1598 .toFormatter();
1599 }
1600 return mye;
1601 }
1602
1603 private static DateTimeFormatter dayOfMonthElement() {
1604 if (dme == null) {
1605 dme = new DateTimeFormatterBuilder()
1606 .appendLiteral('-')
1607 .appendDayOfMonth(2)
1608 .toFormatter();
1609 }
1610 return dme;
1611 }
1612
1613 private static DateTimeFormatter weekyearElement() {
1614 if (we == null) {
1615 we = new DateTimeFormatterBuilder()
1616 .appendWeekyear(4, 9)
1617 .toFormatter();
1618 }
1619 return we;
1620 }
1621
1622 private static DateTimeFormatter weekElement() {
1623 if (wwe == null) {
1624 wwe = new DateTimeFormatterBuilder()
1625 .appendLiteral("-W")
1626 .appendWeekOfWeekyear(2)
1627 .toFormatter();
1628 }
1629 return wwe;
1630 }
1631
1632 private static DateTimeFormatter dayOfWeekElement() {
1633 if (dwe == null) {
1634 dwe = new DateTimeFormatterBuilder()
1635 .appendLiteral('-')
1636 .appendDayOfWeek(1)
1637 .toFormatter();
1638 }
1639 return dwe;
1640 }
1641
1642 private static DateTimeFormatter dayOfYearElement() {
1643 if (dye == null) {
1644 dye = new DateTimeFormatterBuilder()
1645 .appendLiteral('-')
1646 .appendDayOfYear(3)
1647 .toFormatter();
1648 }
1649 return dye;
1650 }
1651
1652 private static DateTimeFormatter literalTElement() {
1653 if (lte == null) {
1654 lte = new DateTimeFormatterBuilder()
1655 .appendLiteral('T')
1656 .toFormatter();
1657 }
1658 return lte;
1659 }
1660
1661 private static DateTimeFormatter hourElement() {
1662 if (hde == null) {
1663 hde = new DateTimeFormatterBuilder()
1664 .appendHourOfDay(2)
1665 .toFormatter();
1666 }
1667 return hde;
1668 }
1669
1670 private static DateTimeFormatter minuteElement() {
1671 if (mhe == null) {
1672 mhe = new DateTimeFormatterBuilder()
1673 .appendLiteral(':')
1674 .appendMinuteOfHour(2)
1675 .toFormatter();
1676 }
1677 return mhe;
1678 }
1679
1680 private static DateTimeFormatter secondElement() {
1681 if (sme == null) {
1682 sme = new DateTimeFormatterBuilder()
1683 .appendLiteral(':')
1684 .appendSecondOfMinute(2)
1685 .toFormatter();
1686 }
1687 return sme;
1688 }
1689
1690 private static DateTimeFormatter fractionElement() {
1691 if (fse == null) {
1692 fse = new DateTimeFormatterBuilder()
1693 .appendLiteral('.')
1694
1695
1696 .appendFractionOfSecond(3, 9)
1697 .toFormatter();
1698 }
1699 return fse;
1700 }
1701
1702 private static DateTimeFormatter offsetElement() {
1703 if (ze == null) {
1704 ze = new DateTimeFormatterBuilder()
1705 .appendTimeZoneOffset("Z", true, 2, 4)
1706 .toFormatter();
1707 }
1708 return ze;
1709 }
1710
1711 }