1 /* Work around platform bugs in strftime.
2 Copyright (C) 2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
28 rpl_strftime (char *buf
, size_t bufsize
, const char *format
, const struct tm
*tp
)
30 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
31 /* Rectify the value of the environment variable TZ.
32 There are four possible kinds of such values:
33 - Traditional US time zone names, e.g. "PST8PDT". Syntax: see
34 <https://msdn.microsoft.com/en-us/library/90s5c885.aspx>
35 - Time zone names based on geography, that contain one or more
36 slashes, e.g. "Europe/Moscow".
37 - Time zone names based on geography, without slashes, e.g.
39 - Time zone names that contain explicit DST rules. Syntax: see
40 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03>
41 The Microsoft CRT understands only the first kind. It produces incorrect
42 results if the value of TZ is of the other kinds.
43 But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value
44 of the second kind for most geographies, or of the first kind in a few
45 other geographies. If it is of the second kind, neutralize it. For the
46 Microsoft CRT, an absent or empty TZ means the time zone that the user
47 has set in the Windows Control Panel.
48 If the value of TZ is of the third or fourth kind -- Cygwin programs
49 understand these syntaxes as well --, it does not matter whether we
50 neutralize it or not, since these values occur only when a Cygwin user
51 has set TZ explicitly; this case is 1. rare and 2. under the user's
53 const char *tz
= getenv ("TZ");
54 if (tz
!= NULL
&& strchr (tz
, '/') != NULL
)
58 return strftime (buf
, bufsize
, format
, tp
);