version 1.24, 2013/04/02 04:40:21 |
version 1.30, 2015/10/23 11:43:16 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
#include <tzfile.h> |
|
|
|
#include "pathnames.h" |
#include "pathnames.h" |
#include "calendar.h" |
#include "calendar.h" |
|
|
static struct fixs fnmonths[13]; /* full national months names */ |
static struct fixs fnmonths[13]; /* full national months names */ |
static struct fixs nmonths[13]; /* short national month names */ |
static struct fixs nmonths[13]; /* short national month names */ |
|
|
|
|
void |
void |
setnnames(void) |
setnnames(void) |
{ |
{ |
|
|
for (i = 0; i < 7; i++) { |
for (i = 0; i < 7; i++) { |
tm.tm_wday = i; |
tm.tm_wday = i; |
l = strftime(buf, sizeof(buf), "%a", &tm); |
l = strftime(buf, sizeof(buf), "%a", &tm); |
for (; l > 0 && isspace((int)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
if (ndays[i].name != NULL) |
if (ndays[i].name != NULL) |
|
|
ndays[i].len = strlen(buf); |
ndays[i].len = strlen(buf); |
|
|
l = strftime(buf, sizeof(buf), "%A", &tm); |
l = strftime(buf, sizeof(buf), "%A", &tm); |
for (; l > 0 && isspace((int)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
if (fndays[i].name != NULL) |
if (fndays[i].name != NULL) |
|
|
for (i = 0; i < 12; i++) { |
for (i = 0; i < 12; i++) { |
tm.tm_mon = i; |
tm.tm_mon = i; |
l = strftime(buf, sizeof(buf), "%b", &tm); |
l = strftime(buf, sizeof(buf), "%b", &tm); |
for (; l > 0 && isspace((int)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
if (nmonths[i].name != NULL) |
if (nmonths[i].name != NULL) |
|
|
nmonths[i].len = strlen(buf); |
nmonths[i].len = strlen(buf); |
|
|
l = strftime(buf, sizeof(buf), "%B", &tm); |
l = strftime(buf, sizeof(buf), "%B", &tm); |
for (; l > 0 && isspace((int)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
if (fnmonths[i].name != NULL) |
if (fnmonths[i].name != NULL) |
|
|
tp->tm_isdst = 0; |
tp->tm_isdst = 0; |
tp->tm_hour = 12; |
tp->tm_hour = 12; |
*now = mktime(tp); |
*now = mktime(tp); |
if (isleap(tp->tm_year + TM_YEAR_BASE)) |
if (isleap(tp->tm_year + 1900)) |
cumdays = daytab[1]; |
cumdays = daytab[1]; |
else |
else |
cumdays = daytab[0]; |
cumdays = daytab[0]; |
|
|
len = strlen(date); |
len = strlen(date); |
if (len < 2) |
if (len < 2) |
return((time_t)-1); |
return((time_t)-1); |
|
bzero(&tm, sizeof tm); |
tm.tm_sec = 0; |
tm.tm_sec = 0; |
tm.tm_min = 0; |
tm.tm_min = 0; |
/* Avoid getting caught by a timezone shift; set time to noon */ |
/* Avoid getting caught by a timezone shift; set time to noon */ |
|
|
*(date + len - 4) = '\0'; |
*(date + len - 4) = '\0'; |
tm.tm_year = atoi(date); |
tm.tm_year = atoi(date); |
|
|
/* tm_year up TM_YEAR_BASE ... */ |
|
if (tm.tm_year < 69) /* Y2K */ |
if (tm.tm_year < 69) /* Y2K */ |
tm.tm_year += 2000 - TM_YEAR_BASE; |
tm.tm_year += 100; |
else if (tm.tm_year < 100) |
else if (tm.tm_year > 1900) |
tm.tm_year += 1900 - TM_YEAR_BASE; |
tm.tm_year -= 1900; |
else if (tm.tm_year > TM_YEAR_BASE) |
|
tm.tm_year -= TM_YEAR_BASE; |
|
} |
} |
|
|
#if DEBUG |
#if DEBUG |
|
|
return(mktime(&tm)); |
return(mktime(&tm)); |
} |
} |
|
|
void |
static void |
adjust_calendar(int *day, int *month) |
adjust_calendar(int *day, int *month) |
{ |
{ |
switch (calendar) { |
switch (calendar) { |
|
|
/* adjust bodun rate */ |
/* adjust bodun rate */ |
if (bodun && !bodun_always) |
if (bodun && !bodun_always) |
bodun = !arc4random_uniform(3); |
bodun = !arc4random_uniform(3); |
|
|
/* Easter or Easter depending days */ |
/* Easter or Easter depending days */ |
if (flags & F_SPECIAL) |
if (flags & F_SPECIAL) |
vwd = v1; |
vwd = v1; |
|
|
*/ |
*/ |
if (tp->tm_yday > 300 && tmtmp.tm_mon <= 1) |
if (tp->tm_yday > 300 && tmtmp.tm_mon <= 1) |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE + 1); |
tmtmp.tm_year + 1900 + 1); |
else |
else |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE); |
tmtmp.tm_year + 1900); |
day = cumdays[tmtmp.tm_mon + 1] + vwd; |
day = cumdays[tmtmp.tm_mon + 1] + vwd; |
tmtmp.tm_mday = vwd; |
tmtmp.tm_mday = vwd; |
} |
} |
v2 = day - tp->tm_yday; |
v2 = day - tp->tm_yday; |
if ((v2 > v1) || (v2 < 0)) { |
if ((v2 > v1) || (v2 < 0)) { |
if ((v2 += isleap(tp->tm_year + TM_YEAR_BASE) ? 366 : 365) |
if ((v2 += isleap(tp->tm_year + 1900) ? 366 : 365) |
<= v1) |
<= v1) |
tmtmp.tm_year++; |
tmtmp.tm_year++; |
else if(!bodun || (day - tp->tm_yday) != -1) |
else if(!bodun || (day - tp->tm_yday) != -1) |
|
|
if (vwd) { |
if (vwd) { |
v1 = vwd; |
v1 = vwd; |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE); |
tmtmp.tm_year + 1900); |
tmtmp.tm_mday = v1; |
tmtmp.tm_mday = v1; |
} else |
} else |
tmtmp.tm_mday = dayp; |
tmtmp.tm_mday = dayp; |
|
|
if (flags & F_SPECIAL) { |
if (flags & F_SPECIAL) { |
tmtmp.tm_mon = 0; /* Gee, mktime() is nice */ |
tmtmp.tm_mon = 0; /* Gee, mktime() is nice */ |
tmtmp.tm_mday = spev[v1].getev(tmtmp.tm_year + |
tmtmp.tm_mday = spev[v1].getev(tmtmp.tm_year + |
TM_YEAR_BASE) + vwd; |
1900) + vwd; |
} else if (vwd) { |
} else if (vwd) { |
v1 = vwd; |
v1 = vwd; |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE); |
tmtmp.tm_year + 1900); |
tmtmp.tm_mday = v1; |
tmtmp.tm_mday = v1; |
} else { |
} else { |
/* Need the following to keep Feb 29 from |
/* Need the following to keep Feb 29 from |