30 |
#include "ircd.h" |
#include "ircd.h" |
31 |
|
|
32 |
|
|
|
static const char *const months[] = |
|
|
{ |
|
|
"January", "February", "March", "April", |
|
|
"May", "June", "July", "August", |
|
|
"September", "October", "November", "December" |
|
|
}; |
|
|
|
|
|
static const char *const weekdays[] = |
|
|
{ |
|
|
"Sunday", "Monday", "Tuesday", "Wednesday", |
|
|
"Thursday", "Friday", "Saturday" |
|
|
}; |
|
|
|
|
33 |
const char * |
const char * |
34 |
date(time_t lclock) |
date(time_t lclock) |
35 |
{ |
{ |
36 |
static char buf[80], plus; |
static char buf[80]; |
37 |
static time_t lclock_last; |
static time_t lclock_last; |
|
struct tm *lt, *gm; |
|
|
struct tm gmbuf; |
|
|
int minswest; |
|
38 |
|
|
39 |
if (!lclock) |
if (!lclock) |
40 |
lclock = CurrentTime; |
lclock = CurrentTime; |
41 |
|
|
42 |
if (lclock_last == lclock) |
if (lclock_last != lclock) |
|
return buf; |
|
|
|
|
|
lclock_last = lclock; |
|
|
gm = gmtime(&lclock); |
|
|
memcpy(&gmbuf, gm, sizeof(gmbuf)); |
|
|
gm = &gmbuf; |
|
|
lt = localtime(&lclock); |
|
|
|
|
|
/* |
|
|
* There is unfortunately no clean portable way to extract time zone |
|
|
* offset information, so do ugly things. |
|
|
*/ |
|
|
minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min); |
|
|
|
|
|
if (lt->tm_yday != gm->tm_yday) |
|
43 |
{ |
{ |
44 |
if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) || |
lclock_last = lclock; |
45 |
(lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year)) |
strftime(buf, sizeof(buf), "%A %B %-e %Y -- %T %z", localtime(&lclock)); |
|
minswest -= 24 * 60; |
|
|
else |
|
|
minswest += 24 * 60; |
|
46 |
} |
} |
47 |
|
|
|
plus = (minswest > 0) ? '-' : '+'; |
|
|
if (minswest < 0) |
|
|
minswest = -minswest; |
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u", |
|
|
weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday, |
|
|
lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec, |
|
|
plus, minswest/60, minswest%60); |
|
48 |
return buf; |
return buf; |
49 |
} |
} |
50 |
|
|