diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 02:51:35 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 02:51:35 +0100 |
| commit | ff4ae02e49de534d453d226475f239b128f63c6a (patch) | |
| tree | 6d98d99d00dab58b297646e8f8e949442ddcb5aa /date822fmt.c | |
| parent | 5d47a7101a2394c7f7bb288585464fa293a2ad33 (diff) | |
| download | qmail-ff4ae02e49de534d453d226475f239b128f63c6a.tar.gz qmail-ff4ae02e49de534d453d226475f239b128f63c6a.tar.bz2 qmail-ff4ae02e49de534d453d226475f239b128f63c6a.zip | |
[PATCH] Make the email headers be written in localtime rather than GMT
qmail-date-localtime
Diffstat (limited to 'date822fmt.c')
| -rw-r--r-- | date822fmt.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/date822fmt.c b/date822fmt.c index 7674bd1..f4942b3 100644 --- a/date822fmt.c +++ b/date822fmt.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <time.h> | ||
| 1 | #include "datetime.h" | 2 | #include "datetime.h" |
| 2 | #include "fmt.h" | 3 | #include "fmt.h" |
| 3 | #include "date822fmt.h" | 4 | #include "date822fmt.h" |
| @@ -12,18 +13,51 @@ struct datetime *dt; | |||
| 12 | { | 13 | { |
| 13 | unsigned int i; | 14 | unsigned int i; |
| 14 | unsigned int len; | 15 | unsigned int len; |
| 16 | time_t now; | ||
| 17 | datetime_sec utc; | ||
| 18 | datetime_sec local; | ||
| 19 | struct tm *tm; | ||
| 20 | struct datetime new_dt; | ||
| 21 | int minutes; | ||
| 22 | |||
| 23 | utc = datetime_untai(dt); | ||
| 24 | now = (time_t)utc; | ||
| 25 | tm = localtime(&now); | ||
| 26 | new_dt.year = tm->tm_year; | ||
| 27 | new_dt.mon = tm->tm_mon; | ||
| 28 | new_dt.mday = tm->tm_mday; | ||
| 29 | new_dt.hour = tm->tm_hour; | ||
| 30 | new_dt.min = tm->tm_min; | ||
| 31 | new_dt.sec = tm->tm_sec; | ||
| 32 | local = datetime_untai(&new_dt); | ||
| 33 | |||
| 15 | len = 0; | 34 | len = 0; |
| 16 | i = fmt_uint(s,dt->mday); len += i; if (s) s += i; | 35 | i = fmt_uint(s,new_dt.mday); len += i; if (s) s += i; |
| 17 | i = fmt_str(s," "); len += i; if (s) s += i; | 36 | i = fmt_str(s," "); len += i; if (s) s += i; |
| 18 | i = fmt_str(s,montab[dt->mon]); len += i; if (s) s += i; | 37 | i = fmt_str(s,montab[new_dt.mon]); len += i; if (s) s += i; |
| 19 | i = fmt_str(s," "); len += i; if (s) s += i; | 38 | i = fmt_str(s," "); len += i; if (s) s += i; |
| 20 | i = fmt_uint(s,dt->year + 1900); len += i; if (s) s += i; | 39 | i = fmt_uint(s,new_dt.year + 1900); len += i; if (s) s += i; |
| 21 | i = fmt_str(s," "); len += i; if (s) s += i; | 40 | i = fmt_str(s," "); len += i; if (s) s += i; |
| 22 | i = fmt_uint0(s,dt->hour,2); len += i; if (s) s += i; | 41 | i = fmt_uint0(s,new_dt.hour,2); len += i; if (s) s += i; |
| 23 | i = fmt_str(s,":"); len += i; if (s) s += i; | 42 | i = fmt_str(s,":"); len += i; if (s) s += i; |
| 24 | i = fmt_uint0(s,dt->min,2); len += i; if (s) s += i; | 43 | i = fmt_uint0(s,new_dt.min,2); len += i; if (s) s += i; |
| 25 | i = fmt_str(s,":"); len += i; if (s) s += i; | 44 | i = fmt_str(s,":"); len += i; if (s) s += i; |
| 26 | i = fmt_uint0(s,dt->sec,2); len += i; if (s) s += i; | 45 | i = fmt_uint0(s,new_dt.sec,2); len += i; if (s) s += i; |
| 27 | i = fmt_str(s," -0000\n"); len += i; if (s) s += i; | 46 | |
| 47 | if (local < utc) { | ||
| 48 | minutes = (utc - local + 30) / 60; | ||
| 49 | i = fmt_str(s," -"); len += i; if (s) s += i; | ||
| 50 | i = fmt_uint0(s,minutes / 60,2); len += i; if (s) s += i; | ||
| 51 | i = fmt_uint0(s,minutes % 60,2); len += i; if (s) s += i; | ||
| 52 | } | ||
| 53 | else { | ||
| 54 | minutes = (local - utc + 30) / 60; | ||
| 55 | i = fmt_str(s," +"); len += i; if (s) s += i; | ||
| 56 | i = fmt_uint0(s,minutes / 60,2); len += i; if (s) s += i; | ||
| 57 | i = fmt_uint0(s,minutes % 60,2); len += i; if (s) s += i; | ||
| 58 | } | ||
| 59 | |||
| 60 | i = fmt_str(s,"\n"); len += i; if (s) s += i; | ||
| 61 | |||
| 28 | return len; | 62 | return len; |
| 29 | } | 63 | } |
