Refuse to log meals in the future
The log is a record of what was eaten, so there is nothing to write down for a dinner that has not happened, and a stray entry dated next year would sit at the top of the history forever. A future date is now clamped to today. The clamp lives in the one function every read and write already goes through, so ?pvm=, the date picker, saving and deleting are all covered. The picker also gets max=today, which avoids offering the dead end at all. Fixes a latent bug found alongside it: today() returned the current instant with its time of day, while dates parsed from ?pvm= are midnight, so the two never compared equal. After saving today's dinner the redirect landed on /?pvm=... and the card then read "la 5.9. kirjattu" instead of "Tänään kirjattu", and "Tänään" stopped highlighting whenever the date was spelled out. today() now truncates to midnight in the configured location.
This commit is contained in:
@@ -135,6 +135,21 @@ check "the day is empty again" \
|
||||
check "search filters the board" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/?haku=keitto")" "keitto"
|
||||
|
||||
# Nothing was eaten tomorrow. A future date is clamped rather than logged.
|
||||
future=$(date -d '+30 days' +%Y-%m-%d)
|
||||
check "a future date falls back to today" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/?pvm=$future")" "$(date +%-d.%-m.%Y)"
|
||||
|
||||
check "saving a future date is clamped too" \
|
||||
"$(curl -s -o /dev/null -w '%{redirect_url}' -u ":$pass" \
|
||||
-d "pvm=$future&ruoka=$ruoka" "http://$addr/kirjaa")" "/"
|
||||
|
||||
check "tomorrow was not written to the log" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/?pvm=$future")" "$(date +%-d.%-m.%Y)"
|
||||
|
||||
# Clean up the entry that clamped onto today.
|
||||
curl -s -o /dev/null -u ":$pass" -d "pvm=$(date +%Y-%m-%d)" "http://$addr/poista"
|
||||
|
||||
# ---- adding a dish without leaving Kirjaa --------------------------------
|
||||
|
||||
miss=$(curl -s -u ":$pass" "http://$addr/?haku=Poronkariste")
|
||||
|
||||
Reference in New Issue
Block a user