summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-06-18 10:35:29 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-06-18 10:35:29 (EDT)
commite2b8eb4e026a18a4a622bfe557234aaa3bd8d1a3 (patch)
tree273cf80dee48f985ea08a26bb0068c37cdb13ab6
parentcf359a62dbad21c31e20add22f8added282ee5f0 (diff)
ob_iso8601_gmtime(): Factor out common gmtime code
-rw-r--r--lib/time.sh35
1 files changed, 22 insertions, 13 deletions
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
+}