The Stack Overflow podcast is back! Listen to an interview with our new CEO.

9 of 11 added 1256 characters in body

# Introduction

tl;dr

In this challenge you have to calculate the moon's phase for a given date.

This challenge is inspired by the game psycho social audiovisual experiment "Superbrothers: Sword & Sworcery EP". In S:S&S EP the moon's phases are important to the outcome of the adventure as some events occur only at a specific point in time.

The question is: Which lunar phase is present on a specific date. Each main phase – from new moon to first quarter to full moon to third quarter – is about 7.38 days long. The whole lunar cycle is roughly 29.52 days. Based on these values various methods of calculation exist.1

# Input

• A date based on the Gregorian calendar, between 1 January 1970 and 31 December 2116.
• You can choose one of the following formats: yyyy-mm-dd, dd.mm.yyyy, dd/mm/yyyy, yyyymmdd or ddmmyyyy.

# Output

Output the index [0-7] of the lunar phase based on this zero-indexed array:

['New moon', 'Waxing crescent', 'First quarter', 'Waxing gibbous', 'Full moon', 'Waning gibbous', 'Third quarter', 'Waning crescent]


# Requirements

• You can write a program or a function. If you go with an anonymous function, please include an example of how to invoke it.
• Input is accepted from STDIN, command line arguments, as function parameters or from the closest equivalent.
• This is so shortest answer in bytes wins.
• Built-ins or external libraries that calculate the moon phase are not allowed.2
• Standard loopholes are disallowed.

# Tests

The value are: date | index of the phase | illumination | name

A full lunar cycle:

08.02.2016 | 0 |   0% | New moon
07.02.2016 | 7 |   2% | Waning crescent
07.02.2016 | 7 |   2% | Waning crescent
06.02.2016 | 7 |   6% | Waning crescent
05.02.2016 | 7 |  12% | Waning crescent
04.02.2016 | 7 |  19% | Waning crescent
03.02.2016 | 7 |  28% | Waning crescent
02.02.2016 | 7 |  37% | Waning crescent
01.02.2016 | 7 |  47% | Third quarter
31.01.2016 | 5 |  56% | Waning gibbous
30.01.2016 | 5 |  65% | Waning gibbous
29.01.2016 | 5 |  74% | Waning gibbous
28.01.2016 | 5 |  82% | Waning gibbous
27.01.2016 | 5 |  89% | Waning gibbous
26.01.2016 | 5 |  94% | Waning gibbous
25.01.2016 | 5 |  98% | Waning gibbous
24.01.2016 | 4 | 100% | Full moon
23.01.2016 | 3 | 100% | Waxing gibbous
22.01.2016 | 3 |  97% | Waxing gibbous
21.01.2016 | 3 |  93% | Waxing gibbous
20.01.2016 | 3 |  86% | Waxing gibbous
19.01.2016 | 3 |  77% | Waxing gibbous
18.01.2016 | 3 |  67% | Waxing gibbous
17.01.2016 | 3 |  56% | Waxing gibbous
16.01.2016 | 2 |  45% | First quarter
15.01.2016 | 1 |  33% | Waxing crescent
14.01.2016 | 1 |  23% | Waxing crescent
13.01.2016 | 1 |  14% | Waxing crescent
12.01.2016 | 1 |   7% | Waxing crescent
11.01.2016 | 1 |   2% | Waxing crescent
10.01.2016 | 0 |   0% | New moon


Random test cases:

14.12.2016 | 4 | 100% | Full moon
16.10.1983 | 3 |  75% | Waxing gibbous
04.07.1976 | 2 |  47% | First quarter
28.11.1970 | 0 |   0% | New moon
`

# Bonus

Reduce your byte count and withdraw:

• 15% – Print the actual name of the phase as listed in section Output instead of its index.
• 25% – Print the dates of the upcoming new and full moon separated by a whitespace or newline on empty input.

1 For example: Calculating phase on Wikipedia.
2 Sorry Mathematica.