Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Data;
- namespace MithraLib
- {
- public class Log
- {
- public static void WriteLine(string entry)
- {
- System.Diagnostics.Debug.WriteLine(entry);
- }
- }
- public static class Calendar
- {
- public static MannicDay Convert(DateTime dt)
- {
- return Converttosolar(dt, "?");
- }
- public static MannicDay Converttosolar(DateTime dt, string calendar)
- {
- int day_of_the_year_to_convert = dt.DayOfYear - 1;
- int year = dt.Year;
- int month = dt.Month;
- int day = dt.Day;
- if ((year == 1582) && (dt.Month == 10) && (dt.Day > 4) && (dt.Day < 15))
- {
- calendar = "Gregorian";
- }
- MannicDay[] YearArray = MannicYear(year, calendar);
- return YearArray[day_of_the_year_to_convert];
- }
- public static LunisolarDay createLunisolarDay(int year, double month, int day)
- {
- return createLunisolarDay(year, month, day, 0);
- }
- public static LunisolarDay createLunisolarDay(int year, double month, int day, int hour)
- {
- return createLunisolarDay(year, month, day, hour, 0);
- }
- public static LunisolarDay createLunisolarDay(int year, double month, int day, int hour, int min)
- {
- return createLunisolarDay(year, month, day, hour, min, 0);
- }
- public static LunisolarDay createLunisolarDay(int year, double month, int day, int hour, int min, int sec)
- {
- int mannic_year = year;
- int gregorian_year;
- if (mannic_year > 10000)
- {
- gregorian_year = mannic_year - 10000;
- }
- else
- {
- gregorian_year = mannic_year - 10001;
- }
- LunisolarYear Calendar_Year = createLunisolarYear(gregorian_year, "Gregorian");
- int i = 0;
- bool found = false;
- LunisolarDay created_day = Calendar_Year.DaysArray[i];
- double checkmonth;
- int checkday;
- while(found == false)
- {
- created_day = Calendar_Year.DaysArray[i];
- checkmonth = created_day.month;
- checkday = created_day.day;
- if((checkday == day) && (checkmonth == month))
- {
- found = true;
- }
- else
- {
- i++;
- }
- }
- DateTime dt = created_day.Gregorian;
- int gregmonth = dt.Month;
- int gregday = dt.Day;
- DateTime gregdate = new DateTime(gregorian_year, gregmonth, gregday, hour, min, sec);
- created_day.Gregorian = gregdate;
- return created_day;
- }
- public static LunisolarDay ConverttoLunisolar(DateTime dt)
- {
- return ConverttoLunisolar(dt, "?");
- }
- public static LunisolarDay ConverttoLunisolar(DateTime dt, string calendar)
- {
- int day_of_the_year_to_convert = dt.DayOfYear - 1;
- int year = dt.Year;
- int month = dt.Month;
- int day = dt.Day;
- if ((year == 1582) && (dt.Month == 10) && (dt.Day > 4) && (dt.Day < 15))
- {
- calendar = "Gregorian";
- }
- //MannicDay[] YearArray = MannicYear(year, calendar);
- //return YearArray[day_of_the_year_to_convert];
- LunisolarYear converted_year = createLunisolarYear(year, calendar);
- LunisolarDay converted_day = converted_year.DaysArray[day_of_the_year_to_convert];
- return converted_day;
- }
- public static LunisolarYear createLunisolarYear(int gregyear)
- {
- return createLunisolarYear(gregyear, "gregorian");
- }
- public static LunisolarYear createLunisolarYear(int gregyear, string calendar)
- {
- DateTime[] FourPoints = Points(gregyear, calendar);
- int i = 0;
- //int j = 0;
- int m = 1;
- DateTime[] months = Moons(gregyear);
- ////Console.WriteLine("New Moons");
- //Object[,] DaysList = new Object[19,4];
- //LunisolarArrayElement[] DaysList = new LunisolarArrayElement[17];
- List<LunisolarArrayElement> DaysList = new List<LunisolarArrayElement>();
- ////Console.WriteLine("Four Points");
- string info = "0";
- foreach (DateTime element in FourPoints)
- {
- //count++;
- ////Console.WriteLine(element);
- switch (i)
- {
- case 0:
- info = "Vernal";
- break;
- case 1:
- info = "Midsummer";
- break;
- case 2:
- info = "Mabon";
- break;
- case 3:
- info = "Yule";
- break;
- }
- DaysList.Add(new LunisolarArrayElement(element, info, 0));
- //DaysList[i] = new LunisolarArrayElement(element, info, 0);
- //DaysList[i, 0] = element.DayOfYear;
- //DaysList[i, 1] = element;
- //DaysList[i, 2] = info;
- //DaysList[i, 3] = true;
- i++;
- }
- ////Console.WriteLine("months");
- foreach (DateTime element in months)
- {
- //count++;
- ////Console.WriteLine(element);
- //DaysList[i, 0] = element.DayOfYear;
- //DaysList[i, 1] = element;
- //DaysList[i, 2] = "New Moon " + m;
- //DaysList[i, 3] = false;
- info = "moon";
- DaysList.Add(new LunisolarArrayElement(element, info, m));
- m++;
- i++;
- }
- DateTime dt = new DateTime(gregyear, 1, 1, 0, 0, 0);
- DateTime newyear = dt;
- //somehow make the four points of the year, as well as the year boundary round so that they are month boundaries
- DateTime new_year_eve = new DateTime(gregyear, 12, 31, 0, 0, 0);
- int yeardays = new_year_eve.DayOfYear;
- //Sort array DaysList by element.dayoftheyear
- int manuyear = gregyear;
- if (manuyear > 0)
- {
- manuyear += 10000;
- }
- else
- {
- manuyear += 10001;
- }
- foreach (var item in DaysList)
- {
- //Console.WriteLine(item);
- }
- //Console.WriteLine(" xxxxxxxxxxxxx ");
- //List<LunisolarArrayElement>.Sort(DaysList);
- DaysList.Sort();
- foreach (var item in DaysList)
- {
- //Console.WriteLine(item);
- }
- //Console.WriteLine(" xxxxxxxxxxxxx ");
- bool complete = false;
- i = 0;
- LunisolarArrayElement[] QuarterArray = new LunisolarArrayElement[4];
- int q = 0;
- bool isquarter;
- int quarter = 4;
- int enditem = DaysList.Count - 1;
- LunisolarArrayElement LastItem = DaysList[enditem];
- if (LastItem.info == "Yule")
- {
- quarter = 3;
- DaysList[enditem - 1].info = "Yule";
- DaysList[enditem - 1].number = 0;
- DaysList.RemoveAt(enditem);
- }
- while (complete == false)
- {
- isquarter = DaysList[i].isquarter();
- //check last item, if it is Yule then fix it and set quarter to 3
- if (isquarter == true)
- {
- LunisolarArrayElement Fudge = LunisolarFudge(DaysList[i - 1].getdate(), DaysList[i].getdate(), DaysList[i + 1].getdate());
- DaysList[i].date = Fudge.date;
- int change = (int)(i + Fudge.number);
- //DaysList[change] = new LunisolarArrayElement(new DateTime(1, 1, 1, 0, 0, 0), "0", 999);
- DaysList.RemoveAt(change);
- q++;
- }
- //Console.WriteLine(DaysList[i]);
- i++;
- if ((i == DaysList.Count - 1) || (q == quarter))
- {
- complete = true;
- }
- }
- DaysList.Add(new LunisolarArrayElement(new DateTime(1, 12, 31, 0, 0, 0), "end", 999));
- DaysList.Add(new LunisolarArrayElement(new DateTime(1, 12, 31, 0, 0, 0), "end", 999));
- DaysList.Add(new LunisolarArrayElement(new DateTime(1, 12, 31, 0, 0, 0), "end", 999));
- DaysList.Add(new LunisolarArrayElement(new DateTime(1, 12, 31, 0, 0, 0), "end", 999));
- //Array.Sort(DaysList);
- DaysList.Sort();
- foreach (var item in DaysList)
- {
- //Console.WriteLine(item);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //DaysList.Insert(0, DaysList[10]);
- Dictionary<double, int> monthlengths = new Dictionary<double, int>();
- double month = 1;
- monthlengths.Add(1, 0);
- monthlengths.Add(2, 0);
- monthlengths.Add(3, 0);
- monthlengths.Add(3.5, 0);
- monthlengths.Add(4, 0);
- monthlengths.Add(5, 0);
- monthlengths.Add(6, 0);
- monthlengths.Add(6.5, 0);
- monthlengths.Add(7, 0);
- monthlengths.Add(8, 0);
- monthlengths.Add(9, 0);
- monthlengths.Add(9.5, 0);
- monthlengths.Add(10, 0);
- monthlengths.Add(11, 0);
- monthlengths.Add(12, 0);
- monthlengths.Add(12.5, 0);
- monthlengths.Add(13, 0);
- i = 0;
- if (DaysList[i].dayoftheyear() > 5)
- {
- LunisolarArrayElement insert = new LunisolarArrayElement(newyear, "Capricorn", 1);
- DaysList.Insert(i, insert);
- }
- else
- {
- DaysList[i].date = newyear;
- DaysList[i].info = "Capricorn";
- DaysList[i].number = 1;
- }
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Aquarius";
- DaysList[i].number = 2;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Pisces";
- DaysList[i].number = 3;
- //Console.WriteLine(DaysList[i]);
- i++; //i=3;
- //Console.WriteLine(i);
- if (DaysList[i].info == "moon")
- {
- DaysList[i].info = "Cetus";
- DaysList[i].number = 3.5;
- //Console.WriteLine(DaysList[i]);
- i++;
- }
- DaysList[i].info = "Aries";
- DaysList[i].number = 4;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Taurus";
- DaysList[i].number = 5;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Gemini";
- DaysList[i].number = 6;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- if (DaysList[i].info == "moon")
- {
- DaysList[i].info = "Lynx";
- DaysList[i].number = 6.5;
- //Console.WriteLine(DaysList[i]);
- i++;
- }
- DaysList[i].info = "Cancer";
- DaysList[i].number = 7;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Leo";
- DaysList[i].number = 8;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Virgo";
- DaysList[i].number = 9;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- if (DaysList[i].info == "moon")
- {
- DaysList[i].info = "Centaurus";
- DaysList[i].number = 9.5;
- //Console.WriteLine(DaysList[i]);
- i++;
- }
- DaysList[i].info = "Libra";
- DaysList[i].number = 10;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Scorpio";
- DaysList[i].number = 11;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- DaysList[i].info = "Saggittarius";
- DaysList[i].number = 12;
- //Console.WriteLine(DaysList[i]);
- i++;
- //Console.WriteLine(i);
- if (DaysList[i].info == "moon")
- {
- DaysList[i].info = "Opciucius";
- DaysList[i].number = 12.5;
- //Console.WriteLine(DaysList[i]);
- i++;
- }
- DaysList[i].info = "Mannus";
- DaysList[i].number = 13;
- //Console.WriteLine(DaysList[i]);
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///
- //Console.WriteLine("new list");
- foreach (var item in DaysList)
- {
- //Console.WriteLine(item);
- }
- LunisolarDay[] YearArray = new LunisolarDay[yeardays];
- i = 0;
- int day = 1;
- month = 1;
- int m_int = 1;
- int moonage;
- string feast = "Feast of " + DaysList[i].info;
- while (i < yeardays)
- {
- moonage = (int)MoonAge(dt);
- YearArray[i] = new LunisolarDay(dt, manuyear, month, day, feast, moonage);
- dt = dt.AddDays(1);
- day++;
- i++;
- monthlengths[month]++;
- feast = "0";
- //Console.WriteLine("DaysList[0]");
- //Console.WriteLine(DaysList[0]);
- //Console.WriteLine("m_int = " + m_int);
- //Console.WriteLine("Days List");
- foreach (var item in DaysList)
- {
- //Console.WriteLine(item);
- }
- //Console.WriteLine("if (" + dt + " == " + DaysList[m_int].date + ")");
- if (dt == DaysList[m_int].date)
- {
- day = 1;
- //Console.WriteLine("month before " + month);
- month = DaysList[m_int].number;
- //Console.WriteLine("month after " + month);
- //Console.WriteLine("m_int");
- //Console.WriteLine(m_int);
- m_int++;
- if(m_int > 12)
- {
- m_int = 0; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- }
- if (YearArray[i - 1].feast == "none") //out of array bounds exception
- {
- YearArray[i - 1].feast = "Sabbath of Doors";
- }
- }
- }
- //Console.WriteLine(monthlengths);
- LunisolarYear CreatedYear = new LunisolarYear(YearArray, monthlengths);
- return CreatedYear;
- }
- public static LunisolarArrayElement LunisolarFudge(DateTime PreMoon, DateTime Solar, DateTime PostMoon)
- {
- Object[] ReturnedArray = new Object[5];
- int intercalation = 0;
- double negative = (Solar - PreMoon).TotalDays;
- double positive = (PostMoon - Solar).TotalDays;
- int direction;
- if (negative > positive)
- {
- direction = 1;
- intercalation = (int)positive;
- }
- else
- {
- direction = -1;
- intercalation = (int)negative;
- }
- //Console.WriteLine("negative is " + negative);
- //Console.WriteLine("positive is " + positive);
- //Console.WriteLine("direction: " + direction);
- //Console.WriteLine("magnitude is " + intercalation);
- DateTime returndate;
- string returninfo = "0";
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- if (intercalation >= 5)
- {
- returndate = Solar;
- returninfo = "Solar";
- }
- else if (direction == 1)
- {
- returndate = PostMoon;
- returninfo = "PostMoon";
- }
- else
- {
- returndate = PreMoon;
- returninfo = "PreMoon";
- }
- //ReturnedArray[1] = direction;
- //ReturnedArray[3] = intercalation;
- //return ReturnedArray;
- ///return ReturnedArray[0];
- ///retur
- return new LunisolarArrayElement(returndate, returninfo, direction);
- }
- public static DateTime Monthround(DateTime quarterpoint)
- {
- DateTime beginning = quarterpoint;
- return beginning;
- }
- public static MannicDay[] MannicYear(int year, string calendar)
- {
- ////Console.WriteLine("Hello World!");
- ////Console.WriteLine("We are going to convert a date from the gregorian calendar to the Mannic Calendar");
- bool British = false;
- if (calendar == "British")
- {
- British = true;
- }
- /*In England until 1751 the year began on March 25 and used the Julian calendar
- * In England and Wales, the legal year 1751 was a short year of 282 days, running from 25 March to 31 December. 1752 began on 1 January.
- * Wednesday 2 September 1752 was followed by Thursday 14 September 1752.[c] The year 1752 was thus a short year (355 days) as well.*/
- bool Swedish = false;
- if (calendar == "Swedish")
- {
- Swedish = true;
- }
- /*
- * In Sweden there was a complicated transition from the Julian to the Gregorian Calendar
- * From 1700-1753 there was a complex date conversion, before then it was Julian, after was Gregorian
- **/
- //dt = new DateTime(2018, 7, 24);
- ////Console.WriteLine("This is our sample date to start");
- ////Console.WriteLine(dt.ToString());
- ////Console.WriteLine(dt.DayOfYear);
- //int year = dt.Year;
- ////Console.WriteLine(year);
- //MannicDay[] YearArray = new MannicDay[355];
- DateTime Vernal;
- DateTime Midsummer;
- DateTime Mabon;
- DateTime LastJulian = new DateTime(1582, 10, 4, 0, 0, 0);
- DateTime FirstGregorian = new DateTime(1582, 10, 15, 0, 0, 0);
- DateTime Yule;
- bool Gregory = false;
- if ((year == 1582) && (calendar == "?"))
- {
- Gregory = true;
- }
- if (Gregory == true)
- {
- //MannicDay[] YearArray = new MannicDay[355];
- //1582 had 355 days, not 365
- Vernal = new DateTime(1582, 03, 11, 0, 09, 0);
- Midsummer = new DateTime(1582, 06, 12, 1, 37, 0);
- Mabon = new DateTime(1582, 09, 13, 12, 47, 0);
- Yule = new DateTime(1582, 12, 22, 2, 0, 0);
- }
- else
- {
- DateTime[] FourPoints = Points(year, calendar);
- Vernal = FourPoints[0];
- Midsummer = FourPoints[1];
- Mabon = FourPoints[2];
- Yule = FourPoints[3];
- }
- ////Console.WriteLine("Printing Vernal Midsummer Mabon and Yule");
- ////Console.WriteLine(Vernal);
- ////Console.WriteLine(Midsummer);
- ////Console.WriteLine(Mabon);
- ////Console.WriteLine(Yule);
- ////Console.WriteLine((Yule - Mabon).TotalDays);
- int winter = Vernal.DayOfYear - 1;
- int spring = (int)(Midsummer - Vernal).TotalDays;
- int summer = (int)(Mabon - Midsummer).TotalDays;
- int fall = (int)(Yule - Mabon).TotalDays;
- ////Console.WriteLine("days in fall");
- ////Console.WriteLine(fall);
- if (Gregory == true)
- {
- fall -= 9;
- }
- DateTime newyeareve = new DateTime(year, 12, 31);
- int intercalary = (int)(newyeareve - Yule).TotalDays;
- ////Console.WriteLine("Winter " + winter + " spring " + spring + " summer " + summer + " fall " + fall + " intercalary " + intercalary);
- // other important numbers
- //int preEaster = (int)(Easter - Vernal).TotalDays;
- //int preHannukkah = (int)(HannukahBeginning - Mabon).TotalDays;
- //int preThanksgiving = (int)(Thanksgiving - Mabon).TotalDays;
- int Cap = 0;
- int Aqua = 0;
- int Pis = 0;
- int Ari = 0;
- int Tau = 0;
- int Gem = 0;
- int Can = 0;
- int Leo = 0;
- int Vir = 0;
- int Lib = 0;
- int Sco = 0;
- int Sag = 0;
- int Manu = 0;
- //days short in season are taken from first month
- //extra days in a season are put in the last month
- int wintersmudge = winter - 90;
- if (wintersmudge < 0)
- {
- Cap = wintersmudge;
- }
- else
- {
- Pis = wintersmudge;
- }
- int springsmudge = spring - 90;
- if (springsmudge < 0)
- {
- Ari = springsmudge;
- }
- else
- {
- Gem = springsmudge;
- }
- int summersmudge = summer - 90;
- if (summersmudge < 0)
- {
- Can = summersmudge;
- }
- else
- {
- Vir = summersmudge;
- }
- int fallsmudge = fall - 90;
- if (fallsmudge < 0)
- {
- Lib = fallsmudge;
- }
- else
- {
- Sag = fallsmudge;
- }
- Cap += 30;
- Aqua = 30;
- Pis += 30;
- Ari += 30;
- Tau = 30;
- Gem += 30;
- Can += 30;
- Leo = 30;
- Vir += 30;
- Lib += 30;
- Sco = 30;
- Sag += 30;
- Manu = intercalary;
- ////Console.WriteLine("Cap");
- ////Console.WriteLine(Cap);
- ////Console.WriteLine("Aqua");
- ////Console.WriteLine(Aqua);
- ////Console.WriteLine("Pis");
- ////Console.WriteLine(Pis);
- ////Console.WriteLine("Ari");
- ////Console.WriteLine(Ari);
- ////Console.WriteLine("Tau");
- ////Console.WriteLine(Tau);
- ////Console.WriteLine("Gem");
- ////Console.WriteLine(Gem);
- ////Console.WriteLine("Can");
- ////Console.WriteLine(Can);
- ////Console.WriteLine("Leo");
- ////Console.WriteLine(Leo);
- ////Console.WriteLine("Vir");
- ////Console.WriteLine(Vir);
- ////Console.WriteLine("Lib");
- ////Console.WriteLine(Lib);
- ////Console.WriteLine("Sco");
- ////Console.WriteLine(Sco);
- ////Console.WriteLine("Sag");
- ////Console.WriteLine(Sag);
- ////Console.WriteLine("Manu");
- ////Console.WriteLine(Manu);
- int yeardays;
- yeardays = newyeareve.DayOfYear;
- ////Console.WriteLine("how many days in the year");
- ////Console.WriteLine(yeardays);
- //yeardays = Cap + Aqua + Pis + Ari + Tau + Gem + Can + Leo + Vir + Lib + Sco + Sag + Manu;
- if (Gregory == true)
- {
- ////Console.WriteLine("1582 yeardays calculated");
- ////Console.WriteLine(yeardays);
- yeardays = 355;
- }
- int holidays = 1 + (spring % 30) + (summer % 30) + (fall % 30) + Manu;
- ////Console.WriteLine(Cap);
- ////Console.WriteLine(Aqua);
- ////Console.WriteLine(Pis);
- ////Console.WriteLine(Ari);
- ////Console.WriteLine(Tau);
- ////Console.WriteLine(Gem);
- ////Console.WriteLine(Can);
- ////Console.WriteLine(Leo);
- ////Console.WriteLine(Vir);
- ////Console.WriteLine(Lib);
- ////Console.WriteLine(Sco);
- ////Console.WriteLine(Sag);
- ////Console.WriteLine(Manu);
- ////Console.WriteLine(yeardays);
- ////Console.WriteLine(holidays);
- MannicDay[] YearArray = new MannicDay[yeardays];
- int i = 0;
- int month = 1;
- int day = 1;
- string feast = "none";
- int monthdays = Cap;
- //filling the array with days
- DateTime Gregorian = new DateTime(year, 1, 1);
- while (i < yeardays)
- {
- //getting inputs
- //public MannicDay (DateTime Gregorian, int dayoftheyear, int year, int month, int day)
- int dayoftheyear = i + 1;
- //Gregorian Calendar dependent dates
- if ((Gregorian.Month == 12) && (Gregorian.Day == 25))
- {
- feast = "Gregorian Christmas";
- }
- //Mannic feasts/Holidays
- if (month == 13)
- {
- switch (day)
- {
- case 1:
- feast = "1st Blessing of Manu";
- break;
- case 2:
- feast = "2nd Blessing of Manu";
- break;
- case 3:
- feast = "3rd Blessing of Manu";
- break;
- case 5:
- feast = "Christmas of Manu";
- break;
- default:
- feast = (day + "th Blessing of Manu");
- break;
- }
- }
- if (day == 1)
- {
- switch (month)
- {
- case 1:
- feast = "Feast of Capricorn"; break;
- case 2:
- feast = "Feast of Aquarius"; break;
- case 3:
- feast = "Feast of Pisces"; break;
- case 4:
- feast = "Feast of Aries"; break;
- case 5:
- feast = "Feast of Taurus"; break;
- case 6:
- feast = "Feast of Gemini"; break;
- case 7:
- feast = "Feast of Cancer"; break;
- case 8:
- feast = "Feast of Leo"; break;
- case 9:
- feast = "Feast of Virgo"; break;
- case 10:
- feast = "Feast of Libra"; break;
- case 11:
- feast = "Feast of Scorpio"; break;
- case 12:
- feast = "Feast of Saggittarius"; break;
- case 13:
- feast = "Feast of Manu"; break;
- }
- }
- if ((monthdays < 30) && (day == monthdays) && (month < 13))
- {
- feast = "Sabbath of Doors";
- }
- if (Gregorian == newyeareve)
- {
- feast = "Feast of Yemo";
- }
- if (day > 30)
- {
- int ordinal = day - 30;
- string monthname = "Capricorn";
- switch (month)
- {
- case 1:
- monthname = "Capricorn"; break;
- case 2:
- monthname = "Aquarius"; break;
- case 3:
- monthname = "Pisces"; break;
- case 4:
- monthname = "Aries"; break;
- case 5:
- monthname = "Taurus"; break;
- case 6:
- monthname = "Gemini"; break;
- case 7:
- monthname = "Cancer"; break;
- case 8:
- monthname = "Leo"; break;
- case 9:
- monthname = "Virgo"; break;
- case 10:
- monthname = "Libra"; break;
- case 11:
- monthname = "Scorpio"; break;
- case 12:
- monthname = "Saggittarius"; break;
- case 13:
- monthname = "Mannus"; break;
- }
- switch (ordinal)
- {
- case 1:
- feast = ("1st Blessing of " + monthname);
- break;
- case 2:
- feast = ("2nd Blessing of " + monthname);
- break;
- case 3:
- feast = ("3rd Blessing of " + monthname);
- break;
- default:
- feast = (ordinal + "th Blessing of " + monthname);
- break;
- }
- }
- if ((month == 12) && (day == monthdays))
- {
- feast = "Eve of the Solstice";
- }
- //initialize object
- YearArray[i] = new MannicDay(Gregorian, dayoftheyear, year, month, day, feast);
- ////Console.WriteLine(YearArray[i].ToString());
- //move calendar forward
- day++;
- if (month == 13)
- {
- }
- else if (monthdays < day)
- {
- day = 1;
- month++;
- switch (month)
- {
- case 1:
- monthdays = Cap; break;
- case 2:
- monthdays = Aqua; break;
- case 3:
- monthdays = Pis; break;
- case 4:
- monthdays = Ari; break;
- case 5:
- monthdays = Tau; break;
- case 6:
- monthdays = Gem; break;
- case 7:
- monthdays = Can; break;
- case 8:
- monthdays = Leo; break;
- case 9:
- monthdays = Vir; break;
- case 10:
- monthdays = Lib; break;
- case 11:
- monthdays = Sco; break;
- case 12:
- monthdays = Sag; break;
- case 13:
- monthdays = Manu; break;
- }
- }
- //reset variables
- if ((Gregory == true) && (Gregorian == LastJulian))
- {
- Gregorian = FirstGregorian;
- }
- else { Gregorian = Gregorian.AddDays(1); }
- feast = "none";
- i++;
- }
- //returning date
- return YearArray;
- //YearArray
- /*
- int i = 0;
- int month = 1;
- int day = 1;
- string feast = "none";
- */
- }
- public static DateTime roundtomidnight(DateTime dt)
- {
- int year = dt.Year;
- int month = dt.Month;
- int day = dt.Day;
- int hour = dt.Hour;
- int minute = dt.Minute;
- if (hour > 12)
- {
- day++;
- }
- DateTime rounded = new DateTime(year, month, day, 0, 0, 0);
- return rounded;
- }
- //https://www.codeproject.com/Articles/100174/Calculate-and-Draw-Moon-Phase Got this code from here
- public static int JulianDate(int d, int m, int y)
- {
- int mm, yy;
- int k1, k2, k3;
- int j;
- yy = y - (int)((12 - m) / 10);
- mm = m + 9;
- if (mm >= 12)
- {
- mm = mm - 12;
- }
- k1 = (int)(365.25 * (yy + 4712));
- k2 = (int)(30.6001 * mm + 0.5);
- k3 = (int)((int)((yy / 100) + 49) * 0.75) - 38;
- // 'j' for dates in Julian calendar:
- j = k1 + k2 + d + 59;
- if (j > 2299160)
- {
- // For Gregorian calendar:
- j = j - k3; // 'j' is the Julian date at 12h UT (Universal Time)
- }
- return j;
- }
- public static double MoonAge(DateTime date)
- {
- int day = date.Day;
- int month = date.Month;
- int year = date.Year;
- return MoonAge(day, month, year);
- }
- public static double MoonAge(int d, int m, int y)
- {
- int j = JulianDate(d, m, y);
- //Calculate the approximate phase of the moon
- var ip = (j + 4.867) / 29.53059;
- ip = ip - Math.Floor(ip);
- //After several trials I've seen to add the following lines,
- //which gave the result was not bad
- double ag;
- if (ip < 0.5)
- ag = ip * 29.53059 + 29.53059 / 2;
- else
- ag = ip * 29.53059 - 29.53059 / 2;
- // Moon's age in days
- ag = Math.Floor(ag) + 1;
- return ag;
- }
- public static DateTime[] Moons(int year)
- {
- DateTime[] MoonsArray = new DateTime[13];
- int i = 0;
- int j = 0;
- DateTime date = new DateTime(year, 1, 1, 0, 0, 0);
- DateTime newyear = new DateTime(year, 12, 31, 0, 0, 0);
- int yeardays = newyear.DayOfYear;
- while (i < yeardays)
- {
- if (MoonAge(date) == 1)
- {
- MoonsArray[j] = date;
- j++;
- }
- date = date.AddDays(1);
- i++;
- }
- return MoonsArray;
- }
- public static DateTime CalculateDate(double val, string calendar, int date)
- {
- double ut;
- int jdn;
- int year;
- int month;
- int day;
- int hour;
- int minute;
- bool julian;
- int x;
- int z;
- int m;
- int d;
- int y;
- int daysPer400Years = 146097;
- int fudgedDaysPer4000Years = 1460970 + 31;
- val += 0.5; // Convert astronomical JDN to chronological
- jdn = (int)Math.Floor(val);
- ut = val - jdn;
- //julian = (jdn <= DefineConstants.LASTJULJDN);
- switch (calendar)
- {
- case "Gregorian": //gregorian
- julian = false;
- break;
- case "Julian": //julian
- julian = true;
- break;
- // possibly add more calendars as we go along, converting them to Gregorian first and then to Mannic
- case "British": //British Old Style Calendar
- //break;
- case "Swedish": //Swedish
- //break;
- default: //julian gregorian unknown
- if (date <= 1582)
- {
- julian = true;
- }
- else
- {
- julian = false;
- }
- break;
- }
- x = jdn + 68569;
- if (julian == true)
- {
- x += 38;
- daysPer400Years = 146100;
- fudgedDaysPer4000Years = 1461000 + 1;
- }
- z = 4 * x / daysPer400Years;
- x = x - (daysPer400Years * z + 3) / 4;
- y = 4000 * (x + 1) / fudgedDaysPer4000Years;
- x = x - 1461 * y / 4 + 31;
- m = 80 * x / 2447;
- d = x - 2447 * m / 80;
- x = m / 11;
- m = m + 2 - 12 * x;
- y = 100 * (z - 49) + y + x;
- year = (int)y;
- month = (int)m;
- day = (int)d;
- if (year <= 0) // adjust BC years
- {
- year--;
- }
- hour = (int)(ut * 24);
- minute = (int)((ut * 24 - hour) * 60); // Accurate to about 15 minutes c. 2000 CE.
- //retval.Format("%02d-%02d-%4d %02d:%02d GMT", day, month, year, hour, minute);
- DateTime retval = new DateTime(year, month, day, hour, minute, 0);
- return (retval);
- }
- public static DateTime[] Points(int year, string calendar)
- {
- DateTime[] FourPoints = PointsWithTime(year, calendar);
- DateTime[] FixedTime = new DateTime[4];
- FixedTime[0] = roundtomidnight(FourPoints[0]);
- FixedTime[1] = roundtomidnight(FourPoints[1]);
- FixedTime[2] = roundtomidnight(FourPoints[2]);
- FixedTime[3] = roundtomidnight(FourPoints[3]);
- return FixedTime;
- }
- public static DateTime[] PointsWithTime(int input_year, string calendar)
- {
- DateTime[] points = new DateTime[4];
- double m;
- double ve;
- double ss;
- double ae;
- double ws;
- m = ((double)input_year - 2000.0) / 1000.0;
- ve = 2451623.80984 + 365242.37404 * m + 0.05169 * m * m - 0.00411 * m * m * m - 0.00057 * m * m * m * m;
- points[0] = CalculateDate(ve, calendar, input_year);
- ss = 2451716.56767 + 365241.62603 * m + 0.00325 * m * m + 0.00888 * m * m * m - 0.00030 * m * m * m * m;
- points[1] = CalculateDate(ss, calendar, input_year);
- ae = 2451810.21715 + 365242.01767 * m - 0.11575 * m * m + 0.00337 * m * m * m + 0.00078 * m * m * m * m;
- points[2] = CalculateDate(ae, calendar, input_year);
- ws = 2451900.05952 + 365242.74049 * m - 0.06223 * m * m - 0.00823 * m * m * m + 0.00032 * m * m * m * m;
- points[3] = CalculateDate(ws, calendar, input_year);
- return points;
- }
- public static string textform(int input)
- {
- string suffix;
- int end = input % 100;
- int ten = 10;
- if ((end / ten) == 1)
- {
- suffix = "th";
- }
- else
- {
- end %= 10;
- switch (end)
- {
- case 1:
- suffix = "st";
- break;
- case 2:
- suffix = "nd";
- break;
- case 3:
- suffix = "rd";
- break;
- default:
- suffix = "th";
- break;
- }
- }
- return (input + suffix);
- }
- public static MannicDay create(int year, int month, int day)
- {
- int gregyear;
- if (year > 10000)
- {
- gregyear = year - 10000;
- }
- else
- {
- gregyear = year - 10001;
- }
- //MannicDay[] CreatedYear; //= Mithralib.MannicYear(gregyear, 1);
- //MannicYear
- MannicDay[] YearArray = MannicYear(year, "?");
- int count = 0;
- int dayofyear = 0;
- foreach (MannicDay element in YearArray)
- {
- count++;
- ////Console.WriteLine($"Element #{count}: {element}");
- if ((element.month == month) && (element.day == day))
- {
- dayofyear = element.dayoftheyear;
- }
- }
- if (dayofyear == 0)
- {
- return null;
- }
- //MannicDay(DateTime Gregorian, int dayoftheyear, int year, int month, int day, string feast)
- MannicDay createdday = YearArray[dayofyear];
- return createdday;
- }
- public static DateTime Convertback(MannicDay date)
- {
- return date.Gregorian;
- }
- }
- public class MannicDay
- {
- public DateTime Gregorian;
- public int dayoftheyear;
- public int year;
- public int month;
- public int day;
- public string feast;
- public MannicDay(DateTime Gregorian, int dayoftheyear, int year, int month, int day, string feast)
- {
- this.Gregorian = Gregorian;
- this.dayoftheyear = dayoftheyear;
- if (year >= 1)
- {
- this.year = year + 10000;
- }
- else
- {
- this.year = year + 1001;
- }
- this.month = month;
- this.day = day;
- this.feast = feast;
- }
- public MannicDay()
- {
- }
- public string getmonthname()
- {
- switch (this.month)
- {
- case 1:
- return "Capricorn";
- case 2:
- return "Aquarius";
- case 3:
- return "Pisces";
- case 4:
- return "Aries";
- case 5:
- return "Taurus";
- case 6:
- return "Gemini";
- case 7:
- return "Cancer";
- case 8:
- return "Leo";
- case 9:
- return "Virgo";
- case 10:
- return "Libra";
- case 11:
- return "Scorpio";
- case 12:
- return "Saggittarius";
- case 13:
- return "Mannus";
- }
- return "?";
- }
- public string monthabbreviation()
- {
- switch (this.month)
- {
- case 1:
- return "Cap";
- case 2:
- return "Aqua";
- case 3:
- return "Pis";
- case 4:
- return "Ari";
- case 5:
- return "Tau";
- case 6:
- return "Gem";
- case 7:
- return "Can";
- case 8:
- return "Leo";
- case 9:
- return "Vir";
- case 10:
- return "Lib";
- case 11:
- return "Sco";
- case 12:
- return "Sag";
- case 13:
- return "Manu";
- }
- return "?";
- }
- public string getmonthsymbol()
- {
- switch (this.month)
- {
- case 1:
- return "♑";
- case 2:
- return "♒";
- case 3:
- return "♓️";
- case 4:
- return "♈";
- case 5:
- return "♉";
- case 6:
- return "♊";
- case 7:
- return "♋️";
- case 8:
- return "♌";
- case 9:
- return "♍";
- case 10:
- return "♎";
- case 11:
- return "♏";
- case 12:
- return "♐";
- case 13:
- return "🎄";
- }
- return "?";
- }
- public string getfeast()
- {
- return this.feast;
- }
- public bool feastbool()
- {
- if (string.Equals(this.feast, "none") == true)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public bool dayoff()
- {
- if (this.feastbool() == true)
- {
- return true;
- }
- if ((this.day % 5) == 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public DateTime getGregorian()
- {
- return this.Gregorian;
- }
- public int getmonth()
- {
- return this.month;
- }
- public int getyear()
- {
- return this.year;
- }
- public int getday()
- {
- return this.day;
- }
- public int getdayoftheyear()
- {
- return this.dayoftheyear;
- }
- public string ymd()
- {
- //return string("" + this.year + "/" + this.month + "/" + this.day);
- string output = ("" + this.year + "/" + this.month + "/" + this.day);
- return output;
- }
- public string dmy()
- {
- string output = ("" + this.day + "/" + this.month + "/" + this.year);
- return output;
- }
- public string mdy()
- {
- string output = ("" + this.month + "/" + this.day + "/" + this.year);
- return output;
- }
- public string weekday()
- {
- switch (this.day % 5)
- {
- case 1:
- return "Adonai";
- case 2:
- return "Mithra";
- case 3:
- return "Azoth";
- case 4:
- return "Oxa";
- default:
- return "Manu";
- }
- }
- override public string ToString()
- {
- string s0 = ("" + this.getdayoftheyear());
- string s1 = this.ymd();
- string s2 = this.getmonthsymbol();
- string s3 = this.getmonthname();
- string s4 = this.feast;
- string greg = this.Gregorian.ToString();
- string text = ("day " + s0 + " " + greg + " " + s1 + " " + s3 + " " + s4);
- return text;
- }
- public string display()
- {
- string weekday = this.weekday();
- int day = this.getday();
- string dayth = textform(day);
- string month = this.getmonthname();
- int year = this.getyear();
- string yearth = textform(year);
- string display = (weekday + "day " + month + " " + dayth + ", of the " + yearth + " year of Manu");
- return display;
- }
- public static string textform(int input)
- {
- string suffix;
- int end = input % 100;
- int ten = 10;
- if ((end / ten) == 1)
- {
- suffix = "th";
- }
- else
- {
- end %= 10;
- switch (end)
- {
- case 1:
- suffix = "st";
- break;
- case 2:
- suffix = "nd";
- break;
- case 3:
- suffix = "rd";
- break;
- default:
- suffix = "th";
- break;
- }
- }
- return (input + suffix);
- //MannicDay[] YearArray = MannicYear(year, 1);
- }
- }
- public class LunisolarArrayElement : IComparable<LunisolarArrayElement>
- {
- public DateTime date;
- public string info;
- public double number;
- public LunisolarArrayElement(DateTime date, string info, double number)
- {
- this.date = date;
- this.info = info;
- this.number = number;
- }
- //public int CompareTo([AllowNull] LunisolarArrayElement other)
- public int CompareTo(LunisolarArrayElement other)
- {
- return this.dayoftheyear().CompareTo(other.dayoftheyear());
- }
- public int dayoftheyear()
- {
- if (this.number == 999)
- {
- return 999;
- }
- return this.date.DayOfYear; //I want to be able to sort based on day of the year
- }
- public DateTime getdate()
- {
- return this.date;
- }
- public string getinfo()
- {
- return this.info;
- }
- public bool isquarter()
- {
- if (this.info == "0")
- {
- return false;
- }
- if (this.info == "moon")
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public override string ToString()
- {
- string objectinfo;
- objectinfo = (" " + this.dayoftheyear() + " " + this.date + " " + this.info + " number: " + this.number);
- return objectinfo;
- }
- }
- public class LunisolarYear
- {
- public LunisolarDay[] DaysArray;
- public Dictionary<double, int> monthdays;
- public LunisolarYear(LunisolarDay[] DaysArray, Dictionary<double, int> monthdays)
- {
- this.DaysArray = DaysArray;
- this.monthdays = monthdays;
- }
- }
- public class LunisolarDay
- {
- //DateTime Gregorian, int dayoftheyear, int year, int month, int day, string feast)
- public DateTime Gregorian;
- public int year;
- public double month;
- public int day;
- public string feast;
- public double moonage;
- public LunisolarDay(DateTime Gregorian, int year, double month, int day, string feast, double moonage)
- {
- this.Gregorian = Gregorian;
- //this.dayoftheyear = Gregorian.DayOfYear;
- // dt, manuyear, month, day, feast, moonage
- this.year = year;
- this.month = month;
- this.day = day;
- this.feast = feast;
- this.moonage = moonage;
- //this.month_name = month_name;
- }
- public string monthnames()
- {
- string[] weekDays = new string[] { "Capricorn", "Aquarius", "Pisces", "Cetus", "Aries", "Taurus", "Gemini", "Lynx", "Cancer", "Leo", "Virgo", "Centaurus", "Libra", "Scorpio", "Saggittarius", "Opciucius", "Mannus" };
- //string[] names =
- switch (this.month)
- {
- case 1:
- return "Capricorn";
- case 2:
- return "Aquarius";
- case 3:
- return "Pisces";
- case 3.5:
- return "Cetus";
- case 4:
- return "Aries";
- case 5:
- return "Taurus";
- case 6:
- return "Gemini";
- case 6.5:
- return "Lynx";
- case 7:
- return "Cancer";
- case 8:
- return "Leo";
- case 9:
- return "Virgo";
- case 9.5:
- return "Centaurus";
- case 10:
- return "Libra";
- case 11:
- return "Scorpio";
- case 12:
- return "Saggittarius";
- case 12.5:
- return "Ophiucius";
- case 13:
- return "Mannus";
- default:
- return "unknown";
- }
- }
- public string ymd()
- {
- string ymd = this.year + "/" + this.month + "/" + this.day;
- return ymd;
- }
- override public string ToString()
- {
- int dayoftheyear = this.Gregorian.DayOfYear;
- DateTime date = this.Gregorian;
- string ymd = this.ymd();
- string text = this.display();
- string returnstring = dayoftheyear + " " + date + " " + ymd + " " + text;
- return returnstring;
- }
- public string display()
- {
- string weekday = this.weekday();
- int day = this.day;
- string dayth = textform(day);
- string monthname = this.monthnames();
- int year = this.year;
- string yearth = textform(year);
- string day_info;
- if (this.feast == "0")
- {
- day_info = weekday + "day";
- }
- else
- {
- day_info = this.feast;
- }
- string display = (day_info + " " + monthname + " " + dayth + ", of the " + yearth + " year of Manu");
- return display;
- }
- public string weekday()
- {
- switch (this.day % 5)
- {
- case 1:
- return "Adonai";
- case 2:
- return "Mithra";
- case 3:
- return "Azoth";
- case 4:
- return "Oxa";
- default:
- return "Manu";
- }
- }
- public static string textform(int input)
- {
- string suffix;
- int end = input % 100;
- int ten = 10;
- if ((end / ten) == 1)
- {
- suffix = "th";
- }
- else
- {
- end %= 10;
- switch (end)
- {
- case 1:
- suffix = "st";
- break;
- case 2:
- suffix = "nd";
- break;
- case 3:
- suffix = "rd";
- break;
- default:
- suffix = "th";
- break;
- }
- }
- return (input + suffix);
- //MannicDay[] YearArray = MannicYear(year, 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement