/// <summary>
        /// Structured using Expressions to avoid having to pre-calculate every single option for each call to format a date.
        /// Expressions are pre-compiled.
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        private Dictionary <string, CompiledExpression> AvailableReplacements(BadiDate date)
        {
            var g = date.WithCalendar(CalendarSystem.Gregorian);

            return(new List <Expression <Func <string, object> > > {
                day => date.Day,
                day00 => date.Day.Pad00(),
                day_ordinal => _resolver.GetListItem("OrdinalNames", date.Day),
                day_meaning => _resolver.GetListItem("MonthMeaning", date.Day),
                day_arabic => _resolver.GetListItem("MonthArabic", date.Day),

                weekday => date.Weekday,
                weekday00 => date.Weekday.Pad00(),
                weekday_ordinal => _resolver.GetListItem("OrdinalNames", date.Weekday),
                weekday_meaning => _resolver.GetListItem("WeekdayMeaning", date.Weekday),
                weekday_arabic => _resolver.GetListItem("WeekdayArabic", date.Weekday),

                month => date.Month,
                month00 => date.Month.Pad00(),
                month_ordinal => _resolver.GetListItem("OrdinalNames", date.Month),
                month_meaning => _resolver.GetListItem("MonthMeaning", date.Month),
                month_arabic => _resolver.GetListItem("MonthArabic", date.Month),

                element => date.Element,
                element00 => date.Element.Pad00(),
                element_meaning => _resolver.GetListItem("Elements", date.Element),

                yearOfEra => date.YearOfEra,
                yearOfEra00 => date.YearOfEra.Pad00(),

                yearOfUnity => date.YearOfUnity,
                yearOfUnity00 => date.YearOfUnity.Pad00(),
                yearOfUnity_ordinal => _resolver.GetListItem("OrdinalNames", date.YearOfUnity),
                yearOfUnity_meaning => _resolver.GetListItem("YearOfUnityMeaning", date.YearOfUnity),
                yearOfUnity_arabic => _resolver.GetListItem("YearOfUnityArabic", date.YearOfUnity),

                unity => date.Unity,
                unity00 => date.Unity.Pad00(),
                unity_ordinal => _resolver.GetListItem("OrdinalNames", date.Unity),

                allThings => date.AllThings,
                allThings00 => date.AllThings.Pad00(),
                allThings_ordinal => _resolver.GetListItem("OrdinalNames", date.AllThings),

                gregorian => new List <Expression <Func <string, object> > > {
                    // basic options... for other formats, use standard .NET or Noda Time format features

                    day => g.Day,
                    day00 => g.Day.Pad00(),

                    month => g.Month,
                    month00 => g.Month.Pad00(),
                    month_latin_short => g.ToString("MMM", CultureInfo.CreateSpecificCulture(_resolver.Language)),
                    month_latin_long => g.ToString("MMMM", CultureInfo.CreateSpecificCulture(_resolver.Language)),

                    year => g.Year,
                }.ToDictionary(e => e.Parameters[0].Name, e => new CompiledExpression(e)),
            }.ToDictionary(e => e.Parameters[0].Name, e => new CompiledExpression(e)));
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }