Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

By foul moon

time to read 10 min | 1942 words

Because I know that I will need it...

# Not very accurate, but apperantly good enough for most purposes

# source: http://www.faqs.org/faqs/astronomy/faq/part3/section-15.html

def IsFullMoon(dateToCheck as date):

      two_digit_year as decimal = dateToCheck.Year - ((dateToCheck.Year/100)*100)

      remainder as decimal = two_digit_year %19

      if remainder > 9:

            remainder -= 19;

      phase as decimal = (remainder * 11) %30

      if dateToCheck.Month == 1:


      elif dateToCheck.Month == 2:



            phase+= dateToCheck.Month


      if dateToCheck.Year < 2000:

            phase -= 4


            phase -= 8.3

      phase = phase % 30

      return 14.5 < phase and phase < 15.5

Expected usage:

if IsFullMoon(DateTime.Now):

      raise SqlException("""Transaction (Process ID 179) was deadlocked on lock resources with another
process and has been chosen as the deadlock victim. Rerun the transaction."""

Update: I am still struggling with the code for WasChickenSacrifised(), will be glad to get suggestions...


James Kovacs

The implementation is simple if you ask a vegetarian to write it:

public class ArcaneArts {

public bool WasChickenSacrificed() {

  return false;




Ricardo Stuven

Where are the unit tests? Will you mock then Moon object?


Ken Egozi

return Moon.Capacity == Moon.Length

seriously, you can use Hebrew Calendar and check for day==15

def IsWitch:

return hasBroomstick and UsesBoo()
Ayende Rahien


Using the Hebrew calendar would be too easy... :-)

Regardless, is it guaranteed that 15th of a month is full moon?

Ken Egozi

The Hebrew Calendar is based on the moon. ie, in the firsdt day the moon is "empty", at the middle it's "full", and towards the end of the month the moon is emptying again.

That's how it's defined.

In old times, they did not even had a calendar. they just looked at the skies and when the moon was empty, it was decided as a new month.

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats