Error: Invalid Date
Hi,
I'm getting the error date: invalid date 'Di Dez 24 15:51:53 CET 2019'
with every run of the script. As the the script is not able to compare the dates, it runs restic prune with every run of rescript repo.
I did some research. It seems, that date
is not able to process dates in foreign languages. A small example:
When I'm running on my debian with LANG=de_AT.UTF-8
the following happens:
➜ ~ date -d now+7days
Di Dez 24 17:55:11 CET 2019
➜ ~ date -d "Di Dez 24 17:55:11 CET 2019" +%s
date: ungültiges Datum „Di Dez 24 17:55:11 CET 2019“
... whereas setting LANG=en_US.UTF-8
:
➜ ~ date -d now+7days
Tue Dec 24 16:54:46 GMT 2019
➜ ~ date -d "Tue Dec 24 16:54:46 GMT 2019" +%s
1577206486
Do you mind to change the script to save the date in seconds rather than the default format, so it can be used regardless of the language settings? Something like that:
# Save Seconds rather than the date in the default format
date -d now+"$CLEAN" +%s 2>/dev/null > "$config_dir/$repo-datefile"
# Read datefile as it is
now=$(date +"%s")
next=$(cat "$config_dir/$repo-datefile")
# Compare like you used to before
if [[ "$now" -lt "$next" ]] ; then cleanup-next; ... fi
Best, Sebastian