- Notifications
You must be signed in to change notification settings - Fork587
Commit4c99243
committed
Fix POSIX::strftime()
This fixes GH#22351The new sv_strftime_ints() API function acts consistently with regardsto daylight savings time, with POSIX-mandated behavior, which takes thecurrent locale into account.POSIX::strftime() is problematic in regard to this. This commit adds abackwards compatibility mode to preserve its behavior that inadvertentlywas changed by86a9c18.These functions are intended to wrap libc strftime(), includingnormalizing the input values. For example, if you pass 63 seconds as avalue, they will typically change that to be 3 seconds into the nextminute up. In C, the mktime() function is typically called first to dothat normalization. (I don't know what happens if plain strftime() iscalled with unnormalized values.). mktime() looks at the currentlocale, determines if daylight savings time is in effect, and adjustsaccordingly. Perl calls its own mktime-equivalent for you, eliminatingthe need for explicitly calling something that would need to always becalled anyway, hence saving an extra step.mini_mktime() is the Perl mktime-equivalent. It is unaffected bylocales, and does not consider the possibility of there being daylightsavings time. The problem is that libc strftime() is affected bylocale, and does consider dst. Perl uses these two functions together,and this inconsistency between them is bound to cause problems.The 'isdst' parameter to POSIX::strftime() is used to indicate ifdaylight savings is in effect for the time and date given by the otherparameters. If perl used mktime() to normalize those values, it wouldcalculate this for itself, using the passed-in value only as a hint.But since it uses mini_mktime(), it has to take that value as-is.Thus, daylight savings alone, out of all the input values, is notnormalized. This is contrary to the documentation, and I didn't knowthis when I wrote the blamed commit.It turns out that typical uses of this function, like POSIX::strftime('%s', localtime) POSIX::strftime('%s', gmtime)cause the correct 'isdst' to be passed. But this is a defect in theinterface that can bite you; changing it would cause cpan breakage.I wrote the API function sv_strftime_ints() to not have these issues.And, to workaround a defect in the POSIX definition of mktime(). Itturns out you can't tell it you don't want to adjust for dayight time,except by changing the locale to one that doesn't have dst, such as the"C" locale. But this isn't a Perl-level function.1 parentf3d3dcc commit4c99243
4 files changed
+54
-17
lines changedLines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3588 | 3588 |
| |
3589 | 3589 |
| |
3590 | 3590 |
| |
3591 |
| - | |
| 3591 | + | |
3592 | 3592 |
| |
3593 | 3593 |
| |
3594 | 3594 |
| |
| |||
3603 | 3603 |
| |
3604 | 3604 |
| |
3605 | 3605 |
| |
3606 |
| - | |
3607 | 3606 |
| |
3608 |
| - | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
3609 | 3611 |
| |
3610 | 3612 |
| |
3611 | 3613 |
| |
|
Lines changed: 10 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1872 | 1872 |
| |
1873 | 1873 |
| |
1874 | 1874 |
| |
1875 |
| - | |
| 1875 | + | |
1876 | 1876 |
| |
1877 | 1877 |
| |
1878 | 1878 |
| |
1879 | 1879 |
| |
1880 | 1880 |
| |
1881 | 1881 |
| |
1882 | 1882 |
| |
1883 |
| - | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
1884 | 1888 |
| |
1885 | 1889 |
| |
1886 | 1890 |
| |
| |||
1895 | 1899 |
| |
1896 | 1900 |
| |
1897 | 1901 |
| |
1898 |
| - | |
1899 |
| - | |
1900 |
| - | |
1901 |
| - | |
1902 |
| - | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
1903 | 1906 |
| |
1904 | 1907 |
| |
1905 | 1908 |
| |
|
Lines changed: 10 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
9 | 9 |
| |
10 | 10 |
| |
11 | 11 |
| |
12 |
| - | |
| 12 | + | |
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
| |||
205 | 205 |
| |
206 | 206 |
| |
207 | 207 |
| |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + |
Lines changed: 29 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8095 | 8095 |
| |
8096 | 8096 |
| |
8097 | 8097 |
| |
8098 |
| - | |
8099 |
| - | |
8100 |
| - | |
8101 |
| - | |
8102 |
| - | |
| 8098 | + | |
| 8099 | + | |
| 8100 | + | |
| 8101 | + | |
| 8102 | + | |
| 8103 | + | |
| 8104 | + | |
| 8105 | + | |
| 8106 | + | |
| 8107 | + | |
| 8108 | + | |
| 8109 | + | |
| 8110 | + | |
| 8111 | + | |
| 8112 | + | |
| 8113 | + | |
| 8114 | + | |
| 8115 | + | |
| 8116 | + | |
| 8117 | + | |
| 8118 | + | |
8103 | 8119 |
| |
8104 | 8120 |
| |
8105 | 8121 |
| |
| |||
8166 | 8182 |
| |
8167 | 8183 |
| |
8168 | 8184 |
| |
| 8185 | + | |
| 8186 | + | |
| 8187 | + | |
| 8188 | + | |
| 8189 | + | |
8169 | 8190 |
| |
8170 |
| - | |
| 8191 | + | |
| 8192 | + | |
| 8193 | + | |
8171 | 8194 |
| |
8172 | 8195 |
| |
8173 | 8196 |
| |
|
0 commit comments
Comments
(0)