Skip to content

Instantly share code, notes, and snippets.

@archer884
Created February 18, 2015 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archer884/a21f90bddfbe45c81fd6 to your computer and use it in GitHub Desktop.
Save archer884/a21f90bddfbe45c81fd6 to your computer and use it in GitHub Desktop.
Super-Computus Easter calculator!
using System;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
namespace Computus
{
class Program
{
static Regex NodePattern = new Regex(@"<pre>.*?</pre>", RegexOptions.IgnoreCase|RegexOptions.Singleline);
static Regex DatePattern = new Regex(@"(\d+)(st|nd|rd|th) (April|March) (\d\d\d\d)", RegexOptions.IgnoreCase|RegexOptions.Singleline);
static void Main(string[] args)
{
using (var client = new WebClient())
{
var data = client.DownloadString("http://tlarsen2.tripod.com/anthonypolumbo/apeasterdates.html");
var dates = NodePattern.Matches(data).Cast<Match>().Select(match => match.Value)
.SelectMany(section => DatePattern.Matches(section).Cast<Match>().Select(match => match.Value
.Replace("st", String.Empty)
.Replace("nd", String.Empty)
.Replace("rd", String.Empty)
.Replace("th", String.Empty)))
.Select(date => DateTime.ParseExact(
date,
new[] { "dd MMMM yyyy", "d MMMM yyyy" },
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AdjustToUniversal))
.Where(date => date.Year > 2014 && date.Year < 2026)
.OrderBy(date => date);
foreach (var date in dates)
{
Console.WriteLine(date.ToShortDateString());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment