示例#1
0
        public object?Convert(object?[]?values, Type targetType, object?parameter, CultureInfo culture)
        {
            long ticks = long.MaxValue;

            foreach (var value in values ?? Enumerable.Empty <object?>())
            {
                if (value is DateTime dt)
                {
                    ticks = dt.Ticks;
                }
                else if (value is XmlLanguage language)
                {
                    culture = language.GetSpecificCulture();
                }
            }
            if (ticks == long.MaxValue)
            {
                return(null);
            }

            try
            {
                return(new DateTime(ticks).ToString(CalendarFormatInfo.FromCultureInfo(culture).YearMonthPattern, culture));
            }
            catch (ArgumentOutOfRangeException)
            {
                return(new DateTime(ticks).ToString("Y", CultureInfo.InvariantCulture));
            }
        }
示例#2
0
        public void TestFromCultureInfo(string cultureName, string yearMonth, string componentThree, string componentTwo, string componentOne)
        {
            var result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));

            Assert.Equal(yearMonth, result.YearMonthPattern);
            Assert.Equal(componentOne, result.ComponentOnePattern);
            Assert.Equal(componentTwo, result.ComponentTwoPattern);
            Assert.Equal(componentThree, result.ComponentThreePattern);
        }
示例#3
0
 public void SettingYearPatternOfMultupleCultures()
 {
     string[] cultureNames = { "en-001", "en-150" };
     CalendarFormatInfo.SetYearPattern(cultureNames, "B");
     foreach (var cultureName in cultureNames)
     {
         var result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));
         Assert.Equal("B", result.ComponentThreePattern);
     }
 }
示例#4
0
 public void SettingDayOfWeekStyleOfMultupleCultures()
 {
     string[] cultureNames = { "en-001", "en-150" };
     CalendarFormatInfo.SetDayOfWeekStyle(cultureNames, new CalendarFormatInfo.DayOfWeekStyle("Z", "@", true));
     foreach (var cultureName in cultureNames)
     {
         var result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));
         Assert.Equal("d MMM", result.ComponentOnePattern);
         Assert.Equal("Z@", result.ComponentTwoPattern);
     }
 }
示例#5
0
        public void ResettingDayOfWeekStyle()
        {
            const string cultureName = "en-001";

            CalendarFormatInfo.SetDayOfWeekStyle(cultureName, new CalendarFormatInfo.DayOfWeekStyle("Z", "@", true));
            CalendarFormatInfo.ResetDayOfWeekStyle(cultureName);
            var result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));

            Assert.Equal("d MMM", result.ComponentOnePattern);
            Assert.Equal("ddd,", result.ComponentTwoPattern);
        }
示例#6
0
        public void SettingYearPattern()
        {
            const string cultureName = "en-001";

            CalendarFormatInfo.SetYearPattern(cultureName, "A");
            var result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));

            Assert.Equal("A", result.ComponentThreePattern);

            CalendarFormatInfo.SetYearPattern(cultureName, null);
            result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));
            Assert.Equal("yyyy", result.ComponentThreePattern);
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            long ticks = long.MaxValue;

            foreach (var value in values)
            {
                if (value is DateTime dt)
                {
                    ticks = dt.Ticks;
                }
                else if (value is XmlLanguage language)
                {
                    culture = language.GetSpecificCulture();
                }
            }
            if (ticks == long.MaxValue)
            {
                return(null);
            }

            return(new DateTime(ticks).ToString(CalendarFormatInfo.FromCultureInfo(culture).YearMonthPattern, culture));
        }