daily-psk: simplify algorithm

This commit is contained in:
Christian Hesse 2019-01-09 12:50:19 +01:00
parent 1ee2491e66
commit bd92237003

View file

@ -19,34 +19,26 @@
:local Months { "jan"; "feb"; "mar"; "apr"; "may"; "jun"; :local Months { "jan"; "feb"; "mar"; "apr"; "may"; "jun";
"jul"; "aug"; "sep"; "oct"; "nov"; "dec" }; "jul"; "aug"; "sep"; "oct"; "nov"; "dec" };
:local MonthTbl { 0; 3; 3; 6; 1; 4; 6; 2; 5; 0; 3; 5 };
:local MonthStr [ :pick $Date 0 3 ]; :local Month [ :pick $Date 0 3 ];
:local Month; :local Day [ :tonum [ :pick $Date 4 6 ] ];
:local Day [ :pick $Date 4 6 ]; :local Year [ :pick $Date 7 11 ];
:local Century [ :pick $Date 7 9 ];
:local Year [ :pick $Date 9 11 ];
# get numeric value for month
:for MIndex from=0 to=[ :len $Months ] do={ :for MIndex from=0 to=[ :len $Months ] do={
:if ([ :pick $Months $MIndex ] = $MonthStr) do={ :if ($Months->$MIndex = $Month) do={
:set Month $MIndex; :set Month ($MIndex + 1);
} }
} }
# calculate day of week :local A ((14 - $Month) / 12);
:local Sum 0; :local B ($Year - $A);
:set Sum ($Sum + (2 * (3 - ($Century - (($Century / 4) * 4))))); :local C ($Month + 12 * $A - 2);
:set Sum ($Sum + ($Year / 4)); :local WeekDay (7000 + $Day + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
:set Sum ($Sum + $Year + $Day); :set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
:set Sum ($Sum + $Month);
:set Sum ($Sum - (($Sum / 7) * 7));
:local Return ([ :pick [ :pick $DailyPskSecrets 0 ] ($Day - 1) ] . \ :return (($DailyPskSecrets->0->($Day - 1)) . \
[ :pick [ :pick $DailyPskSecrets 1 ] $Month ] . \ ($DailyPskSecrets->1->($Month - 1)) . \
[ :pick [ :pick $DailyPskSecrets 2 ] $Sum ]); ($DailyPskSecrets->2->$WeekDay));
:return $Return;
} }
:local Date [ / system clock get date ]; :local Date [ / system clock get date ];