/
formats.xml
1242 lines (1211 loc) · 41.4 KB
/
formats.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="datetime.formats" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Supported Date and Time Formats</title>
<para>
This section describes all the different formats in a BNF-like format, that the
<classname>DateTimeImmutable</classname>, <classname>DateTime</classname>,
<function>date_create_immutable</function>,
<function>date_create</function>, <function>date_parse</function>, and
<function>strtotime</function> parser understands. The formats are grouped
by section. In most cases formats from different sections, separated by
whitespace, comma or dot, can be used in the same date/time string. For each
of the supported formats, one or more examples are given, as well
as a description for the format. Characters in single quotes in
the formats are case-insensitive (<literal>'t'</literal> could
be <literal>t</literal> or <literal>T</literal>), characters in
double quotes are case-sensitive (<literal>"T"</literal> is only
<literal>T</literal>).
</para>
<para>
To format <classname>DateTimeImmutable</classname> and
<classname>DateTime</classname> objects, please refer to the documentation
of the <function>DateTimeInterface::format</function> method.
</para>
<para>
A general set of rules should be taken into account.
</para>
<orderedlist>
<listitem>
<simpara>
The parser, allows for each unit (year, month, day, hour, minute, second)
the full range of values. For a year that's just 4 digits, for a month
that's 0-12, day is 0-31, hour is 0-24, and minute is 0-59.
</simpara>
</listitem>
<listitem>
<simpara>
60 is allowed for seconds, as sometimes date strings with that
leapsecond do show up. But PHP implements Unix time where "60" is not
a valid second number and hence it overflows.
</simpara>
</listitem>
<listitem>
<simpara>
<function>strtotime</function> returns &false; if any number is outside of
the ranges, and <function>DateTimeImmutable::__construct</function> throws
an exception.
</simpara>
</listitem>
<listitem>
<simpara>
If a string contains a date, all time elements are reset to 0.
</simpara>
</listitem>
<listitem>
<simpara>
All less-significant time elements are reset to 0 if any part of a time is
present in the given string.
</simpara>
</listitem>
<listitem>
<simpara>
The parser is dumb, and doesn't do any checks to make it faster (and
more generic).
</simpara>
</listitem>
<listitem>
<simpara>
Besides rules for individual time elements, the parser also understand
more specific <link linkend="datetime.formats.compound">compound
formats</link>, such as parsing Unix timestamps
(<literal>@1690388256</literal>) and ISO Weekdates
(<literal>2008-W28-3</literal>).
</simpara>
</listitem>
<listitem>
<para>
There is an additional check if an invalid date is provided:
<example>
<programlisting role="php">
<![CDATA[
<?php
$res = date_parse("2015-09-31");
var_dump($res["warnings"]);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(1) {
[11] =>
string(27) "The parsed date was invalid"
}
]]>
</screen>
</example>
</para>
</listitem>
<listitem>
<para>
It is already possible to handle the edge cases, but then
<function>DateTimeImmutable::createFromFormat</function> must be used
while supplying the correct format.
<example>
<programlisting role="php">
<![CDATA[
<?php
$res = DateTimeImmutable::createFromFormat("Y-m-d", "2015-09-34");
var_dump($res);
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(DateTimeImmutable)#1 (3) {
["date"]=>
string(26) "2015-10-04 17:24:43.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/London"
}
]]>
</screen>
</example>
</para>
</listitem>
</orderedlist>
<!--Time Formats: {{{-->
<sect1 annotations="chunk:false" xml:id="datetime.formats.time">
<title>Time Formats</title>
<para>
This page describes the different date/time formats in a BNF-like syntax,
that the <classname>DateTimeImmutable</classname>,
<classname>DateTime</classname>, <function>date_create</function>,
<function>date_create_immutable</function>, and
<function>strtotime</function> parser understands.
</para>
<para>
To format <classname>DateTimeImmutable</classname> and
<classname>DateTime</classname> objects, please refer to the documentation
of the <function>DateTimeInterface::format</function> method.
</para>
<table>
<title>Used Symbols</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Formats</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>frac</literal></entry>
<entry>. [0-9]+</entry>
<entry>".21342", ".85"</entry>
</row>
<row>
<entry><literal>hh</literal></entry>
<entry>"0"?[1-9] | "1"[0-2]</entry>
<entry>"04", "7", "12"</entry>
</row>
<row>
<entry><literal>HH</literal></entry>
<entry>[01][0-9] | "2"[0-4]</entry>
<entry>"04", "07", "19"</entry>
</row>
<row>
<entry><literal>meridian</literal></entry>
<entry>[AaPp] .? [Mm] .? [\0\t ]</entry>
<entry>"A.m.", "pM", "am."</entry>
</row>
<row>
<entry><literal>MM</literal></entry>
<entry>[0-5][0-9]</entry>
<entry>"00", "12", "59"</entry>
</row>
<row>
<entry><literal>II</literal></entry>
<entry>[0-5][0-9]</entry>
<entry>"00", "12", "59"</entry>
</row>
<row>
<entry><literal>space</literal></entry>
<entry>[ \t]</entry>
<entry></entry>
</row>
<row>
<entry><literal>tz</literal></entry>
<entry>"("? [A-Za-z]{1,6} ")"? | [A-Z][a-z]+([_/][A-Z][a-z]+)+</entry>
<entry>"CEST", "Europe/Amsterdam", "America/Indiana/Knox"</entry>
</row>
<row>
<entry><literal>tzcorrection</literal></entry>
<entry>"GMT"? [+-] <literal>hh</literal> ":"? <literal>MM</literal>?</entry>
<entry>"+0400", "GMT-07:00", "-07:00"</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>12 Hour Notation</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>Hour only, with meridian</entry>
<entry><literal>hh</literal> <literal>space</literal>? <literal>meridian</literal></entry>
<entry>"4 am", "5PM"</entry>
</row>
<row>
<entry>Hour and minutes, with meridian</entry>
<entry><literal>hh</literal> [.:] <literal>MM</literal> <literal>space</literal>? <literal>meridian</literal></entry>
<entry>"4:08 am", "7:19P.M."</entry>
</row>
<row>
<entry>Hour, minutes and seconds, with meridian</entry>
<entry><literal>hh</literal> [.:] <literal>MM</literal> [.:] <literal>II</literal> <literal>space</literal>? <literal>meridian</literal></entry>
<entry>"4:08:37 am", "7:19:19P.M."</entry>
</row>
<row>
<entry>MS SQL (Hour, minutes, seconds and fraction with meridian)</entry>
<entry><literal>hh</literal> ":" <literal>MM</literal> ":" <literal>II</literal> [.:] [0-9]+ <literal>meridian</literal></entry>
<entry>"4:08:39:12313am"</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>24 Hour Notation</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>Hour and minutes</entry>
<entry>'t'? <literal>HH</literal> [.:] <literal>MM</literal></entry>
<entry>"04:08", "19.19", "T23:43"</entry>
</row>
<row>
<entry>Hour and minutes, no colon</entry>
<entry>'t'? <literal>HH</literal> <literal>MM</literal></entry>
<entry>"0408", "t1919", "T2343"</entry>
</row>
<row>
<entry>Hour, minutes and seconds</entry>
<entry>'t'? <literal>HH</literal> [.:] <literal>MM</literal> [.:] <literal>II</literal></entry>
<entry>"04.08.37", "t19:19:19"</entry>
</row>
<row>
<entry>Hour, minutes and seconds, no colon</entry>
<entry>'t'? <literal>HH</literal> <literal>MM</literal> <literal>II</literal></entry>
<entry>"040837", "T191919"</entry>
</row>
<row>
<entry>Hour, minutes, seconds and timezone</entry>
<entry>'t'? <literal>HH</literal> [.:] <literal>MM</literal> [.:] <literal>II</literal> <literal>space</literal>? ( <literal>tzcorrection</literal> | <literal>tz</literal> )</entry>
<entry>"040837CEST", "T191919-0700"</entry>
</row>
<row>
<entry>Hour, minutes, seconds and fraction</entry>
<entry>'t'? <literal>HH</literal> [.:] <literal>MM</literal> [.:] <literal>II</literal> <literal>frac</literal></entry>
<entry>"04.08.37.81412", "19:19:19.532453"</entry>
</row>
<row>
<entry>Time zone information</entry>
<entry><literal>tz</literal> | <literal>tzcorrection</literal></entry>
<entry>"CEST", "Europe/Amsterdam", "+0430", "GMT-06:00"</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<!--}}}-->
<!--Date Formats: {{{-->
<sect1 annotations="chunk:false" xml:id="datetime.formats.date">
<title>Date Formats</title>
<para>
This page describes the different date formats in a BNF-like syntax, that
the <classname>DateTimeImmutable</classname>,
<classname>DateTime</classname>, <function>date_create</function>,
<function>date_create_immutable</function>, and
<function>strtotime</function> parser understands.
</para>
<para>
To format <classname>DateTimeImmutable</classname> and
<classname>DateTime</classname> objects, please refer to the documentation
of the <function>DateTimeInterface::format</function> method.
</para>
<table>
<title>Used Symbols</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>daysuf</literal></entry>
<entry>"st" | "nd" | "rd" | "th"</entry>
<entry></entry>
</row>
<row>
<entry><literal>dd</literal></entry>
<entry>([0-2]?[0-9] | "3"[01]) <literal>daysuf</literal>?</entry>
<entry>"7th", "22nd", "31"</entry>
</row>
<row>
<entry><literal>DD</literal></entry>
<entry>"0" [0-9] | [1-2][0-9] | "3" [01]</entry>
<entry>"07", "31"</entry>
</row>
<row>
<entry><literal>m</literal></entry>
<entry>'january' | 'february' | 'march' | 'april' | 'may' | 'june' |
'july' | 'august' | 'september' | 'october' | 'november' | 'december' |
'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' |
'sept' | 'oct' | 'nov' | 'dec' | "I" | "II" | "III" | "IV" | "V" | "VI"
| "VII" | "VIII" | "IX" | "X" | "XI" | "XII"</entry>
<entry></entry>
</row>
<row>
<entry><literal>M</literal></entry>
<entry>'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' |
'sep' | 'sept' | 'oct' | 'nov' | 'dec'</entry>
<entry></entry>
</row>
<row>
<entry><literal>mm</literal></entry>
<entry>"0"? [0-9] | "1"[0-2]</entry>
<entry>"0", "04", "7", "12"</entry>
</row>
<row>
<entry><literal>MM</literal></entry>
<entry>"0" [0-9] | "1"[0-2]</entry>
<entry>"00", "04", "07", "12"</entry>
</row>
<row>
<entry><literal>y</literal></entry>
<entry>[0-9]{1,4}</entry>
<entry>"00", "78", "08", "8", "2008"</entry>
</row>
<row>
<entry><literal>yy</literal></entry>
<entry>[0-9]{2}</entry>
<entry>"00", "08", "78"</entry>
</row>
<row>
<entry><literal>YY</literal></entry>
<entry>[0-9]{4}</entry>
<entry>"2000", "2008", "1978"</entry>
</row>
<row>
<entry><literal>YYY</literal></entry>
<entry>[0-9]{5,19}</entry>
<entry>"81412", "20192"</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>Localized Notations</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>American month and day</entry>
<entry><literal>mm</literal> "/" <literal>dd</literal></entry>
<entry>"5/12", "10/27"</entry>
</row>
<row>
<entry>American month, day and year</entry>
<entry><literal>mm</literal> "/" <literal>dd</literal> "/" <literal>y</literal></entry>
<entry>"12/22/78", "1/17/2006", "1/17/6"</entry>
</row>
<row>
<entry>Four digit year, month and day with slashes</entry>
<entry><literal>YY</literal> "/" <literal>mm</literal> "/" <literal>dd</literal></entry>
<entry>"2008/6/30", "1978/12/22"</entry>
</row>
<row>
<entry>Four digit year and month (GNU)</entry>
<entry><literal>YY</literal> "-" <literal>mm</literal></entry>
<entry>"2008-6", "2008-06", "1978-12"</entry>
</row>
<row>
<entry>Year, month and day with dashes</entry>
<entry><literal>y</literal> "-" <literal>mm</literal> "-" <literal>dd</literal></entry>
<entry>"2008-6-30", "78-12-22", "8-6-21"</entry>
</row>
<row>
<entry>Day, month and four digit year, with dots, tabs or dashes</entry>
<entry><literal>dd</literal> [.\t-] <literal>mm</literal> [.-] <literal>YY</literal></entry>
<entry>"30-6-2008", "22.12.1978"</entry>
</row>
<row>
<entry>Day, month and two digit year, with dots or tabs</entry>
<entry><literal>dd</literal> [.\t] <literal>mm</literal> "." <literal>yy</literal></entry>
<entry>"30.6.08", "22\t12.78"</entry>
</row>
<row>
<entry>Day, textual month and year</entry>
<entry><literal>dd</literal> ([ \t.-])* <literal>m</literal> ([ \t.-])* <literal>y</literal></entry>
<entry>"30-June 2008", "22DEC78", "14 III 1879"</entry>
</row>
<row>
<entry>Textual month and four digit year (Day reset to 1)</entry>
<entry><literal>m</literal> ([ \t.-])* <literal>YY</literal></entry>
<entry>"June 2008", "DEC1978", "March 1879"</entry>
</row>
<row>
<entry>Four digit year and textual month (Day reset to 1)</entry>
<entry><literal>YY</literal> ([ \t.-])* <literal>m</literal></entry>
<entry>"2008 June", "1978-XII", "1879.MArCH"</entry>
</row>
<row>
<entry>Textual month, day and year</entry>
<entry><literal>m</literal> ([ .\t-])* <literal>dd</literal> [,.stndrh\t ]+ <literal>y</literal></entry>
<entry>"July 1st, 2008", "April 17, 1790", "May.9,78"</entry>
</row>
<row>
<entry>Textual month and day</entry>
<entry><literal>m</literal> ([ .\t-])* <literal>dd</literal> [,.stndrh\t ]*</entry>
<entry>"July 1st,", "Apr 17", "May.9"</entry>
</row>
<row>
<entry>Day and textual month</entry>
<entry><literal>dd</literal> ([ .\t-])* <literal>m</literal></entry>
<entry>"1 July", "17 Apr", "9.May"</entry>
</row>
<row>
<entry>Month abbreviation, day and year</entry>
<entry><literal>M</literal> "-" <literal>DD</literal> "-" <literal>y</literal></entry>
<entry>"May-09-78", "Apr-17-1790"</entry>
</row>
<row>
<entry>Year, month abbreviation and day</entry>
<entry><literal>y</literal> "-" <literal>M</literal> "-" <literal>DD</literal></entry>
<entry>"78-Dec-22", "1814-MAY-17"</entry>
</row>
<row>
<entry>Year (and just the year)</entry>
<entry><literal>YY</literal></entry>
<entry>"1978", "2008"</entry>
</row>
<row>
<entry>Year (expanded, 5-19 digits with sign)</entry>
<entry>[+-] <literal>YYY</literal></entry>
<entry>"-81120", "+20192"</entry>
</row>
<row>
<entry>Textual month (and just the month)</entry>
<entry><literal>m</literal></entry>
<entry>"March", "jun", "DEC"</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>ISO8601 Notations</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>Eight digit year, month and day</entry>
<entry><literal>YY</literal> <literal>MM</literal> <literal>DD</literal></entry>
<entry>"15810726", "19780417", "18140517"</entry>
</row>
<row>
<entry>Four digit year, month and day with slashes</entry>
<entry><literal>YY</literal> "/" <literal>MM</literal> "/" <literal>DD</literal></entry>
<entry>"2008/06/30", "1978/12/22"</entry>
</row>
<row>
<entry>Two digit year, month and day with dashes</entry>
<entry><literal>yy</literal> "-" <literal>MM</literal> "-" <literal>DD</literal></entry>
<entry>"08-06-30", "78-12-22"</entry>
</row>
<row>
<entry>Four digit year with optional sign, month and day</entry>
<entry>[+-]? <literal>YY</literal> "-" <literal>MM</literal> "-" <literal>DD</literal></entry>
<entry>"-0002-07-26", "+1978-04-17", "1814-05-17"</entry>
</row>
<row>
<entry>Five+ digit year with required sign, month and day</entry>
<entry>[+-] <literal>YYY</literal> "-" <literal>MM</literal> "-" <literal>DD</literal></entry>
<entry>"-81120-02-26", "+20192-04-17"</entry>
</row>
</tbody>
</tgroup>
</table>
<note>
<para>
For the <literal>y</literal> and <literal>yy</literal>
formats, years below 100 are handled in a special way when the
<literal>y</literal> or <literal>yy</literal> symbol is used.
If the year falls in the range 0 (inclusive) to 69 (inclusive),
2000 is added. If the year falls in the range 70 (inclusive) to
99 (inclusive) then 1900 is added. This means that "00-01-01" is
interpreted as "2000-01-01".
</para>
</note>
<note>
<para>
The "Day, month and two digit year, with dots or tabs" format
(<literal>dd</literal> [.\t] <literal>mm</literal> "."
<literal>yy</literal>) only works for the year values 61 (inclusive)
to 99 (inclusive) - outside those years the <emphasis>time
format</emphasis> "<literal>HH</literal> [.:] <literal>MM</literal>
[.:] <literal>SS</literal>" has precedence.
</para>
</note>
<note>
<para>
The "Year (and just the year)" format only works if a time string
has already been found -- otherwise this format is recognised as
<literal>HH</literal> <literal>MM</literal>.
</para>
</note>
<caution>
<para>
It is possible to over- and underflow the <literal>dd</literal> and
<literal>DD</literal> format. Day 0 means the last day of previous
month, whereas overflows count into the next month. This makes
"2008-08-00" equivalent to "2008-07-31" and "2008-06-31" equivalent
to "2008-07-01" (June only has 30 days).
</para>
<para>
Note that the day range is restricted to 0-31 as indicated
by the regular expression above. Thus "2008-06-32" is not a valid date
string, for instance.
</para>
<para>
It is also possible to underflow the <literal>mm</literal> and
<literal>MM</literal> formats with the value 0. A month value of
0 means December of the previous year. As example "2008-00-22" is
equivalent to "2007-12-22".
</para>
<para>
If you combine the previous two facts and underflow both the day and
the month, the following happens: "2008-00-00" first gets converted
to "2007-12-00" which then gets converted to "2007-11-30". This also
happens with the string "0000-00-00", which gets transformed into
"-0001-11-30" (the year -1 in the ISO 8601 calendar, which is 2 BC
in the proleptic Gregorian calendar).
</para>
</caution>
</sect1>
<!--}}}-->
<!--Compound Formats: {{{-->
<sect1 annotations="chunk:false" xml:id="datetime.formats.compound">
<title>Compound Formats</title>
<para>
This page describes the different compound date/time formats in a BNF-like
syntax, that the <classname>DateTimeImmutable</classname>,
<classname>DateTime</classname>, <function>date_create</function>,
<function>date_create_immutable</function>, and
<function>strtotime</function> parser understands.
</para>
<para>
To format <classname>DateTimeImmutable</classname> and
<classname>DateTime</classname> objects, please refer to the documentation
of the <function>DateTimeInterface::format</function> method.
</para>
<table>
<title>Used Symbols</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Formats</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>DD</literal></entry>
<entry>"0" [0-9] | [1-2][0-9] | "3" [01]</entry>
<entry>"02", "12", "31"</entry>
</row>
<row>
<entry><literal>doy</literal></entry>
<entry>"00"[1-9] | "0"[1-9][0-9] | [1-2][0-9][0-9] | "3"[0-5][0-9] | "36"[0-6]</entry>
<entry>"001", "012", "180", "350", "366"</entry>
</row>
<row>
<entry><literal>frac</literal></entry>
<entry>. [0-9]+</entry>
<entry>".21342", ".85"</entry>
</row>
<row>
<entry><literal>hh</literal></entry>
<entry>"0"?[1-9] | "1"[0-2]</entry>
<entry>"04", "7", "12"</entry>
</row>
<row>
<entry><literal>HH</literal></entry>
<entry>[01][0-9] | "2"[0-4]</entry>
<entry>"04", "07", "19"</entry>
</row>
<row>
<entry><literal>meridian</literal></entry>
<entry>[AaPp] .? [Mm] .? [\0\t ]</entry>
<entry>"A.m.", "pM", "am."</entry>
</row>
<row>
<entry><literal>ii</literal></entry>
<entry>[0-5]?[0-9]</entry>
<entry>"04", "8", "59"</entry>
</row>
<row>
<entry><literal>II</literal></entry>
<entry>[0-5][0-9]</entry>
<entry>"04", "08", "59"</entry>
</row>
<row>
<entry><literal>M</literal></entry>
<entry>'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'sept' | 'oct' | 'nov' | 'dec'</entry>
<entry></entry>
</row>
<row>
<entry><literal>MM</literal></entry>
<entry>[0-1][0-9]</entry>
<entry>"00", "12"</entry>
</row>
<row>
<entry><literal>space</literal></entry>
<entry>[ \t]</entry>
<entry></entry>
</row>
<row>
<entry><literal>ss</literal></entry>
<entry>([0-5]?[0-9])|60</entry>
<entry>"04", "8", "59", "60" (leap second)</entry>
</row>
<row>
<entry><literal>SS</literal></entry>
<entry>[0-5][0-9]</entry>
<entry>"04", "08", "59"</entry>
</row>
<row>
<entry><literal>W</literal></entry>
<entry>"0"[1-9] | [1-4][0-9] | "5"[0-3]</entry>
<entry>"05", "17", "53"</entry>
</row>
<row>
<entry><literal>tzcorrection</literal></entry>
<entry>"GMT"? [+-] <literal>hh</literal> ":"? <literal>II</literal>?</entry>
<entry>"+0400", "GMT-07:00", "-07:00"</entry>
</row>
<row>
<entry><literal>YY</literal></entry>
<entry>[0-9]{4}</entry>
<entry>"2000", "2008", "1978"</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>Standards Formats</title>
<tgroup cols="2">
<thead>
<row>
<entry>Description</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>ATOM</entry>
<entry>"2022-06-02T16:58:35+00:00"</entry>
</row>
<row>
<entry>COOKIE</entry>
<entry>"Thursday, 02-Jun-2022 16:58:35 UTC"</entry>
</row>
<row>
<entry>ISO8601</entry>
<entry>"2022-06-02T16:58:35+0000"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;822">RFC 822</link></entry>
<entry>"Thu, 02 Jun 22 16:58:35 +0000"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;850">RFC 850</link></entry>
<entry>"Thursday, 02-Jun-22 16:58:35 UTC"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;1036">RFC 1036</link></entry>
<entry>"Thu, 02 Jun 22 16:58:35 +0000"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;1123">RFC 1123</link></entry>
<entry>"Thu, 02 Jun 2022 16:58:35 +0000"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;2822">RFC 2822</link></entry>
<entry>"Thu, 02 Jun 2022 16:58:35 +0000"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;3339">RFC 3339</link></entry>
<entry>"2022-06-02T16:58:35+00:00"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;3339">RFC 3339</link> Extended</entry>
<entry>"2022-06-02T16:58:35.698+00:00"</entry>
</row>
<row>
<entry><link xlink:href="&url.rfc;7231">RFC 7231</link></entry>
<entry>"Thu, 02 Jun 2022 16:58:35 GMT"</entry>
</row>
<row>
<entry>RSS</entry>
<entry>"Thu, 02 Jun 2022 16:58:35 +0000"</entry>
</row>
<row>
<entry>W3C</entry>
<entry>"2022-06-02T16:58:35+00:00"</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>Localized Notations</title>
<tgroup cols="3">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>Common Log Format</entry>
<entry><literal>dd</literal> "/" <literal>M</literal> "/" <literal>YY</literal> : <literal>HH</literal> ":" <literal>II</literal> ":" <literal>SS</literal> <literal>space</literal> <literal>tzcorrection</literal></entry>
<entry>"10/Oct/2000:13:55:36 -0700"</entry>
</row>
<row>
<entry>EXIF</entry>
<entry><literal>YY</literal> ":" <literal>MM</literal> ":" <literal>DD</literal> " " <literal>HH</literal> ":" <literal>II</literal> ":" <literal>SS</literal></entry>
<entry>"2008:08:07 18:11:31"</entry>
</row>
<row>
<entry>ISO year with ISO week</entry>
<entry><literal>YY</literal> "-"? "W" <literal>W</literal></entry>
<entry>"2008W27", "2008-W28"</entry>
</row>
<row>
<entry>ISO year with ISO week and day</entry>
<entry><literal>YY</literal> "-"? "W" <literal>W</literal> "-"? [0-7]</entry>
<entry>"2008W273", "2008-W28-3"</entry>
</row>
<row>
<entry>MySQL</entry>
<entry><literal>YY</literal> "-" <literal>MM</literal> "-" <literal>DD</literal> " " <literal>HH</literal> ":" <literal>II</literal> ":" <literal>SS</literal></entry>
<entry>"2008-08-07 18:11:31"</entry>
</row>
<row>
<entry>PostgreSQL: Year with day-of-year</entry>
<entry><literal>YY</literal> "."? <literal>doy</literal></entry>
<entry>"2008.197", "2008197"</entry>
</row>
<row>
<entry>SOAP</entry>
<entry><literal>YY</literal> "-" <literal>MM</literal> "-" <literal>DD</literal> "T" <literal>HH</literal> ":" <literal>II</literal> ":" <literal>SS</literal> <literal>frac</literal> <literal>tzcorrection</literal>?</entry>
<entry>"2008-07-01T22:35:17.02", "2008-07-01T22:35:17.03+08:00"</entry>
</row>
<row>
<entry>Unix Timestamp</entry>
<entry>"@" "-"? [0-9]+</entry>
<entry>"@1215282385"</entry>
</row>
<row>
<entry>Unix Timestamp with microseconds</entry>
<entry>"@" "-"? [0-9]+ "." [0-9]{0,6}</entry>
<entry>"@1607974647.503686"</entry>
</row>
<row>
<entry>XMLRPC</entry>
<entry><literal>YY</literal> <literal>MM</literal> <literal>DD</literal> "T" <literal>hh</literal> ":" <literal>II</literal> ":" <literal>SS</literal></entry>
<entry>"20080701T22:38:07", "20080701T9:38:07"</entry>
</row>
<row>
<entry>XMLRPC (Compact)</entry>
<entry><literal>YY</literal> <literal>MM</literal> <literal>DD</literal> 't' <literal>hh</literal> <literal>II</literal> <literal>SS</literal></entry>
<entry>"20080701t223807", "20080701T093807"</entry>
</row>
<row>
<entry>WDDX</entry>
<entry><literal>YY</literal> "-" <literal>mm</literal> "-" <literal>dd</literal> "T" <literal>hh</literal> ":" <literal>ii</literal> ":" <literal>ss</literal></entry>
<entry>"2008-7-1T9:3:37"</entry>
</row>
</tbody>
</tgroup>
</table>
<note>
<para>
The "W" in the "ISO year with ISO week" and "ISO year with ISO week
and day" formats is case-sensitive, you can only use the upper case
"W".
</para>
<para>
The "T" in the SOAP, XMLRPC and WDDX formats is case-sensitive, you
can only use the upper case "T".
</para>
<para>
The "Unix Timestamp" format sets the timezone to UTC.
</para>
</note>
</sect1>
<!--}}}-->
<!--Relative Formats: {{{-->
<sect1 annotations="chunk:false" xml:id="datetime.formats.relative">
<title>Relative Formats</title>
<para>
This page describes the different relative date/time formats in a BNF-like
syntax, that the <classname>DateTimeImmutable</classname>,
<classname>DateTime</classname>, <function>date_create</function>,
<function>date_create_immutable</function>, and
<function>strtotime</function> parser understands.
</para>
<para>
To format <classname>DateTimeImmutable</classname> and
<classname>DateTime</classname> objects, please refer to the documentation
of the <function>DateTimeInterface::format</function> method.
</para>
<table>
<title>Used Symbols</title>
<tgroup cols="2">
<thead>
<row>
<entry>Description</entry>
<entry>Format</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>dayname</literal></entry>
<entry>'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' |
'friday' | 'saturday' | 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' |
'sat'</entry>
</row>
<row>
<entry><literal>daytext</literal></entry>
<entry>'weekday' | 'weekdays'</entry>
</row>
<row>
<entry><literal>number</literal></entry>
<entry>[+-]?[0-9]+</entry>
</row>
<row>
<entry><literal>ordinal</literal></entry>
<entry>'first' | 'second' | 'third' | 'fourth' | 'fifth' | 'sixth' |
'seventh' | 'eighth' | 'ninth' | 'tenth' | 'eleventh' | 'twelfth' |
'next' | 'last' | 'previous' | 'this'</entry>
</row>
<row>
<entry><literal>reltext</literal></entry>
<entry>'next' | 'last' | 'previous' | 'this'</entry>
</row>
<row>
<entry><literal>space</literal></entry>
<entry>[ \t]+</entry>
</row>
<row>
<entry><literal>unit</literal></entry>
<entry>'ms' | 'µs' | (( 'msec' | 'millisecond' | 'µsec' | 'microsecond'
| 'usec' | 'sec' | 'second' | 'min' | 'minute' | 'hour' | 'day' |
'fortnight' | 'forthnight' | 'month' | 'year') 's'?) | 'weeks' |
<literal>daytext</literal></entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>Day-based Notations</title>
<tgroup cols="3">
<thead>
<row>
<entry>Format</entry>
<entry>Description</entry>
<entry>Examples</entry>
</row>
</thead>
<tbody>
<row>
<entry>'yesterday'</entry>
<entry>Midnight of yesterday</entry>
<entry>"yesterday 14:00"</entry>
</row>
<row>
<entry>'midnight'</entry>
<entry>The time is set to 00:00:00</entry>
<entry></entry>
</row>
<row>
<entry>'today'</entry>
<entry>The time is set to 00:00:00</entry>
<entry></entry>
</row>
<row>
<entry>'now'</entry>
<entry>Now - this is simply ignored</entry>
<entry></entry>
</row>
<row>
<entry>'noon'</entry>
<entry>The time is set to 12:00:00</entry>
<entry>"yesterday noon"</entry>
</row>
<row>
<entry>'tomorrow'</entry>
<entry>Midnight of tomorrow</entry>
<entry></entry>
</row>
<row>
<entry>'back of' <literal>hour</literal></entry>
<entry>15 minutes past the specified hour</entry>
<entry>"back of 7pm", "back of 15"</entry>
</row>
<row>
<entry>'front of' <literal>hour</literal></entry>
<entry>15 minutes before the specified hour</entry>
<entry>"front of 5am", "front of 23"</entry>
</row>
<row>
<entry>'first day of'</entry>
<entry>Sets the day of the first of the current month. This phrase is
usually best used together with a month name following it as it only
effects the current month</entry>
<entry>"first day of January 2008"</entry>
</row>
<row>
<entry>'last day of'</entry>
<entry>Sets the day to the last day of the current month. This phrase is
usually best used together with a month name following it as it only
effects the current month</entry>
<entry>"last day of next month"</entry>
</row>
<row>
<entry><literal>ordinal</literal> <literal>space</literal> <literal>dayname</literal> <literal>space</literal> 'of'</entry>
<entry>Calculates the <literal>x</literal>-th week day of the current month.</entry>
<entry>"first sat of July 2008"</entry>
</row>