annotate src/lib/utc-offset.c @ 8590:b9faf4db2a9f HEAD

Updated copyright notices to include year 2009.
author Timo Sirainen <tss@iki.fi>
date Tue, 06 Jan 2009 09:25:38 -0500
parents 7ed926ed7aa4
children 8e66ca02b6f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
492
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "utc-offset.h"
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include <sys/time.h>
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 1741
diff changeset
8 int utc_offset(struct tm *tm, time_t t ATTR_UNUSED)
492
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 {
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #ifdef HAVE_TM_GMTOFF
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 return (int) (tm->tm_gmtoff/60);
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #else
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 struct tm ltm, gtm;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 int offset;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 /* gmtime() overwrites tm, so we need to copy it elsewhere */
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 ltm = *tm;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 tm = gmtime(&t);
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 gtm = *tm;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 /* max offset of 24 hours */
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 if (ltm.tm_yday < gtm.tm_yday)
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 offset = -24 * 60;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 else if (ltm.tm_yday > gtm.tm_yday)
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 offset = 24 * 60;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 else
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 offset = 0;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 offset += (ltm.tm_hour - gtm.tm_hour) * 60;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 offset += (ltm.tm_min - gtm.tm_min);
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 /* restore overwritten tm */
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 *tm = ltm;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 return offset;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 #endif
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 }