diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-09-23 00:38:22 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:38:45 -0500 |
commit | f3b412fbd6dd94d64eb6a63d88baef2816891c29 (patch) | |
tree | 61b6086157d30cf1dd64c8cc720638cd484c78d1 /source4/lib/time.c | |
parent | 92d74c340843f52aaced18dcc243965387fcaedb (diff) | |
download | samba-f3b412fbd6dd94d64eb6a63d88baef2816891c29.tar.gz samba-f3b412fbd6dd94d64eb6a63d88baef2816891c29.tar.bz2 samba-f3b412fbd6dd94d64eb6a63d88baef2816891c29.zip |
r10438: Move portability functions to lib/replace/; replace now simply ensures
that a given set of (working) POSIX functions are available (without
prefixes to their names, etc). See lib/replace/README for a list.
Functions that behave different from their POSIX specification
(such as sys_select, sys_read, etc) have kept the sys_ prefix.
(This used to be commit 29919a71059b29fa27a49b1f5b84bb8881de65fc)
Diffstat (limited to 'source4/lib/time.c')
-rw-r--r-- | source4/lib/time.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source4/lib/time.c b/source4/lib/time.c index 61e92b8c00..5de9046c8d 100644 --- a/source4/lib/time.c +++ b/source4/lib/time.c @@ -594,3 +594,37 @@ NTTIME timeval_to_nttime(const struct timeval *tv) return 10*(tv->tv_usec + ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); } + +/******************************************************************* +yield the difference between *A and *B, in seconds, ignoring leap seconds +********************************************************************/ +static int tm_diff(struct tm *a, struct tm *b) +{ + int ay = a->tm_year + (1900 - 1); + int by = b->tm_year + (1900 - 1); + int intervening_leap_days = + (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + + return seconds; +} + +/******************************************************************* + return the UTC offset in seconds west of UTC, or 0 if it cannot be determined + ******************************************************************/ +int get_time_zone(time_t t) +{ + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); +} |