From e2b8eb4e026a18a4a622bfe557234aaa3bd8d1a3 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 18 Jun 2019 10:35:29 -0400 Subject: ob_iso8601_gmtime(): Factor out common gmtime code --- diff --git a/lib/time.sh b/lib/time.sh index 21e7448..95510e5 100644 --- a/lib/time.sh +++ b/lib/time.sh @@ -139,18 +139,7 @@ ob_rfc822_mktime() return 0 } -## @brief Convert seconds since the Epoch into a date and time -## @details \fBob_iso8601_gmtime\fP() converts the number of non-leap seconds -## elapsed since the Epoch into date and time in UTC formatted -## according to ISO 8601. It is similar to the C function \fBgmtime\fP -## except that it returns a formatted string instead of a structure. -## It is intended to generate a date and time usable with a -## POSIX-conformant \fBtouch\fP utility. -## @operand timep req The number of non-leap seconds elapsed since the Epoch. -## @return Returns 0. -## @stdout Prints the date and time in UTC formatted according to ISO 8601. -## @pure yes This function has no side effects. -ob_iso8601_gmtime() +_ob_gmtime() { local timep="${1}" shift 1 || _ob_abort @@ -177,7 +166,27 @@ ob_iso8601_gmtime() done mday=$((${timep} - $(_ob_month_to_days ${mon} ${year}) + 1)) - printf '%04d-%02d-%02dT%02d:%02d:%02dZ' \ + printf '%04d %02d %02d %02d %02d %02d' \ ${year} ${mon} ${mday} ${hour} ${min} ${sec} return 0 } + +## @brief Convert seconds since the Epoch into a date and time +## @details \fBob_iso8601_gmtime\fP() converts the number of non-leap seconds +## elapsed since the Epoch into date and time in UTC formatted +## according to ISO 8601. It is similar to the C function \fBgmtime\fP +## except that it returns a formatted string instead of a structure. +## It is intended to generate a date and time usable with a +## POSIX-conformant \fBtouch\fP utility. +## @operand timep req The number of non-leap seconds elapsed since the Epoch. +## @return Returns 0. +## @stdout Prints the date and time in UTC formatted according to ISO 8601. +## @pure yes This function has no side effects. +ob_iso8601_gmtime() +{ + local timep="${1}" + shift 1 || _ob_abort + + printf '%04d-%02d-%02dT%02d:%02d:%02dZ' $(_ob_gmtime "${timep}") + return 0 +} -- cgit v0.9.1