diff options
author | Werner Koch <[email protected]> | 2016-06-28 13:45:53 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-06-28 13:53:59 +0000 |
commit | 1ddf5b846fc058171af5f2784dad866b73eb0205 (patch) | |
tree | 4298df7be9dd465cd659ca633c854cb4ca09a034 /common/gettime.c | |
parent | common: Add missing header file for clarity. (diff) | |
download | gnupg-1ddf5b846fc058171af5f2784dad866b73eb0205.tar.gz gnupg-1ddf5b846fc058171af5f2784dad866b73eb0205.zip |
common: New function rfctimestamp.
* common/gettime.c (rfctimestamp): New.
--
It is surprisingly hard to create an RFC-2822 compliant Date value.
The problem is that strftime uses the current locale but the RFC
requires that the English names are used. This code is pretty simply
and avoid the extra problem of figuring out the correct timezone;
instead UTC is used. For the planned use case this is anyway better.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/gettime.c')
-rw-r--r-- | common/gettime.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/gettime.c b/common/gettime.c index 115f7256d..dd9c1968c 100644 --- a/common/gettime.c +++ b/common/gettime.c @@ -723,6 +723,39 @@ asctimestamp (u32 stamp) } +/* Return the timestamp STAMP in RFC-2822 format. This is always done + * in the C locale. We return the gmtime to avoid computing the + * timezone. The caller must release the returned string. + * + * Example: "Mon, 27 Jun 2016 1:42:00 +0000". + */ +char * +rfctimestamp (u32 stamp) +{ + time_t atime = stamp; + struct tm tmbuf, *tp; + + + if (IS_INVALID_TIME_T (atime)) + { + gpg_err_set_errno (EINVAL); + return NULL; + } + + tp = gnupg_gmtime (&atime, &tmbuf); + if (!tp) + return NULL; + return xtryasprintf ("%.3s, %02d %.3s %04d %02d:%02d:%02d +0000", + ("SunMonTueWedThuFriSat" + (tp->tm_wday%7)*3), + tp->tm_mday, + ("JanFebMarAprMayJunJulAugSepOctNovDec" + + (tp->tm_mon%12)*3), + tp->tm_year + 1900, + tp->tm_hour, + tp->tm_min, + tp->tm_sec); +} + static int days_per_year (int y) |