From 7d5bb275dbe5c80bcb743150b1ae4463bc708333 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 18 Jun 2019 10:45:59 -0400 Subject: ob_touch_t_gmtime(): New function --- (limited to 'lib') diff --git a/lib/time.sh b/lib/time.sh index 95510e5..64843f5 100644 --- a/lib/time.sh +++ b/lib/time.sh @@ -190,3 +190,24 @@ ob_iso8601_gmtime() printf '%04d-%02d-%02dT%02d:%02d:%02dZ' $(_ob_gmtime "${timep}") return 0 } + +## @brief Convert seconds since the Epoch into a date and time +## @details \fBob_touch_t_gmtime\fP() converts the number of non-leap seconds +## elapsed since the Epoch into date and time in UTC formatted for the +## \fB-t\fP option of the \fBtouch\fP utility according to POSIX. It +## is similar to the C function \fBgmtime\fP except that it returns a +## formatted string instead of a structure. +## @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 for the \fBtouch\fP +## utility's \fB-t\fP option. +## @pure yes This function has no side effects. +ob_touch_t_gmtime() +{ + local timep="${1}" + shift 1 || _ob_abort + + # [[CC]YY]MMDDhhmm[.SS] + printf '%04d%02d%02d%02d%02d.%02d' $(_ob_gmtime "${timep}") + return 0 +} -- cgit v0.9.1