annotate src/lib/utc-offset.c @ 22664:fea53c2725c0

director: Fix director_max_parallel_moves/kicks type Should be uint, not time.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 09 Nov 2017 12:24:16 +0200
parents 2e2563132d5f
children cb108f786fb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 19552
diff changeset
1 /* Copyright (c) 2002-2017 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 */
9647
22ede7ce7be4 utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
22 if ((ltm.tm_yday < gtm.tm_yday && ltm.tm_year == gtm.tm_year) ||
22ede7ce7be4 utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
23 ltm.tm_year < gtm.tm_year)
492
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 offset = -24 * 60;
9647
22ede7ce7be4 utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
25 else if ((ltm.tm_yday > gtm.tm_yday && ltm.tm_year == gtm.tm_year) ||
22ede7ce7be4 utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
26 ltm.tm_year > gtm.tm_year)
492
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 offset = 24 * 60;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 else
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 offset = 0;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 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
32 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
33
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 /* restore overwritten tm */
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 *tm = ltm;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 return offset;
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 #endif
efa46e28a0d7 Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 }