Commit 31aa950
authored
Auto-append pipe modifier in createFromFormat for deterministic behavior (#504)
Unlike PHP's native DateTimeImmutable::createFromFormat(), this method
now automatically appends the | modifier if no reset modifier (| or \!)
is present. This ensures that unparsed components are reset to zero
instead of being filled from the current time.
This provides more predictable and deterministic behavior, especially
useful for testing where flaky tests can occur due to missing components
being filled with the current system time.
Examples:
- createFromFormat('Y-m-d', '2024-03-14') -> time is 00:00:00 (not current)
- createFromFormat('Y-m-d H:i', '2024-03-14 12:30') -> seconds is 00
This is a behavior change from PHP's native method, but arguably the
more intuitive default.1 parent 59f2c99 commit 31aa950
File tree
2 files changed
+70
-3
lines changed- src
- tests/TestCase/DateTime
2 files changed
+70
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
674 | 680 | | |
675 | 681 | | |
676 | 682 | | |
| |||
682 | 688 | | |
683 | 689 | | |
684 | 690 | | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
685 | 697 | | |
686 | 698 | | |
687 | 699 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 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 | + | |
32 | 75 | | |
33 | 76 | | |
34 | 77 | | |
| |||
49 | 92 | | |
50 | 93 | | |
51 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
52 | 107 | | |
53 | 108 | | |
54 | 109 | | |
| |||
65 | 120 | | |
66 | 121 | | |
67 | 122 | | |
68 | | - | |
| 123 | + | |
69 | 124 | | |
70 | | - | |
71 | | - | |
| 125 | + | |
| 126 | + | |
72 | 127 | | |
73 | 128 | | |
0 commit comments