For those who are curious, here is the basic function in AppleScript for calculating sunrise and sunset times given latitude, longitude, and time of day. I adapted it from

this document published by the NOAA.

**____**
-- Function to determine sunrise and setset times (in seconds) given latitude and logitude

on sunrise_sunset(lati, longi)

-- Query 'date' command for time zone. Convert time zone information into an offset specified in hours.

set timezoneoffset to do shell script "/bin/date +%z" as string

set hoursadjust to (first character of timezoneoffset) & (second character of timezoneoffset) & (third character of timezoneoffset) as number

set day_of_year to dayofyear()

set currentyear to (do shell script "/bin/date +%Y") as number

-- Calculate sunrise and sunset times in seconds. The following algorithm is accurate to within one minute without the need to query an external web service.

set days_in_year to 365

-- Check for leap year

if (currentyear mod 4) = 0 then

if (currentyear mod 100) is not equal to 0 or (currentyear mod 400) = 0 then set days_in_year to 366

end if

-- Calculate fractional year in degrees

set fractionalyear to 360 / days_in_year * (day_of_year)

set eqtime to 229.18 * (7.5E-5 + 0.001868 * (cosine_of(fractionalyear)) - 0.032077 * (sine_of(fractionalyear)) - 0.014615 * (cosine_of(2 * fractionalyear)) - 0.040849 * (sine_of(2 * fractionalyear)))

set decl to 0.006918 - 0.399912 * (cosine_of(fractionalyear)) + 0.070257 * (sine_of(fractionalyear)) - 0.006758 * (cosine_of(2 * fractionalyear)) + 9.07E-4 * (sine_of(2 * fractionalyear)) - 0.002697 * (cosine_of(3 * fractionalyear)) + 0.00148 * (sine_of(3 * fractionalyear))

set decl to 180 * decl / pi

set x to cosine_of(90.833) / (cosine_of(lati)) / (cosine_of(decl)) - tan(lati) * (tan(decl))

set ha to arccos(x)

set sunrise_time to round (60 * ((720 - 4 * (longi + ha) - eqtime) + (60 * hoursadjust)))

set sunset_time to round (60 * ((720 - 4 * (longi - ha) - eqtime) + (60 * hoursadjust)))

return {sunrise_time, sunset_time}

end sunrise_sunset