summaryrefslogtreecommitdiff
path: root/src/date.c
diff options
context:
space:
mode:
authorJacques Germishuys <jacquesg@striata.com>2014-04-10 12:42:29 +0200
committerJacques Germishuys <jacquesg@striata.com>2014-04-11 21:55:35 +0200
commit8e14b47fd788ce5ae0d1a003a8fba17753eb7db5 (patch)
tree53cb173d0b9562f714f8764b511095822bc6ff41 /src/date.c
parentb3b36a68d16f1fdc383a06fbe85c3cc042d86314 (diff)
downloadlibgit2-8e14b47fd788ce5ae0d1a003a8fba17753eb7db5.tar.gz
Introduce git__date_rfc2822_fmt. Allows for RFC2822 date headers
Diffstat (limited to 'src/date.c')
-rw-r--r--src/date.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/date.c b/src/date.c
index 7849c2f02..0e1b31aee 100644
--- a/src/date.c
+++ b/src/date.c
@@ -874,3 +874,31 @@ int git__date_parse(git_time_t *out, const char *date)
*out = approxidate_str(date, time_sec, &error_ret);
return error_ret;
}
+
+int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)
+{
+ int written;
+ struct tm gmt;
+ time_t t;
+
+ assert(out && date);
+
+ t = (time_t) (date->time + date->offset * 60);
+
+ if (p_gmtime_r (&t, &gmt) == NULL)
+ return -1;
+
+ written = p_snprintf(out, len, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d",
+ weekday_names[gmt.tm_wday],
+ gmt.tm_mday,
+ month_names[gmt.tm_mon],
+ gmt.tm_year + 1900,
+ gmt.tm_hour, gmt.tm_min, gmt.tm_sec,
+ date->offset / 60, date->offset % 60);
+
+ if (written < 0 || (written > (int) len - 1))
+ return -1;
+
+ return 0;
+}
+