/// <summary> /// Generate a string for this BadiDate based on the template given. /// </summary> /// <param name="date"></param> /// <param name="template"></param> /// <returns></returns> public string FillTemplate(BadiDate date, string template = null) { if (string.IsNullOrWhiteSpace(template)) { template = "{yearOfEra}-{month}-{day}"; } string answer1 = template; string answer2; bool repeat; do { answer2 = _tokenReplacer.ReplaceTokens(answer1, AvailableReplacements(date)); repeat = answer2.Contains("{") && answer2 != answer1; if (repeat) { answer1 = answer2; } } while (repeat); return(answer2); }
public void CreateDate_FromBadiLocalDate() { var d1 = new BadiDate(180, 19, 1); var d2 = new BadiDate(d1.LocalDate); d2.Month.ShouldEqual(19); }
public void DatesAreEquals(int gYear, int gMonth, int gDay, int bYear, int bMonth, int bDay) { var wDate2 = new BadiDate(new LocalDate(gYear, gMonth, gDay)); var wDate3 = new BadiDate(new DateTime(gYear, gMonth, gDay)); Assert.True(wDate3.Equals(wDate2)); wDate3.ShouldEqual(new BadiDate(bYear, bMonth, bDay)); }
public void Plus() { var w1 = new BadiDate(180, 8, 10); w1.PlusDays(2).Day.ShouldEqual(12); w1.PlusDays(20).Day.ShouldEqual(11); w1.PlusDays(-9).ToString().ShouldEqual("180-8-1"); w1.PlusYears(2).ToString().ShouldEqual("182-8-10"); w1.PlusYears(-2).ToString().ShouldEqual("178-8-10"); }
public void CreateDateNow() { var b = new BadiDate(); var g = DateTime.Today; var g2 = b.WithCalendar(CalendarSystem.Gregorian); g2.Year.ShouldEqual(g.Year); g2.Month.ShouldEqual(g.Month); g2.Day.ShouldEqual(g.Day); }
public void ToLocalDate(int gYear, int gMonth, int gDay, int bYear, int bMonth, int bDay) { var wDate = new BadiDate(bYear, bMonth, bDay); var localDate = wDate.LocalDate.WithCalendar(CalendarSystem.Gregorian); localDate.Year.ShouldEqual(gYear); localDate.Month.ShouldEqual(gMonth); localDate.Day.ShouldEqual(gDay); var dateTime = wDate.DateTime; dateTime.Year.ShouldEqual(gYear); dateTime.Month.ShouldEqual(gMonth); dateTime.Day.ShouldEqual(gDay); }
public void GeneralConversion(int gYear, int gMonth, int gDay, int bYear, int bMonth, int bDay) { // create in the Badíʿ calendar var wDate = new BadiDate(bYear, bMonth, bDay); // convert to gregorian and check var gDate = wDate.WithCalendar(CalendarSystem.Gregorian); gDate.Year.ShouldEqual(gYear); gDate.Month.ShouldEqual(gMonth); gDate.Day.ShouldEqual(gDay); // convert from a LocalDate var wDate2 = new BadiDate(new LocalDate(gYear, gMonth, gDay)); wDate2.YearOfEra.ShouldEqual(bYear); wDate2.Month.ShouldEqual(bMonth); wDate2.Day.ShouldEqual(bDay); }
static void Main(string[] args) { Console.WriteLine($"Today is {new BadiDate().ToString()}"); var d1 = LocalDate.FromDateTime(DateTime.Now); Console.WriteLine($"Today is {d1.ToString()}"); var w1 = new BadiDate(d1); Console.WriteLine($"Today is {w1.ToString()}"); var w2 = new BadiDate(); var d2 = w2.DateTime; Console.WriteLine($"{w2} --> {d2}"); var date3 = new BadiDate(175, 1, 1); var gregorianDate2 = date3.PlusDays(-1).DateTime; Console.WriteLine("The day before Naw Rúz 175 is " + gregorianDate2.ToString("D")); var year174 = new BadiYearInfo(174); var listing = year174.GetSpecialDays(SpecialDayType.HolyDay_WorkSuspended | SpecialDayType.FeastDay); Console.WriteLine($"There are {listing.Count} Feast and major Holy Days in 174."); var nawRuz = year174.GetSpecialDays(SpecialDayType.HolyDay_WorkSuspended, HolyDayCode.NawRuz).First(); Console.WriteLine($"Naw Ruz was on {nawRuz.Date.ToString()}"); var dtp = new BadiNodaTime.Utility.DateTemplateProcessor(); dtp.AvailableTokens(w2).ToList().ForEach(Console.WriteLine); Console.WriteLine("\nGerman..."); var resolver = new BadiResources("de"); dtp = new BadiNodaTime.Utility.DateTemplateProcessor(resolver); dtp.AvailableTokens(w2).ToList().ForEach(Console.WriteLine); }