Hi.
That’s fun.
With regard to your code, ‘days’ is actually an AppleScript constant with the value 86400 ” the number of seconds in a day. It can be set to something else in a script, but ideally it should be treated as a reserved word.
SInce all the numbers are positive, you don’t need to use Satimage’s ‘floor’. You can simply use AppleScript’s ‘div’ instead of ‘/’.
If you have text which is coercible to number, you can perform mathematical operations on it directly. The coercions are then automatic. So instead of ‘(text 1 thru 2 of the_year) as integer’, you could just have ‘the_year div 100’. Of course, you could, if you liked, explicitly coerce the_year to integer before doing the various math operations with it.
property anchors : {2, 0, 5, 3} -- (2000-2099 = 2; 2100-2199 = 0; 2200-2299 = 5; 2300-2399 = 3) the same every 400 years
property wkdays : {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
set the_year to (text returned of (display dialog "What year would like to find the Doomsday for?" default answer "xxxx" buttons {"Cancel", "OK"} default button "OK")) as integer
set the_anchor to the_year div 100
set the_anchor_day to item (the_anchor mod 4 + 1) of anchors
set yy to the_year mod 100
set a to yy div 12
set b to yy mod 12
set c to b div 4
set d to (a + b + c) mod 7
set dooms to (d + the_anchor_day) mod 7
set the_day to item (dooms + 1) of wkdays
beep 1
display dialog "Doomsday for the year " & the_year & " is " & the_day buttons {"Cancel", "OK"} default button "OK"
Not sensibly. AppleScript’s weekdays can be coerced to integer, but not vice versa. You could add ‘dooms’ days (assuming you’re no longer using ‘days’ for something else!) to a known Sunday date and coerce the weekday of the result to text, but it’s a bit convoluted and only produces English results:
set the_day to (weekday of ((date ("1 1 2006" as text)) + dooms * days)) as text
I don’t know the mathematical significance of the anchor numbers, but the list of them can be replaced with a mathematical cheat:
set the_anchor_day to (2053 div (10 ^ (3 - the_anchor mod 4))) mod 10
Addendum: Another cheat, since we’re using AppleScript anyway, would be to create a “memorable date” in the given year and simply read off the weekday!
set the_year to (text returned of (display dialog "What year would like to find the Doomsday for?" default answer "xxxx" buttons {"Cancel", "OK"} default button "OK")) as integer
tell (current date)
set {its day, its month, its year} to {4, 4, the_year}
set the_day to item (its weekday) of {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} -- Or: its weekday as text
end tell
beep 1
display dialog "Doomsday for the year " & the_year & " is " & the_day buttons {"Cancel", "OK"} default button "OK"