From da6a6243c487a4c61e2e624bb2f7c63619dc88b7 Mon Sep 17 00:00:00 2001 From: cesarradtke Date: Sat, 12 Jan 2019 12:29:10 -0200 Subject: [PATCH] avoid error in system time 12H format This change proposal is to avoid 'failed conversion' error in riseT and setT when system time was configured to 12H format. --- Darkmode.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Darkmode.sh b/Darkmode.sh index 689505a..b4708aa 100755 --- a/Darkmode.sh +++ b/Darkmode.sh @@ -74,9 +74,20 @@ solar() { # Get Night Shift solar times (UTC) riseT=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunrise | cut -d \" -f2) setT=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunset | cut -d \" -f2) + + # test 12 or 24 hour format + strig="M" + if [[ $riseT == *${strig}* ]]; + then + formatT="%Y-%m-%d %H:%M:%S %p %z" + else + formatT="%Y-%m-%d %H:%M:%S %z" + fi + # Convert to local time - riseTL=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$riseT" +"%H:%M") - setTL=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$setT" +"%H:%M") + riseTL=$(date -jf "$formatT" "$riseT" +"%H:%M") + setTL=$(date -jf "$formatT" "$setT" +"%H:%M") + # Store times in database sqlite3 "$darkdir"/solar.db <