Mercurial > gnulib
annotate lib/localtime.c @ 40186:8964917f9574
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 18 Feb 2019 08:02:49 -0800 |
parents | b06060465f09 |
children | 5a52ef2d4772 |
rev | line source |
---|---|
18837 | 1 /* Work around platform bugs in localtime. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19595
diff
changeset
|
2 Copyright (C) 2017-2019 Free Software Foundation, Inc. |
18837 | 3 |
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. | |
8 | |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
18837 | 16 |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include <time.h> | |
21 | |
18846
661c3fb8962f
New module 'localtime-buffer', split off from module 'gettimeofday'.
Bruno Haible <bruno@clisp.org>
parents:
18837
diff
changeset
|
22 /* Keep consistent with localtime-buffer.c! */ |
18837 | 23 #if !(GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME) |
24 | |
25 # include <stdlib.h> | |
26 # include <string.h> | |
27 | |
28 # undef localtime | |
29 | |
30 struct tm * | |
31 rpl_localtime (const time_t *tp) | |
32 { | |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
33 # if defined _WIN32 && ! defined __CYGWIN__ |
18875
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
34 /* Rectify the value of the environment variable TZ. |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
35 There are four possible kinds of such values: |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
36 - Traditional US time zone names, e.g. "PST8PDT". Syntax: see |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
37 <https://msdn.microsoft.com/en-us/library/90s5c885.aspx> |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
38 - Time zone names based on geography, that contain one or more |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
39 slashes, e.g. "Europe/Moscow". |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
40 - Time zone names based on geography, without slashes, e.g. |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
41 "Singapore". |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
42 - Time zone names that contain explicit DST rules. Syntax: see |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
43 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03> |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
44 The Microsoft CRT understands only the first kind. It produces incorrect |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
45 results if the value of TZ is of the other kinds. |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
46 But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
47 of the second kind for most geographies, or of the first kind in a few |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
48 other geographies. If it is of the second kind, neutralize it. For the |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
49 Microsoft CRT, an absent or empty TZ means the time zone that the user |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
50 has set in the Windows Control Panel. |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
51 If the value of TZ is of the third or fourth kind -- Cygwin programs |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
52 understand these syntaxes as well --, it does not matter whether we |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
53 neutralize it or not, since these values occur only when a Cygwin user |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
54 has set TZ explicitly; this case is 1. rare and 2. under the user's |
affde4311db7
tzset: Expand comment about TZ problem on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18846
diff
changeset
|
55 responsibility. */ |
18837 | 56 const char *tz = getenv ("TZ"); |
57 if (tz != NULL && strchr (tz, '/') != NULL) | |
58 _putenv ("TZ="); | |
59 # endif | |
60 | |
61 return localtime (tp); | |
62 } | |
63 | |
64 #endif |