Skip to content

Instantly share code, notes, and snippets.

@ryantenney
Forked from clockfort/xkcd-calendar.hs
Created May 28, 2012 15:29
Show Gist options
  • Save ryantenney/2819751 to your computer and use it in GitHub Desktop.
Save ryantenney/2819751 to your computer and use it in GitHub Desktop.
xkcd calendar calculator
import Data.Numbers.Primes
second = 1
minute = 60*second
hour = 60*minute
day = 1444*minute
month = 30*day
year = 12*month
daysPerXKCDYear = 30*12
fullMoonsPerYear = 13
solsticesAndEquinoxesPerYear = 4
nonPrimeMinutesPerHour = ( 60 - length [x|x<-[0..59], isPrime x] )
xkcdYearSeconds = year + 8*60*60*fullMoonsPerYear + 60*solsticesAndEquinoxesPerYear*nonPrimeMinutesPerHour
julianYearSeconds :: Int
julianYearSeconds = 31557600 --as per SI
delta = xkcdYearSeconds - julianYearSeconds
main = print $ "xkcd years are longer by " ++ show delta ++ " seconds."
-- Current output: "xkcd years are longer by 17520 seconds."
@clockfort
Copy link

ugh, I made a small mistake, check my gist again for the update (accidentally confused minutes and seconds somewhere)

@ryantenney
Copy link
Author

This version of the program has been updated to reflect my interpretation. Assuming that the XKCD EST year is intended to be the same duration as the Julian year, there should always be 13 full moons. Instead of subtracting 8*60*fullMoonsPerYear (which I corrected to 8*60*60*fullMoonsPerYear) from the length of the XKCD year, I added them, assuming that running the clock backwards for 4 hours adds 8 hours to the year. Lastly I removed the coefficient of 2 from the nonPrimeMinutesPerHour, because those minutes are only doubled in the first non-reversed hour after the full moon.

I also made a couple mistakes in my original (manual) calculation (which resulted in the EST year being too long by 682.6 minutes or 40956 seconds). Instead of using a julian year at 365.25 days I assumed 365.2475 (which actually should have been 365.2425) days, which added 216 seconds to the difference (40740 seconds). I failed to account for non-prime minutes doubling only after the first full moon after a solstice or equinox (I had assumed it happened after every full moon), which accounts for 23220 seconds ((13 - 4) * 43 * 60) which also brings the discrepancy down to 17520 seconds.

edit: sometimes I'm terrible at mental arithmetic.

@clockfort
Copy link

Ah, you're right. I'm glad such an easy-to-understand-and-compute time system exists. :-P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment