Saturday, January 15, 2011

Blue moons this century

I've been doing some work on calendars and I needed to generate a list of full moons in a given year. This got me wondering when the next blue moon will be and how many blue moons there will be this century. The next blue moon will be on 31 August 2012 at 1:57:45pm UTC and there will be 41 blue moons this century. Here is the code that I used to generate the list of dates:  

DateGenerator dateGenerator = new DateGenerator();
int[] years = Enumerable.Range(2000, 100).ToArray();
HashSet<int> hashSet = new HashSet<int>();
foreach (int year in years)
{
    List<DateTime> fullMoons = dateGenerator.FullMoons(year, 0);
    foreach (DateTime date in fullMoons)
    {
        int yearMonth = date.Year * 100 + date.Month;
        if (hashSet.Contains(yearMonth))
        {
            Console.WriteLine(date.ToString("dd-MMM-yyyy HH:mm:ss"));
        }
        hashSet.Add(yearMonth);
    }
}
Console.ReadLine();

Here is a full list of blue moons for this century. Times are UTC

30-Nov-2001 20:51:10
31-Jul-2004 18:06:05
30-Jun-2007 13:50:25
31-Dec-2009 19:14:20
31-Aug-2012 13:57:45
31-Jul-2015 10:45:46
31-Jan-2018 13:27:46
31-Mar-2018 12:37:46
31-Oct-2020 14:51:29
31-Aug-2023 01:37:05
31-May-2026 08:46:46
31-Dec-2028 16:49:45
30-Sep-2031 18:58:02
31-Jul-2034 05:56:35
31-Jan-2037 14:05:42
31-Mar-2037 09:54:43
31-Oct-2039 22:36:54
31-Aug-2042 02:05:14
30-May-2045 17:53:13
31-Jan-2048 00:16:32
30-Sep-2050 17:32:47
30-Jul-2053 17:08:32
31-Mar-2056 10:26:26
31-Oct-2058 12:54:58
30-Aug-2061 22:20:53
30-May-2064 10:37:03
31-Dec-2066 14:42:26
30-Mar-2067 20:11:05
30-Sep-2069 18:12:11
31-May-2072 22:19:43
30-Apr-2075 18:40:43
31-Oct-2077 10:39:00
31-Jul-2080 19:16:42
31-May-2083 09:43:39
31-Dec-2085 00:00:58
30-Sep-2088 15:28:47
30-Jul-2091 12:03:20
31-Jan-2094 12:40:11
30-Apr-2094 13:58:47
31-Oct-2096 11:20:22
30-Aug-2099 17:59:15