From 9069f71ee6168a651fd42f90b7aea309fefa260b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 10 May 2023 13:48:46 +0200 Subject: daily-psk: use $ParseDate --- daily-psk.capsman.rsc | 19 ++++++++----------- daily-psk.local.rsc | 19 ++++++++----------- daily-psk.template.rsc | 19 ++++++++----------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/daily-psk.capsman.rsc b/daily-psk.capsman.rsc index 2bfb576..a24d761 100644 --- a/daily-psk.capsman.rsc +++ b/daily-psk.capsman.rsc @@ -33,21 +33,18 @@ $WaitFullyConnected; :global DailyPskSecrets; - :local Months { "jan"=1; "feb"=2; "mar"=3; "apr"=4; "may"=5; "jun"=6; - "jul"=7; "aug"=8; "sep"=9; "oct"=10; "nov"=11; "dec"=12 }; + :global ParseDate; - :local Month ($Months->[ :pick $Date 0 3 ]); - :local Day [ :tonum [ :pick $Date 4 6 ] ]; - :local Year [ :tonum [ :pick $Date 7 11 ] ]; + :set Date [ $ParseDate $Date ]; - :local A ((14 - $Month) / 12); - :local B ($Year - $A); - :local C ($Month + 12 * $A - 2); - :local WeekDay (7000 + $Day + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12)); + :local A ((14 - ($Date->"month")) / 12); + :local B (($Date->"year") - $A); + :local C (($Date->"month") + 12 * $A - 2); + :local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12)); :set WeekDay ($WeekDay - (($WeekDay / 7) * 7)); - :return (($DailyPskSecrets->0->($Day - 1)) . \ - ($DailyPskSecrets->1->($Month - 1)) . \ + :return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \ + ($DailyPskSecrets->1->(($Date->"month") - 1)) . \ ($DailyPskSecrets->2->$WeekDay)); } diff --git a/daily-psk.local.rsc b/daily-psk.local.rsc index 5f4382f..5e6e30f 100644 --- a/daily-psk.local.rsc +++ b/daily-psk.local.rsc @@ -33,21 +33,18 @@ $WaitFullyConnected; :global DailyPskSecrets; - :local Months { "jan"=1; "feb"=2; "mar"=3; "apr"=4; "may"=5; "jun"=6; - "jul"=7; "aug"=8; "sep"=9; "oct"=10; "nov"=11; "dec"=12 }; + :global ParseDate; - :local Month ($Months->[ :pick $Date 0 3 ]); - :local Day [ :tonum [ :pick $Date 4 6 ] ]; - :local Year [ :tonum [ :pick $Date 7 11 ] ]; + :set Date [ $ParseDate $Date ]; - :local A ((14 - $Month) / 12); - :local B ($Year - $A); - :local C ($Month + 12 * $A - 2); - :local WeekDay (7000 + $Day + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12)); + :local A ((14 - ($Date->"month")) / 12); + :local B (($Date->"year") - $A); + :local C (($Date->"month") + 12 * $A - 2); + :local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12)); :set WeekDay ($WeekDay - (($WeekDay / 7) * 7)); - :return (($DailyPskSecrets->0->($Day - 1)) . \ - ($DailyPskSecrets->1->($Month - 1)) . \ + :return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \ + ($DailyPskSecrets->1->(($Date->"month") - 1)) . \ ($DailyPskSecrets->2->$WeekDay)); } diff --git a/daily-psk.template.rsc b/daily-psk.template.rsc index 7dd5c7e..966a407 100644 --- a/daily-psk.template.rsc +++ b/daily-psk.template.rsc @@ -34,21 +34,18 @@ $WaitFullyConnected; :global DailyPskSecrets; - :local Months { "jan"=1; "feb"=2; "mar"=3; "apr"=4; "may"=5; "jun"=6; - "jul"=7; "aug"=8; "sep"=9; "oct"=10; "nov"=11; "dec"=12 }; + :global ParseDate; - :local Month ($Months->[ :pick $Date 0 3 ]); - :local Day [ :tonum [ :pick $Date 4 6 ] ]; - :local Year [ :tonum [ :pick $Date 7 11 ] ]; + :set Date [ $ParseDate $Date ]; - :local A ((14 - $Month) / 12); - :local B ($Year - $A); - :local C ($Month + 12 * $A - 2); - :local WeekDay (7000 + $Day + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12)); + :local A ((14 - ($Date->"month")) / 12); + :local B (($Date->"year") - $A); + :local C (($Date->"month") + 12 * $A - 2); + :local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12)); :set WeekDay ($WeekDay - (($WeekDay / 7) * 7)); - :return (($DailyPskSecrets->0->($Day - 1)) . \ - ($DailyPskSecrets->1->($Month - 1)) . \ + :return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \ + ($DailyPskSecrets->1->(($Date->"month") - 1)) . \ ($DailyPskSecrets->2->$WeekDay)); } -- cgit v1.2.3-70-g09d2