Ayende @ Rahien

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

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 6,124 | Comments: 45,483

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:

            phase+=3

      elif dateToCheck.Month == 2:

            phase+=4

      else:

            phase+= dateToCheck.Month

      phase+=dateToCheck.Day

      if dateToCheck.Year < 2000:

            phase -= 4

      else:

            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...


Comments

James Kovacs

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

public class ArcaneArts {

public bool WasChickenSacrificed() {

  return false;

}

}

:^P

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

@Ken,

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.

FUTURE POSTS

  1. RavenDB 3.5 whirl wind tour: I’ll find who is taking my I/O bandwidth and they SHALL pay - 5 hours from now
  2. The design of RavenDB 4.0: Physically segregating collections - about one day from now
  3. RavenDB 3.5 Whirlwind tour: I need to be free to explore my data - 2 days from now
  4. RavenDB 3.5 whirl wind tour: I'll have the 3+1 goodies to go, please - 5 days from now
  5. The design of RavenDB 4.0: Voron has a one track mind - 6 days from now

And 12 more posts are pending...

There are posts all the way to May 30, 2016

RECENT SERIES

  1. RavenDB 3.5 whirl wind tour (14):
    02 May 2016 - You want all the data, you can’t handle all the data
  2. The design of RavenDB 4.0 (13):
    03 May 2016 - Making Lucene reliable
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats