Mercurial > dovecot > core-2.2
annotate src/lib/utc-offset.c @ 23007:36e01285b5b8
lib: buffer - Improve header comment for buffer_insert() and buffer_delete().
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Mon, 18 Mar 2019 00:52:37 +0100 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
1 /* Copyright (c) 2002-2018 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 } |