aboutsummaryrefslogtreecommitdiff
path: root/src/timezone/localtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/timezone/localtime.c')
-rw-r--r--src/timezone/localtime.c172
1 files changed, 83 insertions, 89 deletions
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c
index 098d6700f92..342bdc920c8 100644
--- a/src/timezone/localtime.c
+++ b/src/timezone/localtime.c
@@ -3,7 +3,7 @@
* 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.11 2005/06/20 08:00:51 neilc Exp $
+ * $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.12 2005/10/15 02:49:51 momjian Exp $
*/
/*
@@ -69,8 +69,7 @@ struct rule
#define JULIAN_DAY 0 /* Jn - Julian day */
#define DAY_OF_YEAR 1 /* n - day of year */
-#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of
- * week */
+#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
/*
* Prototypes for static functions.
@@ -81,15 +80,15 @@ static const char *getzname(const char *strp);
static const char *getnum(const char *strp, int *nump, int min, int max);
static const char *getsecs(const char *strp, long *secsp);
static const char *getoffset(const char *strp, long *offsetp);
-static const char *getrule(const char *strp, struct rule *rulep);
-static void gmtload(struct state *sp);
-static void gmtsub(const pg_time_t *timep, long offset, struct pg_tm *tmp);
-static void localsub(const pg_time_t *timep, long offset, struct pg_tm *tmp, const pg_tz *tz);
+static const char *getrule(const char *strp, struct rule * rulep);
+static void gmtload(struct state * sp);
+static void gmtsub(const pg_time_t *timep, long offset, struct pg_tm * tmp);
+static void localsub(const pg_time_t *timep, long offset, struct pg_tm * tmp, const pg_tz *tz);
static void timesub(const pg_time_t *timep, long offset,
- const struct state *sp, struct pg_tm *tmp);
+ const struct state * sp, struct pg_tm * tmp);
static pg_time_t transtime(pg_time_t janfirst, int year,
- const struct rule *rulep, long offset);
-int tzparse(const char *name, struct state *sp, int lastditch);
+ const struct rule * rulep, long offset);
+int tzparse(const char *name, struct state * sp, int lastditch);
/* GMT timezone */
static struct state gmtmem;
@@ -113,8 +112,8 @@ static struct pg_tm tm;
static long
detzcode(const char *codep)
{
- long result;
- int i;
+ long result;
+ int i;
result = (codep[0] & 0x80) ? ~0L : 0L;
for (i = 0; i < 4; ++i)
@@ -123,16 +122,16 @@ detzcode(const char *codep)
}
int
-tzload(const char *name, struct state *sp)
+tzload(const char *name, struct state * sp)
{
const char *p;
- int i;
- int fid;
+ int i;
+ int fid;
if (name == NULL && (name = TZDEFAULT) == NULL)
return -1;
{
- int doaccess;
+ int doaccess;
char fullname[MAXPGPATH];
if (name[0] == ':')
@@ -286,7 +285,7 @@ static const int year_lengths[2] = {
static const char *
getzname(const char *strp)
{
- char c;
+ char c;
while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
c != '+')
@@ -303,8 +302,8 @@ getzname(const char *strp)
static const char *
getnum(const char *strp, int *nump, int min, int max)
{
- char c;
- int num;
+ char c;
+ int num;
if (strp == NULL || !is_digit(c = *strp))
return NULL;
@@ -336,8 +335,8 @@ getsecs(const char *strp, long *secsp)
/*
* `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
- * "M10.4.6/26", which does not conform to Posix, but which specifies
- * the equivalent of ``02:00 on the first Sunday on or after 23 Oct''.
+ * "M10.4.6/26", which does not conform to Posix, but which specifies the
+ * equivalent of ``02:00 on the first Sunday on or after 23 Oct''.
*/
strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
if (strp == NULL)
@@ -372,7 +371,7 @@ getsecs(const char *strp, long *secsp)
static const char *
getoffset(const char *strp, long *offsetp)
{
- int neg = 0;
+ int neg = 0;
if (*strp == '-')
{
@@ -396,7 +395,7 @@ getoffset(const char *strp, long *offsetp)
* Otherwise, return a pointer to the first character not part of the rule.
*/
static const char *
-getrule(const char *strp, struct rule *rulep)
+getrule(const char *strp, struct rule * rulep)
{
if (*strp == 'J')
{
@@ -458,10 +457,10 @@ getrule(const char *strp, struct rule *rulep)
*/
static pg_time_t
transtime(const pg_time_t janfirst, int year,
- const struct rule *rulep, long offset)
+ const struct rule * rulep, long offset)
{
- int leapyear;
- pg_time_t value = 0;
+ int leapyear;
+ pg_time_t value = 0;
int i,
d,
m1,
@@ -478,9 +477,9 @@ transtime(const pg_time_t janfirst, int year,
/*
* Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
- * years. In non-leap years, or if the day number is 59 or
- * less, just add SECSPERDAY times the day number-1 to the
- * time of January 1, midnight, to get the day.
+ * years. In non-leap years, or if the day number is 59 or less,
+ * just add SECSPERDAY times the day number-1 to the time of
+ * January 1, midnight, to get the day.
*/
value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
if (leapyear && rulep->r_day >= 60)
@@ -490,8 +489,8 @@ transtime(const pg_time_t janfirst, int year,
case DAY_OF_YEAR:
/*
- * n - day of year. Just add SECSPERDAY times the day number
- * to the time of January 1, midnight, to get the day.
+ * n - day of year. Just add SECSPERDAY times the day number to
+ * the time of January 1, midnight, to get the day.
*/
value = janfirst + rulep->r_day * SECSPERDAY;
break;
@@ -519,9 +518,8 @@ transtime(const pg_time_t janfirst, int year,
dow += DAYSPERWEEK;
/*
- * "dow" is the day-of-week of the first day of the month. Get
- * the day-of-month (zero-origin) of the first "dow" day of
- * the month.
+ * "dow" is the day-of-week of the first day of the month. Get the
+ * day-of-month (zero-origin) of the first "dow" day of the month.
*/
d = rulep->r_day - dow;
if (d < 0)
@@ -543,9 +541,8 @@ transtime(const pg_time_t janfirst, int year,
/*
* "value" is the Epoch-relative time of 00:00:00 UTC on the day in
- * question. To get the Epoch-relative time of the specified local
- * time on that day, add the transition time and the current offset
- * from UTC.
+ * question. To get the Epoch-relative time of the specified local time
+ * on that day, add the transition time and the current offset from UTC.
*/
return value + rulep->r_time + offset;
}
@@ -556,7 +553,7 @@ transtime(const pg_time_t janfirst, int year,
*/
int
-tzparse(const char *name, struct state *sp, int lastditch)
+tzparse(const char *name, struct state * sp, int lastditch)
{
const char *stdname;
const char *dstname = NULL;
@@ -564,10 +561,10 @@ tzparse(const char *name, struct state *sp, int lastditch)
size_t dstlen;
long stdoffset;
long dstoffset;
- pg_time_t *atp;
+ pg_time_t *atp;
unsigned char *typep;
- char *cp;
- int load_result;
+ char *cp;
+ int load_result;
stdname = name;
if (lastditch)
@@ -614,8 +611,8 @@ tzparse(const char *name, struct state *sp, int lastditch)
{
struct rule start;
struct rule end;
- int year;
- pg_time_t janfirst;
+ int year;
+ pg_time_t janfirst;
pg_time_t starttime;
pg_time_t endtime;
@@ -671,12 +668,12 @@ tzparse(const char *name, struct state *sp, int lastditch)
}
else
{
- long theirstdoffset;
- long theirdstoffset;
- long theiroffset;
- int isdst;
- int i;
- int j;
+ long theirstdoffset;
+ long theirdstoffset;
+ long theiroffset;
+ int isdst;
+ int i;
+ int j;
if (*name != '\0')
return -1;
@@ -714,8 +711,8 @@ tzparse(const char *name, struct state *sp, int lastditch)
theiroffset = theirstdoffset;
/*
- * Now juggle transition times and types tracking offsets as
- * you do.
+ * Now juggle transition times and types tracking offsets as you
+ * do.
*/
for (i = 0; i < sp->timecnt; ++i)
{
@@ -728,17 +725,15 @@ tzparse(const char *name, struct state *sp, int lastditch)
else
{
/*
- * If summer time is in effect, and the transition
- * time was not specified as standard time, add the
- * summer time offset to the transition time;
- * otherwise, add the standard time offset to the
- * transition time.
+ * If summer time is in effect, and the transition time
+ * was not specified as standard time, add the summer time
+ * offset to the transition time; otherwise, add the
+ * standard time offset to the transition time.
*/
/*
- * Transitions from DST to DDST will effectively
- * disappear since POSIX provides for only one DST
- * offset.
+ * Transitions from DST to DDST will effectively disappear
+ * since POSIX provides for only one DST offset.
*/
if (isdst && !sp->ttis[j].tt_ttisstd)
{
@@ -759,8 +754,7 @@ tzparse(const char *name, struct state *sp, int lastditch)
}
/*
- * Finally, fill in ttis. ttisstd and ttisgmt need not be
- * handled.
+ * Finally, fill in ttis. ttisstd and ttisgmt need not be handled.
*/
sp->ttis[0].tt_gmtoff = -stdoffset;
sp->ttis[0].tt_isdst = FALSE;
@@ -798,7 +792,7 @@ tzparse(const char *name, struct state *sp, int lastditch)
}
static void
-gmtload(struct state *sp)
+gmtload(struct state * sp)
{
if (tzload(gmt, sp) != 0)
(void) tzparse(gmt, sp, TRUE);
@@ -814,11 +808,11 @@ gmtload(struct state *sp)
* The unused offset argument is for the benefit of mktime variants.
*/
static void
-localsub(const pg_time_t *timep, long offset, struct pg_tm *tmp, const pg_tz *tz)
+localsub(const pg_time_t *timep, long offset, struct pg_tm * tmp, const pg_tz *tz)
{
- const struct state *sp;
+ const struct state *sp;
const struct ttinfo *ttisp;
- int i;
+ int i;
const pg_time_t t = *timep;
sp = &tz->state;
@@ -859,7 +853,7 @@ pg_localtime(const pg_time_t *timep, const pg_tz *tz)
* gmtsub is to gmtime as localsub is to localtime.
*/
static void
-gmtsub(const pg_time_t *timep, long offset, struct pg_tm *tmp)
+gmtsub(const pg_time_t *timep, long offset, struct pg_tm * tmp)
{
if (!gmt_is_set)
{
@@ -870,8 +864,8 @@ gmtsub(const pg_time_t *timep, long offset, struct pg_tm *tmp)
/*
* Could get fancy here and deliver something such as "UTC+xxxx" or
- * "UTC-xxxx" if offset is non-zero, but this is no time for a
- * treasure hunt.
+ * "UTC-xxxx" if offset is non-zero, but this is no time for a treasure
+ * hunt.
*/
if (offset != 0)
tmp->tm_zone = wildabbr;
@@ -889,20 +883,20 @@ pg_gmtime(const pg_time_t *timep)
static void
timesub(const pg_time_t *timep, long offset,
- const struct state *sp, struct pg_tm *tmp)
+ const struct state * sp, struct pg_tm * tmp)
{
const struct lsinfo *lp;
/* expand days to 64 bits to support full Julian-day range */
- int64 days;
- int idays;
- long rem;
- int y;
- int yleap;
- const int *ip;
- long corr;
- int hit;
- int i;
+ int64 days;
+ int idays;
+ long rem;
+ int y;
+ int yleap;
+ const int *ip;
+ long corr;
+ int hit;
+ int i;
corr = 0;
hit = 0;
@@ -959,8 +953,8 @@ timesub(const pg_time_t *timep, long offset,
tmp->tm_min = (int) (rem / SECSPERMIN);
/*
- * A positive leap second requires a special representation. This
- * uses "... ??:59:60" et seq.
+ * A positive leap second requires a special representation. This uses
+ * "... ??:59:60" et seq.
*/
tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;
tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
@@ -970,16 +964,16 @@ timesub(const pg_time_t *timep, long offset,
/*
* Note: the point of adding 4800 is to ensure we make the same
- * assumptions as Postgres' Julian-date routines about the placement
- * of leap years in centuries BC, at least back to 4713BC which is as
- * far as we'll go. This is effectively extending Gregorian
- * timekeeping into pre-Gregorian centuries, which is a tad bogus but
- * it conforms to the SQL spec...
+ * assumptions as Postgres' Julian-date routines about the placement of
+ * leap years in centuries BC, at least back to 4713BC which is as far as
+ * we'll go. This is effectively extending Gregorian timekeeping into
+ * pre-Gregorian centuries, which is a tad bogus but it conforms to the
+ * SQL spec...
*/
#define LEAPS_THRU_END_OF(y) (((y) + 4800) / 4 - ((y) + 4800) / 100 + ((y) + 4800) / 400)
while (days < 0 || days >= (int64) year_lengths[yleap = isleap(y)])
{
- int newy;
+ int newy;
newy = y + days / DAYSPERNYEAR;
if (days < 0)
@@ -1027,12 +1021,12 @@ pg_next_dst_boundary(const pg_time_t *timep,
pg_time_t *boundary,
long int *after_gmtoff,
int *after_isdst,
- const pg_tz *tz)
+ const pg_tz *tz)
{
const struct state *sp;
const struct ttinfo *ttisp;
- int i;
- int j;
+ int i;
+ int j;
const pg_time_t t = *timep;
sp = &tz->state;