Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6a2b75c

Browse files
committed
Add Olson's public domain timezone library to src/timezone.
1 parent d51d870 commit 6a2b75c

31 files changed

+16039
-0
lines changed

src/timezone/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile--
4+
# Makefile for the timezone library
5+
6+
# IDENTIFICATION
7+
# $PostgreSQL: pgsql/src/timezone/Makefile,v 1.1 2004/04/30 04:09:23 momjian Exp $
8+
#
9+
#-------------------------------------------------------------------------
10+
11+
subdir = src/port/tz
12+
top_builddir = ../../..
13+
include $(top_builddir)/src/Makefile.global
14+
15+
OBJS= asctime.o difftime.o localtime.o pgtz.o
16+
ZICOBJS= zic.o ialloc.o scheck.o localtime.o asctime.o pgtz.o ../path.o
17+
18+
TZDATA := africa antarctica asia australasia europe northamerica southamerica pacificnew etcetera factory backward systemv solar87 solar88 solar89
19+
TZDATAFILES := $(TZDATA:%=data/%)
20+
21+
all: SUBSYS.o zic
22+
23+
SUBSYS.o: $(OBJS)
24+
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
25+
26+
27+
zic: $(ZICOBJS)
28+
29+
install: zic
30+
zic -d $(datadir)/timezone $(TZDATAFILES)
31+
32+
clean distclean maintainer-clean:
33+
rm -f SUBSYS.o $(OBJS) $(ZICOBJS)

src/timezone/README

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This is a PostgreSQL adapted version of the timezone library
2+
from:
3+
ftp://elsie.nci.nih.gov/pub/tz*.tar.gz
4+
5+
6+
The interface is used when USE_PGTZ is defined at the top level. This
7+
will cause the following functions to be redefined:
8+
localtime pg_localtime
9+
gmtime pg_gmtime
10+
asctime pg_asctime
11+
ctime pg_ctime
12+
difftime pg_difftime
13+
mktime pg_mktime
14+
tzset pg_tzset
15+
16+
and the TIMEZONE_GLOBAL define in c.h is redefined to pg_timezone.
17+

src/timezone/asctime.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
** This file is in the public domain, so clarified as of
3+
** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
4+
*/
5+
6+
#ifndef lint
7+
#ifndef NOID
8+
static char elsieid[] = "@(#)asctime.c 7.9";
9+
#endif /* !defined NOID */
10+
#endif /* !defined lint */
11+
12+
/*LINTLIBRARY*/
13+
14+
#include "private.h"
15+
#include "tzfile.h"
16+
17+
/*
18+
** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12.
19+
*/
20+
21+
char *
22+
asctime_r(timeptr, buf)
23+
register const struct tm * timeptr;
24+
char * buf;
25+
{
26+
static const char wday_name[][3] = {
27+
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
28+
};
29+
static const char mon_name[][3] = {
30+
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
31+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
32+
};
33+
register const char * wn;
34+
register const char * mn;
35+
36+
if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
37+
wn = "???";
38+
else wn = wday_name[timeptr->tm_wday];
39+
if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
40+
mn = "???";
41+
else mn = mon_name[timeptr->tm_mon];
42+
/*
43+
** The X3J11-suggested format is
44+
** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
45+
** Since the .2 in 02.2d is ignored, we drop it.
46+
*/
47+
(void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
48+
wn, mn,
49+
timeptr->tm_mday, timeptr->tm_hour,
50+
timeptr->tm_min, timeptr->tm_sec,
51+
TM_YEAR_BASE + timeptr->tm_year);
52+
return buf;
53+
}
54+
55+
/*
56+
** A la X3J11, with core dump avoidance.
57+
*/
58+
59+
char *
60+
asctime(timeptr)
61+
register const struct tm * timeptr;
62+
{
63+
/*
64+
** Big enough for something such as
65+
** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
66+
** (two three-character abbreviations, five strings denoting integers,
67+
** three explicit spaces, two explicit colons, a newline,
68+
** and a trailing ASCII nul).
69+
*/
70+
static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
71+
3 + 2 + 1 + 1];
72+
73+
return asctime_r(timeptr, result);
74+
}

0 commit comments

Comments
 (0)