Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

avoid error in system time 12H format #16

Merged
merged 1 commit into from
Jan 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Darkmode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
CREATE TABLE IF NOT EXISTS solar (id INTEGER PRIMARY KEY, time VARCHAR(5));
Expand Down