summaryrefslogtreecommitdiffstats
path: root/server/util_time.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--server/util_time.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/server/util_time.c b/server/util_time.c
index 3632d0d..299b53c 100644
--- a/server/util_time.c
+++ b/server/util_time.c
@@ -22,9 +22,11 @@
* */
#define AP_CTIME_USEC_LENGTH 7
-/* Length of ISO 8601 date/time */
+/* Length of ISO 8601 date/time (including trailing '\0') */
#define AP_CTIME_COMPACT_LEN 20
+/* Length of timezone offset from GMT ([+-]hhmm) plus leading space */
+#define AP_CTIME_GMTOFF_LEN 6
/* Cache for exploded values of recent timestamps
*/
@@ -181,7 +183,13 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
needed += AP_CTIME_USEC_LENGTH;
}
- /* Check the provided buffer length */
+ if (option & AP_CTIME_OPTION_GMTOFF) {
+ needed += AP_CTIME_GMTOFF_LEN;
+ }
+
+ /* Check the provided buffer length (note: above AP_CTIME_COMPACT_LEN
+ * and APR_CTIME_LEN include the trailing '\0'; so does 'needed' then).
+ */
if (len && *len >= needed) {
*len = needed;
}
@@ -193,9 +201,10 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
}
/* example without options: "Wed Jun 30 21:49:08 1993" */
- /* 123456789012345678901234 */
/* example for compact format: "1993-06-30 21:49:08" */
- /* 1234567890123456789 */
+ /* example for compact+usec+gmtoff format:
+ * "1993-06-30 22:49:08.123456 +0100"
+ */
ap_explode_recent_localtime(&xt, t);
real_year = 1900 + xt.tm_year;
@@ -249,7 +258,23 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
*date_str++ = real_year % 100 / 10 + '0';
*date_str++ = real_year % 10 + '0';
}
- *date_str++ = 0;
+ if (option & AP_CTIME_OPTION_GMTOFF) {
+ int off = xt.tm_gmtoff, off_hh, off_mm;
+ char sign = '+';
+ if (off < 0) {
+ off = -off;
+ sign = '-';
+ }
+ off_hh = off / 3600;
+ off_mm = off % 3600 / 60;
+ *date_str++ = ' ';
+ *date_str++ = sign;
+ *date_str++ = off_hh / 10 + '0';
+ *date_str++ = off_hh % 10 + '0';
+ *date_str++ = off_mm / 10 + '0';
+ *date_str++ = off_mm % 10 + '0';
+ }
+ *date_str = 0;
return APR_SUCCESS;
}