From e30f9b9d514b8a79f59fee77b12bf96c94ab47c5 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 15 Jun 2019 23:48:08 -0400 Subject: ob_rfc822_mktime(): Parse month --- (limited to 'lib') diff --git a/lib/time.sh b/lib/time.sh index 23b88ad..cb89ca8 100644 --- a/lib/time.sh +++ b/lib/time.sh @@ -79,6 +79,21 @@ _ob_mktime() return 0 } +_ob_mon_to_m() +{ + local mon="${1}" + shift 1 || _ob_abort + local m= + + case ${mon} in + Jan) m=1;; Feb) m=2;; Mar) m=3;; Apr) m=4;; + May) m=5;; Jun) m=6;; Jul) m=7;; Aug) m=8;; + Sep) m=9;; Oct) m=10;; Nov) m=11;; Dec) m=12;; + esac + printf '%d' ${m} + return 0 +} + ## @brief Convert a date and time into seconds since the Epoch ## @details \fBob_rfc822_mktime\fP() converts date and time formatted according ## to RFCs 822, 2822, and 5322 into non-leap seconds elapsed since the @@ -111,13 +126,14 @@ ob_rfc822_mktime() read wday mday mon year time tz <<-EOF ${rfc822_tm} EOF + mon=$(_ob_mon_to_m ${mon}) IFS=':' read hour min sec <<-EOF ${time} EOF tzsgn="${tz%%[0-9]*}"; tz=${tz#[+-]}; tz=${tz#0}; tz=${tz#0} tzhour=$((${tz} / 100)) tzmin=$(( ${tz} % 100)) - _ob_mktime ${year} ${mon#0} ${mday#0} ${hour#0} ${min#0} ${sec#0} \ + _ob_mktime ${year} ${mon} ${mday#0} ${hour#0} ${min#0} ${sec#0} \ $((${tzsgn}1 * (${tzhour} * 60 + ${tzmin}) * 60)) return 0 } -- cgit v0.9.1