Skip to content

Instantly share code, notes, and snippets.

@moritzuehling
Created November 18, 2014 14:05
Show Gist options
  • Save moritzuehling/50a003196798074affa4 to your computer and use it in GitHub Desktop.
Save moritzuehling/50a003196798074affa4 to your computer and use it in GitHub Desktop.
using System;
using System.Globalization;
namespace YearCalc
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input date (e.g. \"31.05\"): ");
DateTime blah = DateTime.Parse(Console.ReadLine(), CultureInfo.GetCultureInfo("de"));
int nt = blah.Day;
int nm = GetNM(blah);
Console.Write("For what yearhunded (e.g. 2000 for the current) the dates shall the dates be outputted: ");
int jh = int.Parse(Console.ReadLine()) / 100;
int njh = 6 - (jh % 4) * 2;
int x = 6 - (nt + nm + njh) % 7;
for (int i = 0; i < 99; i += 7 )
{
int njz = x + i;
int jz = (int)Math.Ceiling(njz / 1.25);
int njzcheck = (int)(jz / 4) + jz;
if(njz == njzcheck) //Yay, found a year! Need to chech since I only have a function jz -> njz, and the function isn't surjective, so imma check back.
{
string date = blah.Day + "." + blah.Month + "." + jh + jz.ToString("00");
Console.Write(date);
Console.WriteLine(" " + DateTime.Parse(date, CultureInfo.GetCultureInfo("de")).DayOfWeek);
}
}
Console.ReadLine();
}
static int[] nmtable2 = { 6, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
static int[] nmtable = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
static int GetNM(DateTime dateTime)
{
if (dateTime.Year % 4 == 0) //leap year handling.
return nmtable2[dateTime.Month - 1];
else
return nmtable[dateTime.Month - 1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment