Difference between revisions of "Weekday"
From Scriptwiki
($day2 not $day..) |
|||
Line 2: | Line 2: | ||
− | ; format: $ | + | ; format: $day2 or $day2(day,month,year) |
[[alias]] day2 { | [[alias]] day2 { | ||
; if there are no parameter, just return the name of the current day | ; if there are no parameter, just return the name of the current day |
Revision as of 21:58, 27 November 2005
The following alias returns the name of a date you have specified. Only after 01.01.0001. If no date is specified, it returns the name of the current day.
; format: $day2 or $day2(day,month,year) alias day2 { ; if there are no parameter, just return the name of the current day if (!$1) { return $day } ; we get parameters else { ; lets first check if we got 3 correct ones if (($1 !isnum 1-31) || ($2 !isnum 1-12) || (!$3)) { return $false } ; there are no 5.10.1582 -> 14.10.1582 due to the change of calendar if (($3 == 1582) && ($2 == 10) && ($1 > 4) && ($1 < 15)) { return $false } ; we need the days of months var %month = 31,28,31,30,31,30,31,31,30,31,30,31 ; lets calc all days of all complete years and days in the current month var %days = $calc((($3 - 1)*365) + ($1 - 1)) ; now lets include all complete month in the current year (we need to loop through all) var %i = 0 while (%i < $calc($2 - 1)) { %days = $calc(%days + $gettok(%month,$calc(%i + 1),44)) inc %i } ; decrease days by ten due to change of calendar if (($3 > 1582) || (($3 == 1582) && (($2 > 10) || (($2 == 10) && ($1 > 4))))) { %days = $calc(%days - 10) } ; leapyears til 1599: all years divided by 4 ; after 1600: all years divided by 4 but not at full centurys, only if they are dividable by 400 var %leapyears = $floor($calc($3 / 4)) if (($calc($3 % 4) == 0) && ($2 < 3)) { dec %leapyears } if ($3 >= 1600) { %leapyears = $calc(%leapyears - $floor($calc(($3 - 1600) / 100))) %leapyears = $calc(%leapyears + $floor($calc(($3 - 1600) / 400))) if (($calc($3 % 100) == 0) && ($2 < 3)) { inc %leapyears if ($calc($3 % 400) == 0) { dec %leapyears } } } %days = $calc(%days + %leapyears) ; lets show the result var %week = Saturday,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday var %erg = $gettok(%week,$calc((%days % 7) + 1),44) return %erg } }