aboutsummaryrefslogtreecommitdiff
path: root/src/timezone/strftime.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-03-28 15:10:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-03-28 15:10:17 -0400
commit1c1a7cbd6a1600c97dfcd9b5dc78a23b5db9bbf6 (patch)
tree83a3722b946a8610306512bcfb2ccc77be745e84 /src/timezone/strftime.c
parente5a4dea80f2506a7a565508e48aaa52296ff410a (diff)
downloadpostgresql-1c1a7cbd6a1600c97dfcd9b5dc78a23b5db9bbf6.tar.gz
postgresql-1c1a7cbd6a1600c97dfcd9b5dc78a23b5db9bbf6.zip
Sync our copy of the timezone library with IANA release tzcode2016c.
We hadn't done this in about six years, which proves to have been a mistake because there's been a lot of code churn upstream, making the merge rather painful. But putting it off any further isn't going to lessen the pain, and there are at least two incompatible changes that we need to absorb before someone starts complaining that --with-system-tzdata doesn't work at all on their platform, or we get blindsided by a tzdata release that our out-of-date zic can't compile. Last week's "time zone abbreviation differs from POSIX standard" mess was a wake-up call in that regard. This is a sufficiently large patch that I'm afraid to back-patch it immediately, though the foregoing considerations imply that we probably should do so eventually. For the moment, just put it in HEAD so that it can get some testing. Maybe we can wait till the end of the 9.6 beta cycle before deeming it okay.
Diffstat (limited to 'src/timezone/strftime.c')
-rw-r--r--src/timezone/strftime.c84
1 files changed, 54 insertions, 30 deletions
diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c
index bdc8dd32408..56306193213 100644
--- a/src/timezone/strftime.c
+++ b/src/timezone/strftime.c
@@ -1,18 +1,38 @@
+/* Convert a broken-down time stamp to a string. */
+
/*
- * Copyright (c) 1989 The Regents of the University of California.
+ * Copyright 1989 The Regents of the University of California.
* All rights reserved.
*
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Based on the UCB version with the copyright notice appearing above.
+ *
+ * This is ANSIish only when "multibyte character == plain character".
*
* IDENTIFICATION
* src/timezone/strftime.c
@@ -92,8 +112,7 @@ static char *_add(const char *, char *, const char *);
static char *_conv(int, const char *, char *, const char *);
static char *_fmt(const char *, const struct pg_tm *, char *,
const char *, int *);
-static char *_yconv(const int, const int, const int, const int,
- char *, const char *const);
+static char *_yconv(int, int, bool, bool, char *, const char *);
#define IN_NONE 0
#define IN_SOME 1
@@ -162,8 +181,8 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
* ...whereas now POSIX 1003.2 calls for something
* completely different. (ado, 1993-05-24)
*/
- pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
- pt, ptlim);
+ pt = _yconv(t->tm_year, TM_YEAR_BASE,
+ true, false, pt, ptlim);
continue;
case 'c':
{
@@ -224,7 +243,7 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
case 'K':
/*
- * * After all this time, still unclaimed!
+ * After all this time, still unclaimed!
*/
pt = _add("kitchen sink", pt, ptlim);
continue;
@@ -296,7 +315,7 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
* (01-53)."
* (ado, 1993-05-24)
*
- * From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
+ * From <http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html> by Markus Kuhn:
* "Week 01 of a year is per definition the first week which has the
* Thursday in this year, which is equivalent to the week which contains
* the fourth day of January. In other words, the first week of a new year
@@ -367,11 +386,13 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
else if (*format == 'g')
{
*warnp = IN_ALL;
- pt = _yconv(year, base, 0, 1,
+ pt = _yconv(year, base,
+ false, true,
pt, ptlim);
}
else
- pt = _yconv(year, base, 1, 1,
+ pt = _yconv(year, base,
+ true, true,
pt, ptlim);
}
continue;
@@ -409,11 +430,13 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
continue;
case 'y':
*warnp = IN_ALL;
- pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
+ pt = _yconv(t->tm_year, TM_YEAR_BASE,
+ false, true,
pt, ptlim);
continue;
case 'Y':
- pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
+ pt = _yconv(t->tm_year, TM_YEAR_BASE,
+ true, true,
pt, ptlim);
continue;
case 'Z':
@@ -427,7 +450,7 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
continue;
case 'z':
{
- int diff;
+ long diff;
char const *sign;
if (t->tm_isdst < 0)
@@ -441,9 +464,10 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
else
sign = "+";
pt = _add(sign, pt, ptlim);
- diff /= 60;
- pt = _conv((diff / 60) * 100 + diff % 60,
- "%04d", pt, ptlim);
+ diff /= SECSPERMIN;
+ diff = (diff / MINSPERHOUR) * 100 +
+ (diff % MINSPERHOUR);
+ pt = _conv(diff, "%04d", pt, ptlim);
}
continue;
case '+':
@@ -473,7 +497,7 @@ _conv(int n, const char *format, char *pt, const char *ptlim)
{
char buf[INT_STRLEN_MAXIMUM(int) +1];
- (void) sprintf(buf, format, n);
+ sprintf(buf, format, n);
return _add(buf, pt, ptlim);
}
@@ -493,13 +517,13 @@ _add(const char *str, char *pt, const char *ptlim)
* with more only if necessary.
*/
static char *
-_yconv(const int a, const int b, const int convert_top,
- const int convert_yy, char *pt, const char *const ptlim)
+_yconv(int a, int b, bool convert_top, bool convert_yy,
+ char *pt, const char *ptlim)
{
int lead;
int trail;
-#define DIVISOR 100
+#define DIVISOR 100
trail = a % DIVISOR + b % DIVISOR;
lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
trail %= DIVISOR;