예제 #1
0
        private static GlobalizationInfo.DateFormatInfo.EraInfo GetEraInfo(CultureInfo culture, int eraNum)
        {
            var era = new GlobalizationInfo.DateFormatInfo.EraInfo
            {
                name   = culture.DateTimeFormat.GetEraName(eraNum),
                offset = 0,
                start  = null
            };
            var calendar = culture.DateTimeFormat.Calendar;

            Type type = calendar.GetType();

            if (type != typeof(GregorianCalendar))
            {
                if (type == typeof(TaiwanCalendar))
                {
                    era.offset = 0x777;
                }
                else if (type == typeof(KoreanCalendar))
                {
                    era.offset = -2333;
                }
                else if (type == typeof(ThaiBuddhistCalendar))
                {
                    era.offset = -543;
                }
                else if (type == typeof(JapaneseCalendar))
                {
                    switch (eraNum)
                    {
                    case 1:
                        era.start  = 0xdf9984200L;
                        era.offset = 0x7c4;
                        break;

                    case 2:
                        era.start  = -1357603200000L;
                        era.offset = 0x785;
                        break;

                    case 3:
                        era.start  = -1812153600000L;
                        era.offset = 0x777;
                        break;

                    case 4:
                        era.start  = null;
                        era.offset = 0x74b;
                        break;

                    default:
                        throw new InvalidOperationException("Invalid era number for JapaneseCalendar: " + eraNum.ToString());
                    }
                }
            }
            return(era);
        }
예제 #2
0
        private static GlobalizationInfo.DateFormatInfo.EraInfo GetEraInfo(CultureInfo culture, int eraNum)
        {
            var era = new GlobalizationInfo.DateFormatInfo.EraInfo {
                name   = culture.DateTimeFormat.GetEraName(eraNum),
                offset = 0,
                start  = null
            };
            var calendar = culture.DateTimeFormat.Calendar;

            Type type = calendar.GetType();

            if (type != typeof(GregorianCalendar))
            {
                if (type == typeof(TaiwanCalendar))
                {
                    era.offset = 0x777;
                }
                else if (type == typeof(KoreanCalendar))
                {
                    era.offset = -2333;
                }
                else if (type == typeof(ThaiBuddhistCalendar))
                {
                    era.offset = -543;
                }
                else if (type == typeof(JapaneseCalendar))
                {
                    switch (era.name)
                    {
                    case "令和":     // Reiwa
                        era.start  = 1556668800000L;
                        era.offset = 0x7e2;
                        break;

                    case "平成":     // Heisei
                        era.start  = 600220800000;
                        era.offset = 0x7c4;
                        break;

                    case "昭和":     // Showa
                        era.start  = -1357603200000L;
                        era.offset = 0x785;
                        break;

                    case "大正":     // Taisho
                        era.start  = -1812153600000L;
                        era.offset = 0x777;
                        break;

                    case "明治":     // Meiji
                        era.start  = null;
                        era.offset = 0x74b;
                        break;

                    default:
                        throw new InvalidOperationException("Invalid era number for JapaneseCalendar: " + eraNum.ToString());
                    }
                }
            }
            return(era);
        }