public void PosTest1()
 {
     int[] actual = new JapaneseCalendar().Eras;
     Assert.NotNull(actual);
     Assert.Equal(c_EXPECTED_ERAS.Length, actual.Length);
     Assert.Equal(c_EXPECTED_ERAS, actual);
 }
        //This function exists as a hack to prevent us from loading all of the non-gregorian
        //calendars unless they're required.
        internal Calendar GetCalendarInstanceRare(int calType)
        {
            BCLDebug.Assert(calType != Calendar.CAL_GREGORIAN, "calType!=Calendar.CAL_GREGORIAN");

            switch (calType)
            {
            case Calendar.CAL_GREGORIAN_US:                   // Gregorian (U.S.) calendar
            case Calendar.CAL_GREGORIAN_ME_FRENCH:            // Gregorian Middle East French calendar
            case Calendar.CAL_GREGORIAN_ARABIC:               // Gregorian Arabic calendar
            case Calendar.CAL_GREGORIAN_XLIT_ENGLISH:         // Gregorian Transliterated English calendar
            case Calendar.CAL_GREGORIAN_XLIT_FRENCH:          // Gregorian Transliterated French calendar
                return(new GregorianCalendar((GregorianCalendarTypes)calType));

            case Calendar.CAL_TAIWAN:                         // Taiwan Era calendar
                return(TaiwanCalendar.GetDefaultInstance());

            case Calendar.CAL_JAPAN:                          // Japanese Emperor Era calendar
                return(JapaneseCalendar.GetDefaultInstance());

            case Calendar.CAL_KOREA:                          // Korean Tangun Era calendar
                return(KoreanCalendar.GetDefaultInstance());

            case Calendar.CAL_HIJRI:                          // Hijri (Arabic Lunar) calendar
                return(HijriCalendar.GetDefaultInstance());

            case Calendar.CAL_THAI:                           // Thai calendar
                return(ThaiBuddhistCalendar.GetDefaultInstance());

            case Calendar.CAL_HEBREW:                         // Hebrew (Lunar) calendar
                return(HebrewCalendar.GetDefaultInstance());
            }
            return(GregorianCalendar.GetDefaultInstance());
        }
 public void PosTest2()
 {
     int expected = 200;
     System.Globalization.Calendar calendar = new JapaneseCalendar();
     calendar.TwoDigitYearMax = expected;
     int actual = calendar.TwoDigitYearMax;
     Assert.Equal(expected, actual);
 }
        /// <summary>
        /// 元号の取得します。
        /// </summary>
        /// <param name="date">日付</param>
        /// <returns>元号</returns>
        public static string GetJapaneseEraString(this DateTime date)
        {
            Calendar calendar = new JapaneseCalendar();
            CultureInfo culture = new CultureInfo("ja-JP");
            culture.DateTimeFormat.Calendar = calendar;

            return date.ToString("gy", culture);
        }
Example #5
0
 private static string[] GetJapaneseEnglishEraNames()
 {
     if (GlobalizationMode.Invariant)
     {
         throw new PlatformNotSupportedException();
     }
     return(JapaneseCalendar.EnglishEraNames());
 }
Example #6
0
        private void InitializeAbbreviatedEraNames(string localeName, CalendarId calendarId)
        {
            // Note that the saAbbrevEraNames only include "AD"  We don't have localized names for other calendars available from windows
            switch (calendarId)
            {
            // For Localized Gregorian we really expect the data from the OS.
            case CalendarId.GREGORIAN:
                // Fallback for CoreCLR < Win7 or culture.dll missing
                if (this.saAbbrevEraNames == null || this.saAbbrevEraNames.Length == 0 || String.IsNullOrEmpty(this.saAbbrevEraNames[0]))
                {
                    this.saAbbrevEraNames = new String[] { "AD" };
                }
                break;

            // The rest of the calendars have constant data, so we'll just use that
            case CalendarId.GREGORIAN_US:
            case CalendarId.JULIAN:
                this.saAbbrevEraNames = new String[] { "AD" };
                break;

            case CalendarId.JAPAN:
            case CalendarId.JAPANESELUNISOLAR:
                this.saAbbrevEraNames = JapaneseCalendar.AbbrevEraNames();
                break;

            case CalendarId.HIJRI:
            case CalendarId.UMALQURA:
                if (localeName == "dv-MV")
                {
                    // Special case for Divehi
                    this.saAbbrevEraNames = new String[] { "\x0780\x002e" };
                }
                else
                {
                    this.saAbbrevEraNames = new String[] { "\x0647\x0640" };
                }
                break;

            case CalendarId.TAIWAN:
                // Get era name and abbreviate it
                this.saAbbrevEraNames = new String[1];
                if (this.saEraNames[0].Length == 4)
                {
                    this.saAbbrevEraNames[0] = this.saEraNames[0].Substring(2, 2);
                }
                else
                {
                    this.saAbbrevEraNames[0] = this.saEraNames[0];
                }
                break;

            default:
                // Most calendars just use the full name
                this.saAbbrevEraNames = this.saEraNames;
                break;
            }
        }
Example #7
0
 // Token: 0x06003006 RID: 12294 RVA: 0x000B8884 File Offset: 0x000B6A84
 internal static string[] EnglishEraNames()
 {
     EraInfo[] eraInfo = JapaneseCalendar.GetEraInfo();
     string[]  array   = new string[eraInfo.Length];
     for (int i = 0; i < eraInfo.Length; i++)
     {
         array[i] = eraInfo[eraInfo.Length - i - 1].englishEraName;
     }
     return(array);
 }
Example #8
0
        public static string ToJaCal(this DateTime d)
        {
            JapaneseCalendar jaCal = new JapaneseCalendar();

            var nengo = new string[]{ "明治", "大正", "昭和", "平成" };

            var nen = nengo[jaCal.GetEra(d) - 1] + jaCal.GetYear(d) + "年";
            var tsuki = d.Month + "月";
            var hi = d.Day + "日";

            return nen + tsuki + hi;
        }
Example #9
0
 /// <summary>初始化 <see cref="T:System.Globalization.JapaneseCalendar" /> 类的新实例。</summary>
 /// <exception cref="T:System.TypeInitializationException">由于缺少区域性信息,所以无法初始化 <see cref="T:System.Globalization.JapaneseCalendar" /> 对象。</exception>
 public JapaneseCalendar()
 {
     try
     {
         CultureInfo cultureInfo = new CultureInfo("ja-JP");
     }
     catch (ArgumentException ex)
     {
         throw new TypeInitializationException(this.GetType().FullName, (Exception)ex);
     }
     this.helper = new GregorianCalendarHelper((Calendar)this, JapaneseCalendar.GetEraInfo());
 }
Example #10
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Globalization.JapaneseCalendar" /> class.</summary>
 /// <exception cref="T:System.TypeInitializationException">Unable to initialize a <see cref="T:System.Globalization.JapaneseCalendar" /> object because of missing culture information.</exception>
 // Token: 0x06002FEF RID: 12271 RVA: 0x000B8624 File Offset: 0x000B6824
 public JapaneseCalendar()
 {
     try
     {
         new CultureInfo("ja-JP");
     }
     catch (ArgumentException innerException)
     {
         throw new TypeInitializationException(base.GetType().FullName, innerException);
     }
     this.helper = new GregorianCalendarHelper(this, JapaneseCalendar.GetEraInfo());
 }
Example #11
0
        // Summary:
        //     Returns a string DateJapan after convert
        //
        // Parameters:
        //   date:
        //     The DateTime to read. Date want to convert
        //
        // Returns:
        //    string DateJapan
        public static string GetTextDateJapan(DateTime?date)
        {
            string result = string.Empty;

            if (date.HasValue)
            {
                JapaneseCalendar calendarJp = new System.Globalization.JapaneseCalendar();
                CultureInfo      cultureJp  = new System.Globalization.CultureInfo("ja-JP", false);
                cultureJp.DateTimeFormat.Calendar = calendarJp;
                result = date.Value.ToString(ExactDateJapanEraFormat, cultureJp);
            }
            return(result);
        }
Example #12
0
 internal static string[] EnglishEraNames()
 {
     EraInfo[] eraInfo   = JapaneseCalendar.GetEraInfo();
     string[]  strArray1 = new string[eraInfo.Length];
     for (int index1 = 0; index1 < eraInfo.Length; ++index1)
     {
         string[]  strArray2    = strArray1;
         int       index2       = index1;
         EraInfo[] eraInfoArray = eraInfo;
         int       index3       = eraInfoArray.Length - index1 - 1;
         string    str          = eraInfoArray[index3].englishEraName;
         strArray2[index2] = str;
     }
     return(strArray1);
 }
Example #13
0
 // Token: 0x06002FEA RID: 12266 RVA: 0x000B82D4 File Offset: 0x000B64D4
 internal static EraInfo[] GetEraInfo()
 {
     if (JapaneseCalendar.japaneseEraInfo == null)
     {
         JapaneseCalendar.japaneseEraInfo = JapaneseCalendar.GetErasFromRegistry();
         if (JapaneseCalendar.japaneseEraInfo == null)
         {
             JapaneseCalendar.japaneseEraInfo = new EraInfo[]
             {
                 new EraInfo(4, 1989, 1, 8, 1988, 1, 8011, "平成", "平", "H"),
                 new EraInfo(3, 1926, 12, 25, 1925, 1, 64, "昭和", "昭", "S"),
                 new EraInfo(2, 1912, 7, 30, 1911, 1, 15, "大正", "大", "T"),
                 new EraInfo(1, 1868, 1, 1, 1867, 1, 45, "明治", "明", "M")
             };
         }
     }
     return(JapaneseCalendar.japaneseEraInfo);
 }
        private void InitializeAbbreviatedEraNames(string localeName, int calendarId)
        {
            switch (((CalendarId)((ushort)calendarId)))
            {
            case CalendarId.GREGORIAN:
                if (((this.saAbbrevEraNames == null) || (this.saAbbrevEraNames.Length == 0)) || string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
                {
                    this.saAbbrevEraNames = new string[] { "AD" };
                }
                return;

            case CalendarId.GREGORIAN_US:
            case CalendarId.JULIAN:
                this.saAbbrevEraNames = new string[] { "AD" };
                return;

            case CalendarId.JAPAN:
            case CalendarId.JAPANESELUNISOLAR:
                this.saAbbrevEraNames = JapaneseCalendar.AbbrevEraNames();
                return;

            case CalendarId.TAIWAN:
                this.saAbbrevEraNames = new string[1];
                if (this.saEraNames[0].Length != 4)
                {
                    this.saAbbrevEraNames[0] = this.saEraNames[0];
                    return;
                }
                this.saAbbrevEraNames[0] = this.saEraNames[0].Substring(2, 2);
                return;

            case CalendarId.HIJRI:
            case CalendarId.UMALQURA:
                if (localeName == "dv-MV")
                {
                    this.saAbbrevEraNames = new string[] { "ހ." };
                    return;
                }
                this.saAbbrevEraNames = new string[] { "هـ" };
                return;
            }
            this.saAbbrevEraNames = this.saEraNames;
        }
	protected override void SetUp() {
		gcal = new GregorianCalendar();
		jucal = new JulianCalendar();
		hical = new HijriCalendar();
		hecal = new HebrewCalendar();
		jacal = new JapaneseCalendar();
		tacal = new TaiwanCalendar();
		kcal = new KoreanCalendar();
		tbcal = new ThaiBuddhistCalendar();
		acal = new Calendar[] {
			gcal, jucal, hical, hecal, jacal,
			tacal, kcal, tbcal};
	}
Example #16
0
        // Token: 0x06002CC1 RID: 11457 RVA: 0x000AAE30 File Offset: 0x000A9030
        private void InitializeAbbreviatedEraNames(string localeName, int calendarId)
        {
            CalendarId calendarId2 = (CalendarId)calendarId;

            if (calendarId2 <= CalendarId.JULIAN)
            {
                switch (calendarId2)
                {
                case CalendarId.GREGORIAN:
                    if (this.saAbbrevEraNames == null || this.saAbbrevEraNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
                    {
                        this.saAbbrevEraNames = new string[]
                        {
                            "AD"
                        };
                        return;
                    }
                    return;

                case CalendarId.GREGORIAN_US:
                    break;

                case CalendarId.JAPAN:
                    goto IL_96;

                case CalendarId.TAIWAN:
                    this.saAbbrevEraNames = new string[1];
                    if (this.saEraNames[0].Length == 4)
                    {
                        this.saAbbrevEraNames[0] = this.saEraNames[0].Substring(2, 2);
                        return;
                    }
                    this.saAbbrevEraNames[0] = this.saEraNames[0];
                    return;

                case CalendarId.KOREA:
                    goto IL_14B;

                case CalendarId.HIJRI:
                    goto IL_A2;

                default:
                    if (calendarId2 != CalendarId.JULIAN)
                    {
                        goto IL_14B;
                    }
                    break;
                }
                this.saAbbrevEraNames = new string[]
                {
                    "AD"
                };
                return;
            }
            if (calendarId2 != CalendarId.JAPANESELUNISOLAR)
            {
                if (calendarId2 != CalendarId.PERSIAN)
                {
                    if (calendarId2 != CalendarId.UMALQURA)
                    {
                        goto IL_14B;
                    }
                    goto IL_A2;
                }
                else
                {
                    if (this.saAbbrevEraNames == null || this.saAbbrevEraNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
                    {
                        this.saAbbrevEraNames = this.saEraNames;
                        return;
                    }
                    return;
                }
            }
IL_96:
            this.saAbbrevEraNames = JapaneseCalendar.AbbrevEraNames();
            return;

IL_A2:
            if (localeName == "dv-MV")
            {
                this.saAbbrevEraNames = new string[]
                {
                    "ހ."
                };
                return;
            }
            this.saAbbrevEraNames = new string[]
            {
                "هـ"
            };
            return;

IL_14B:
            this.saAbbrevEraNames = this.saEraNames;
        }
Example #17
0
	protected void SetUp() {
		gcal = new GregorianCalendar();
		jucal = new JulianCalendar();
		hical = new HijriCalendar();
		hecal = new HebrewCalendar();
		jacal = new JapaneseCalendar();
		tacal = new TaiwanCalendar();
		kcal = new KoreanCalendar();
		tbcal = new ThaiBuddhistCalendar();
		acal = new Calendar[] {
			gcal, jucal, hical, hecal, jacal,
			tacal, kcal, tbcal};
#if NET_2_0
		clcal = new ChineseLunisolarCalendar ();
		tlcal = new TaiwanLunisolarCalendar ();
		jlcal = new JapaneseLunisolarCalendar ();
		klcal = new KoreanLunisolarCalendar ();
#endif
	}
Example #18
0
        /// <summary>
        /// GetCalendar returns a .NET Calendar equivalent to a CLDR Calendar
        /// </summary>
        /// <param name="calendar">A CLDR Calendar</param>
        /// <returns>A .NET Calendar</returns>
        private static System.Globalization.Calendar GetCalendar(Types.Calendar calendar)
        {
            System.Globalization.Calendar dotNetCalendar = null;

            if (string.Compare(calendar.Id, "gregorian", StringComparison.InvariantCulture) == 0 && calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
            {
                dotNetCalendar = new GregorianCalendar();
            }
            else if (string.Compare(calendar.Id, "japanese", StringComparison.InvariantCulture) == 0)
            {
                if (calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
                {
                    dotNetCalendar = new JapaneseCalendar();
                }
                else if (calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
                {
                    dotNetCalendar = new JapaneseLunisolarCalendar();
                }
            }
            else if (string.Compare(calendar.Id, "islamic-civil", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new HijriCalendar();
            }
            else if (string.Compare(calendar.Id, "islamic", StringComparison.InvariantCulture) == 0
                && calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new HijriCalendar();
            }
            else if (string.Compare(calendar.Id, "chinese", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new ChineseLunisolarCalendar();
            }
            else if (string.Compare(calendar.Id, "hebrew", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new HebrewCalendar();
            }
            else if (string.Compare(calendar.Id, "buddhist", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
            {
                dotNetCalendar = new ThaiBuddhistCalendar();
            }
            else if (string.Compare(calendar.Id, "coptic", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }
            else if (string.Compare(calendar.Id, "persian", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
            {
                return new PersianCalendar();
            }
            else if (string.Compare(calendar.Id, "ethiopic", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }
            else if (string.Compare(calendar.Id, "indian", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }
            else if (string.Compare(calendar.Id, "roc", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }

            return dotNetCalendar;
        }
Example #19
0
        //
        // Get a bunch of data for a calendar
        //
        internal CalendarData(String localeName, int calendarId, bool bUseUserOverrides)
        {
            // Call nativeGetCalendarData to populate the data
            this.bUseUserOverrides = bUseUserOverrides;
            if (!nativeGetCalendarData(this, localeName, calendarId))
            {
                Contract.Assert(false, "[CalendarData] nativeGetCalendarData call isn't expected to fail for calendar " + calendarId + " locale " + localeName);

                // Something failed, try invariant for missing parts
                // This is really not good, but we don't want the callers to crash.
                if (this.sNativeName == null)
                {
                    this.sNativeName = String.Empty;                                        // Calendar Name for the locale.
                }
                // Formats
                if (this.saShortDates == null)
                {
                    this.saShortDates = Invariant.saShortDates;                             // Short Data format, default first
                }
                if (this.saYearMonths == null)
                {
                    this.saYearMonths = Invariant.saYearMonths;                             // Year/Month Data format, default first
                }
                if (this.saLongDates == null)
                {
                    this.saLongDates = Invariant.saLongDates;                               // Long Data format, default first
                }
                if (this.sMonthDay == null)
                {
                    this.sMonthDay = Invariant.sMonthDay;                                   // Month/Day format
                }
                // Calendar Parts Names
                if (this.saEraNames == null)
                {
                    this.saEraNames = Invariant.saEraNames;                                                                 // Names of Eras
                }
                if (this.saAbbrevEraNames == null)
                {
                    this.saAbbrevEraNames = Invariant.saAbbrevEraNames;                                                     // Abbreviated Era Names
                }
                if (this.saAbbrevEnglishEraNames == null)
                {
                    this.saAbbrevEnglishEraNames = Invariant.saAbbrevEnglishEraNames;                                       // Abbreviated Era Names in English
                }
                if (this.saDayNames == null)
                {
                    this.saDayNames = Invariant.saDayNames;                                                                 // Day Names, null to use locale data, starts on Sunday
                }
                if (this.saAbbrevDayNames == null)
                {
                    this.saAbbrevDayNames = Invariant.saAbbrevDayNames;                                                     // Abbrev Day Names, null to use locale data, starts on Sunday
                }
                if (this.saSuperShortDayNames == null)
                {
                    this.saSuperShortDayNames = Invariant.saSuperShortDayNames;                                             // Super short Day of week names
                }
                if (this.saMonthNames == null)
                {
                    this.saMonthNames = Invariant.saMonthNames;                                                             // Month Names (13)
                }
                if (this.saAbbrevMonthNames == null)
                {
                    this.saAbbrevMonthNames = Invariant.saAbbrevMonthNames;                                                 // Abbrev Month Names (13)
                }
                // Genitive and Leap names can follow the fallback below
            }

            // Clean up the escaping of the formats
            this.saShortDates = CultureData.ReescapeWin32Strings(this.saShortDates);
            this.saLongDates  = CultureData.ReescapeWin32Strings(this.saLongDates);
            this.saYearMonths = CultureData.ReescapeWin32Strings(this.saYearMonths);
            this.sMonthDay    = CultureData.ReescapeWin32String(this.sMonthDay);

            if ((CalendarId)calendarId == CalendarId.TAIWAN)
            {
                // for Geo----al reasons, the ----ese native name should only be returned when
                // for ----ese SKU
                if (CultureInfo.IsTaiwanSku)
                {
                    // We got the month/day names from the OS (same as gregorian), but the native name is wrong
                    this.sNativeName = "\x4e2d\x83ef\x6c11\x570b\x66c6";
                }
                else
                {
                    this.sNativeName = String.Empty;
                }
            }

            // Check for null genitive names (in case unmanaged side skips it for non-gregorian calendars, etc)
            if (this.saMonthGenitiveNames == null || String.IsNullOrEmpty(this.saMonthGenitiveNames[0]))
            {
                this.saMonthGenitiveNames = this.saMonthNames;              // Genitive month names (same as month names for invariant)
            }
            if (this.saAbbrevMonthGenitiveNames == null || String.IsNullOrEmpty(this.saAbbrevMonthGenitiveNames[0]))
            {
                this.saAbbrevMonthGenitiveNames = this.saAbbrevMonthNames;    // Abbreviated genitive month names (same as abbrev month names for invariant)
            }
            if (this.saLeapYearMonthNames == null || String.IsNullOrEmpty(this.saLeapYearMonthNames[0]))
            {
                this.saLeapYearMonthNames = this.saMonthNames;
            }

            InitializeEraNames(localeName, calendarId);

            InitializeAbbreviatedEraNames(localeName, calendarId);

            // Abbreviated English Era Names are only used for the Japanese calendar.
            if (!GlobalizationMode.Invariant && calendarId == (int)CalendarId.JAPAN)
            {
                this.saAbbrevEnglishEraNames = JapaneseCalendar.EnglishEraNames();
            }
            else
            {
                // For all others just use the an empty string (doesn't matter we'll never ask for it for other calendars)
                this.saAbbrevEnglishEraNames = new String[] { "" };
            }

            // Japanese is the only thing with > 1 era.  Its current era # is how many ever
            // eras are in the array.  (And the others all have 1 string in the array)
            this.iCurrentEra = this.saEraNames.Length;
        }
Example #20
0
        //
        // Get a bunch of data for a calendar
        //
        internal CalendarData(string localeName, CalendarId calendarId, bool bUseUserOverrides)
        {
            this.bUseUserOverrides = bUseUserOverrides;

            Debug.Assert(!GlobalizationMode.Invariant);

            bool loadedCalendarData = GlobalizationMode.UseNls ?
                                      NlsLoadCalendarDataFromSystem(localeName, calendarId) :
                                      IcuLoadCalendarDataFromSystem(localeName, calendarId);

            if (!loadedCalendarData)
            {
                // LoadCalendarDataFromSystem sometimes can fail on Linux if the installed ICU package is missing some resources.
                // The ICU package can miss some resources in some cases like if someone compile and build the ICU package manually or ICU has a regression.

                // Something failed, try invariant for missing parts
                // This is really not good, but we don't want the callers to crash.
                this.sNativeName ??= string.Empty;           // Calendar Name for the locale.

                // Formats
                this.saShortDates ??= Invariant.saShortDates; // Short Data format, default first
                this.saYearMonths ??= Invariant.saYearMonths; // Year/Month Data format, default first
                this.saLongDates ??= Invariant.saLongDates;   // Long Data format, default first
                this.sMonthDay ??= Invariant.sMonthDay;       // Month/Day format

                // Calendar Parts Names
                this.saEraNames ??= Invariant.saEraNames;                           // Names of Eras
                this.saAbbrevEraNames ??= Invariant.saAbbrevEraNames;               // Abbreviated Era Names
                this.saAbbrevEnglishEraNames ??= Invariant.saAbbrevEnglishEraNames; // Abbreviated Era Names in English
                this.saDayNames ??= Invariant.saDayNames;                           // Day Names, null to use locale data, starts on Sunday
                this.saAbbrevDayNames ??= Invariant.saAbbrevDayNames;               // Abbrev Day Names, null to use locale data, starts on Sunday
                this.saSuperShortDayNames ??= Invariant.saSuperShortDayNames;       // Super short Day of week names
                this.saMonthNames ??= Invariant.saMonthNames;                       // Month Names (13)
                this.saAbbrevMonthNames ??= Invariant.saAbbrevMonthNames;           // Abbrev Month Names (13)
                // Genitive and Leap names can follow the fallback below
            }

            if (calendarId == CalendarId.TAIWAN)
            {
                if (SystemSupportsTaiwaneseCalendar())
                {
                    // We got the month/day names from the OS (same as gregorian), but the native name is wrong
                    this.sNativeName = "\x4e2d\x83ef\x6c11\x570b\x66c6";
                }
                else
                {
                    this.sNativeName = string.Empty;
                }
            }

            // Check for null genitive names (in case unmanaged side skips it for non-gregorian calendars, etc)
            if (this.saMonthGenitiveNames == null || this.saMonthGenitiveNames.Length == 0 || string.IsNullOrEmpty(this.saMonthGenitiveNames[0]))
            {
                this.saMonthGenitiveNames = this.saMonthNames;              // Genitive month names (same as month names for invariant)
            }
            if (this.saAbbrevMonthGenitiveNames == null || this.saAbbrevMonthGenitiveNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevMonthGenitiveNames[0]))
            {
                this.saAbbrevMonthGenitiveNames = this.saAbbrevMonthNames;    // Abbreviated genitive month names (same as abbrev month names for invariant)
            }
            if (this.saLeapYearMonthNames == null || this.saLeapYearMonthNames.Length == 0 || string.IsNullOrEmpty(this.saLeapYearMonthNames[0]))
            {
                this.saLeapYearMonthNames = this.saMonthNames;
            }

            InitializeEraNames(localeName, calendarId);

            InitializeAbbreviatedEraNames(localeName, calendarId);

            // Abbreviated English Era Names are only used for the Japanese calendar.
            if (calendarId == CalendarId.JAPAN)
            {
                this.saAbbrevEnglishEraNames = JapaneseCalendar.EnglishEraNames();
            }
            else
            {
                // For all others just use the an empty string (doesn't matter we'll never ask for it for other calendars)
                this.saAbbrevEnglishEraNames = new string[] { "" };
            }

            // Japanese is the only thing with > 1 era.  Its current era # is how many ever
            // eras are in the array.  (And the others all have 1 string in the array)
            this.iCurrentEra = this.saEraNames.Length;
        }
Example #21
0
        private void InitializeAbbreviatedEraNames(string localeName, int calendarId)
        {
            CalendarId calendarId1 = (CalendarId)calendarId;

            if ((uint)calendarId1 <= 13U)
            {
                switch (calendarId1)
                {
                case CalendarId.GREGORIAN:
                    if (this.saAbbrevEraNames != null && this.saAbbrevEraNames.Length != 0 && !string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
                    {
                        return;
                    }
                    this.saAbbrevEraNames = new string[1] {
                        "AD"
                    };
                    return;

                case CalendarId.GREGORIAN_US:
                case CalendarId.JULIAN:
                    this.saAbbrevEraNames = new string[1] {
                        "AD"
                    };
                    return;

                case CalendarId.JAPAN:
                    break;

                case CalendarId.TAIWAN:
                    this.saAbbrevEraNames = new string[1];
                    if (this.saEraNames[0].Length == 4)
                    {
                        this.saAbbrevEraNames[0] = this.saEraNames[0].Substring(2, 2);
                        return;
                    }
                    this.saAbbrevEraNames[0] = this.saEraNames[0];
                    return;

                case CalendarId.HIJRI:
                    goto label_11;

                default:
                    goto label_19;
                }
            }
            else if (calendarId1 != CalendarId.JAPANESELUNISOLAR)
            {
                if (calendarId1 != CalendarId.PERSIAN)
                {
                    if (calendarId1 == CalendarId.UMALQURA)
                    {
                        goto label_11;
                    }
                    else
                    {
                        goto label_19;
                    }
                }
                else
                {
                    if (this.saAbbrevEraNames != null && this.saAbbrevEraNames.Length != 0 && !string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
                    {
                        return;
                    }
                    this.saAbbrevEraNames = this.saEraNames;
                    return;
                }
            }
            this.saAbbrevEraNames = JapaneseCalendar.AbbrevEraNames();
            return;

label_11:
            if (localeName == "dv-MV")
            {
                this.saAbbrevEraNames = new string[1] {
                    "ހ."
                };
                return;
            }
            this.saAbbrevEraNames = new string[1] {
                "هـ"
            };
            return;

label_19:
            this.saAbbrevEraNames = this.saEraNames;
        }
Example #22
0
 private string getEraFromWesternYear(string westernYear, string westernMonth, string westernDay)
 {
     DateTime date = new DateTime(Convert.ToInt32(westernYear), Convert.ToInt32(westernMonth), Convert.ToInt32(westernDay));
     JapaneseCalendar jpCalendar = new JapaneseCalendar();
     string[] era = { "明治", "大正", "昭和", "平成" };
     return era[jpCalendar.GetEra(date) - 1];
 }
Example #23
0
        private static EraInfo[] GetErasFromRegistry()
        {
            int newSize = 0;

            EraInfo[] array = (EraInfo[])null;
            try
            {
                PermissionSet      permissionSet      = new PermissionSet(PermissionState.None);
                RegistryPermission registryPermission = new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras");
                permissionSet.AddPermission((IPermission)registryPermission);
                permissionSet.Assert();
                RegistryKey registryKey = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey("System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras", false);
                if (registryKey == null)
                {
                    return((EraInfo[])null);
                }
                string[] valueNames = registryKey.GetValueNames();
                if (valueNames != null)
                {
                    if (valueNames.Length != 0)
                    {
                        array = new EraInfo[valueNames.Length];
                        for (int index = 0; index < valueNames.Length; ++index)
                        {
                            EraInfo eraFromValue = JapaneseCalendar.GetEraFromValue(valueNames[index], registryKey.GetValue(valueNames[index]).ToString());
                            if (eraFromValue != null)
                            {
                                array[newSize] = eraFromValue;
                                ++newSize;
                            }
                        }
                    }
                }
            }
            catch (SecurityException ex)
            {
                return((EraInfo[])null);
            }
            catch (IOException ex)
            {
                return((EraInfo[])null);
            }
            catch (UnauthorizedAccessException ex)
            {
                return((EraInfo[])null);
            }
            if (newSize < 4)
            {
                return((EraInfo[])null);
            }
            Array.Resize <EraInfo>(ref array, newSize);
            Array.Sort <EraInfo>(array, new Comparison <EraInfo>(JapaneseCalendar.CompareEraRanges));
            for (int index = 0; index < array.Length; ++index)
            {
                array[index].era = array.Length - index;
                if (index == 0)
                {
                    array[0].maxEraYear = 9999 - array[0].yearOffset;
                }
                else
                {
                    array[index].maxEraYear = array[index - 1].yearOffset + 1 - array[index].yearOffset;
                }
            }
            return(array);
        }
Example #24
0
        private void InitializeEraNames(string localeName, int calendarId)
        {
            switch ((ushort)calendarId)
            {
            case 1:
                if (this.saEraNames != null && this.saEraNames.Length != 0 && !string.IsNullOrEmpty(this.saEraNames[0]))
                {
                    break;
                }
                this.saEraNames = new string[1] {
                    "A.D."
                };
                break;

            case 2:
            case 13:
                this.saEraNames = new string[1] {
                    "A.D."
                };
                break;

            case 3:
            case 14:
                this.saEraNames = JapaneseCalendar.EraNames();
                break;

            case 4:
                if (CultureInfo.IsTaiwanSku)
                {
                    this.saEraNames = new string[1] {
                        "中華民國"
                    };
                    break;
                }
                this.saEraNames = new string[1] {
                    string.Empty
                };
                break;

            case 5:
                this.saEraNames = new string[1] {
                    "단기"
                };
                break;

            case 6:
            case 23:
                if (localeName == "dv-MV")
                {
                    this.saEraNames = new string[1] {
                        "ހިޖްރީ"
                    };
                    break;
                }
                this.saEraNames = new string[1] {
                    "بعد الهجرة"
                };
                break;

            case 7:
                this.saEraNames = new string[1] {
                    "พ.ศ."
                };
                break;

            case 8:
                this.saEraNames = new string[1] {
                    "C.E."
                };
                break;

            case 9:
                this.saEraNames = new string[1] {
                    "ap. J.-C."
                };
                break;

            case 10:
            case 11:
            case 12:
                this.saEraNames = new string[1] {
                    "م"
                };
                break;

            case 22:
                if (this.saEraNames != null && this.saEraNames.Length != 0 && !string.IsNullOrEmpty(this.saEraNames[0]))
                {
                    break;
                }
                this.saEraNames = new string[1] {
                    "ه.ش"
                };
                break;

            default:
                this.saEraNames = CalendarData.Invariant.saEraNames;
                break;
            }
        }
Example #25
0
        //
        // Get a bunch of data for a calendar
        //
        internal CalendarData(string localeName, CalendarId calendarId, bool bUseUserOverrides)
        {
            this.bUseUserOverrides = bUseUserOverrides;

            Debug.Assert(!GlobalizationMode.Invariant);

            if (!LoadCalendarDataFromSystem(localeName, calendarId))
            {
                Debug.Fail("[CalendarData] LoadCalendarDataFromSystem call isn't expected to fail for calendar " + calendarId + " locale " + localeName);

                // Something failed, try invariant for missing parts
                // This is really not good, but we don't want the callers to crash.
                if (this.sNativeName == null)
                {
                    this.sNativeName = string.Empty;                                     // Calendar Name for the locale.
                }
                // Formats
                if (this.saShortDates == null)
                {
                    this.saShortDates = Invariant.saShortDates;                            // Short Data format, default first
                }
                if (this.saYearMonths == null)
                {
                    this.saYearMonths = Invariant.saYearMonths;                            // Year/Month Data format, default first
                }
                if (this.saLongDates == null)
                {
                    this.saLongDates = Invariant.saLongDates;                            // Long Data format, default first
                }
                if (this.sMonthDay == null)
                {
                    this.sMonthDay = Invariant.sMonthDay;                            // Month/Day format
                }
                // Calendar Parts Names
                if (this.saEraNames == null)
                {
                    this.saEraNames = Invariant.saEraNames;                                       // Names of Eras
                }
                if (this.saAbbrevEraNames == null)
                {
                    this.saAbbrevEraNames = Invariant.saAbbrevEraNames;                                       // Abbreviated Era Names
                }
                if (this.saAbbrevEnglishEraNames == null)
                {
                    this.saAbbrevEnglishEraNames = Invariant.saAbbrevEnglishEraNames;                                       // Abbreviated Era Names in English
                }
                if (this.saDayNames == null)
                {
                    this.saDayNames = Invariant.saDayNames;                                       // Day Names, null to use locale data, starts on Sunday
                }
                if (this.saAbbrevDayNames == null)
                {
                    this.saAbbrevDayNames = Invariant.saAbbrevDayNames;                                       // Abbrev Day Names, null to use locale data, starts on Sunday
                }
                if (this.saSuperShortDayNames == null)
                {
                    this.saSuperShortDayNames = Invariant.saSuperShortDayNames;                                       // Super short Day of week names
                }
                if (this.saMonthNames == null)
                {
                    this.saMonthNames = Invariant.saMonthNames;                                       // Month Names (13)
                }
                if (this.saAbbrevMonthNames == null)
                {
                    this.saAbbrevMonthNames = Invariant.saAbbrevMonthNames;                                       // Abbrev Month Names (13)
                }
                // Genitive and Leap names can follow the fallback below
            }

            if (calendarId == CalendarId.TAIWAN)
            {
                if (SystemSupportsTaiwaneseCalendar())
                {
                    // We got the month/day names from the OS (same as gregorian), but the native name is wrong
                    this.sNativeName = "\x4e2d\x83ef\x6c11\x570b\x66c6";
                }
                else
                {
                    this.sNativeName = string.Empty;
                }
            }

            // Check for null genitive names (in case unmanaged side skips it for non-gregorian calendars, etc)
            if (this.saMonthGenitiveNames == null || this.saMonthGenitiveNames.Length == 0 || string.IsNullOrEmpty(this.saMonthGenitiveNames[0]))
            {
                this.saMonthGenitiveNames = this.saMonthNames;              // Genitive month names (same as month names for invariant)
            }
            if (this.saAbbrevMonthGenitiveNames == null || this.saAbbrevMonthGenitiveNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevMonthGenitiveNames[0]))
            {
                this.saAbbrevMonthGenitiveNames = this.saAbbrevMonthNames;    // Abbreviated genitive month names (same as abbrev month names for invariant)
            }
            if (this.saLeapYearMonthNames == null || this.saLeapYearMonthNames.Length == 0 || string.IsNullOrEmpty(this.saLeapYearMonthNames[0]))
            {
                this.saLeapYearMonthNames = this.saMonthNames;
            }

            InitializeEraNames(localeName, calendarId);

            InitializeAbbreviatedEraNames(localeName, calendarId);

            // Abbreviated English Era Names are only used for the Japanese calendar.
            if (calendarId == CalendarId.JAPAN)
            {
                this.saAbbrevEnglishEraNames = JapaneseCalendar.EnglishEraNames();
            }
            else
            {
                // For all others just use the an empty string (doesn't matter we'll never ask for it for other calendars)
                this.saAbbrevEnglishEraNames = new string[] { "" };
            }

            // Japanese is the only thing with > 1 era.  Its current era # is how many ever
            // eras are in the array.  (And the others all have 1 string in the array)
            this.iCurrentEra = this.saEraNames.Length;
        }
Example #26
0
 public static void JapaneseTest()
 {
     JapaneseCalendar cal = new JapaneseCalendar();
     Assert.True(cal.Eras.Length >= 4);
 }
Example #27
0
 private string convertWesternYearToJapaneseYear(string westernYear, string westernMonth, string westernDay)
 {
     DateTime date = new DateTime(Convert.ToInt32(westernYear), Convert.ToInt32(westernMonth), Convert.ToInt32(westernDay));
     JapaneseCalendar jpCalendar = new JapaneseCalendar();
     string year = jpCalendar.GetYear(date).ToString();
     return jpCalendar.GetYear(date).ToString();
 }
Example #28
0
        public static Calendar CalendarFromString(
            string                                      name
        )
        {
            Calendar                                    c;

            if (name == null)
            {
                name = String.Empty;
            }

            switch (name.ToLower())
            {
                case "hebrew":
                    c = new HebrewCalendar();
                    break;

                case "hijri":
                    c = new HijriCalendar();
                    break;

                case "japanese":
                    c = new JapaneseCalendar();
                    break;

                case "korean":
                    c = new KoreanCalendar();
                    break;

                case "taiwan":
                    c = new TaiwanCalendar();
                    break;

                case "thaibuddhist":
                    c = new ThaiBuddhistCalendar();
                    break;

                case "umalqura":
                    c = new UmAlQuraCalendar();
                    break;
#if !SILVERLIGHT
                case "persian":
                    c = new PersianCalendar();
                    break;
#endif 
                default:
                    c = new GregorianCalendar();
                    break;
            }

            return c;
        }
Example #29
0
 public static void JapaneseTest()
 {
     JapaneseCalendar jCal = new JapaneseCalendar();
     DateTime dTest = jCal.ToDateTime(1, 1, 8, 0, 0, 0, 0);
     Assert.Equal(dTest, new DateTime(1989, 1, 8));
 }
 public void PosTest1()
 {
     int actual = new JapaneseCalendar().TwoDigitYearMax;
     int expected = 99;
     Assert.Equal(expected, actual);
 }
Example #31
0
        private void chakkoNenTextBox_Leave(object sender, EventArgs e)
        {
            int i;

            if (int.TryParse(chakkoNenTextBox.Text, out i))
            {
                if (int.Parse(chakkoNenTextBox.Text) > 1868)
                {
                    JapaneseCalendar jpCalender = new JapaneseCalendar();
                    //jpCalender.GetEra(DateTime.Parse(chakkoNenTextBox.Text + "-01-01"));

                    string[] Gengo = { "M", "T", "S", "H" };

                    chakkoNenTextBox.Text = Gengo[jpCalender.GetEra(DateTime.Parse(chakkoNenTextBox.Text + "-12-31")) - 1] + jpCalender.GetYear(DateTime.Parse(chakkoNenTextBox.Text + "-12-31")).ToString();
                }
                else
                {
                    chakkoNenTextBox.Text = "H" + chakkoNenTextBox.Text;
                }
            }
        }
Example #32
0
 private void drawNodeGStamp(Graphics g, XmlNode source, PointF margin, Font defaultFont)
 {
     if (this.mIsWriteGStamp || this.mIsNullData)
     {
         string mGStampInfo;
         if (this.mIsNullData)
         {
             mGStampInfo = Resources.ResourceManager.GetString("MSG0208");
         }
         else
         {
             mGStampInfo = this.mGStampInfo;
         }
         List<string> list = CommaText.CommaTextToItems(mGStampInfo);
         PointF tf = this.getLocationAttribute(source);
         tf.X += margin.X;
         tf.Y += margin.Y;
         SizeF ef = this.getSizeAttribute(source);
         float num = 19f * SizeDef.PrintPixelPerDisplayPixel;
         PointF tf2 = new PointF(LBGStamp._topText.X * SizeDef.PrintPixelPerDisplayPixel, LBGStamp._topText.Y * SizeDef.PrintPixelPerDisplayPixel);
         PointF tf3 = new PointF(LBGStamp._dateText.X * SizeDef.PrintPixelPerDisplayPixel, LBGStamp._dateText.Y * SizeDef.PrintPixelPerDisplayPixel);
         PointF tf4 = new PointF(LBGStamp._underText1.X * SizeDef.PrintPixelPerDisplayPixel, LBGStamp._underText1.Y * SizeDef.PrintPixelPerDisplayPixel);
         PointF tf5 = new PointF(LBGStamp._underText2.X * SizeDef.PrintPixelPerDisplayPixel, LBGStamp._underText2.Y * SizeDef.PrintPixelPerDisplayPixel);
         PointF tf6 = new PointF(LBGStamp._underText3.X * SizeDef.PrintPixelPerDisplayPixel, LBGStamp._underText3.Y * SizeDef.PrintPixelPerDisplayPixel);
         SizeF size = new SizeF(LBGStamp._textSize.Width * SizeDef.PrintPixelPerDisplayPixel, LBGStamp._textSize.Height * SizeDef.PrintPixelPerDisplayPixel);
         using (Pen pen = this.getPenAttribute(source))
         {
             g.DrawRectangle(pen, tf.X, tf.Y, ef.Width, ef.Height);
             g.DrawLine(pen, tf.X, tf.Y + num, tf.X + ef.Width, tf.Y + num);
             g.DrawLine(pen, tf.X, tf.Y + (num * 2f), tf.X + ef.Width, tf.Y + (num * 2f));
         }
         Font font = new Font("Tahoma", 9f);
         SolidBrush brush = new SolidBrush(Color.Black);
         StringFormat format = new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap);
         try
         {
             if (list.Count > 0)
             {
                 g.DrawString(list[0], font, brush, new PointF(tf.X + tf2.X, tf.Y + tf2.Y));
             }
             if (list.Count > 1)
             {
                 format.LineAlignment = StringAlignment.Center;
                 if (this.mGStampDateAlign.IndexOf("Center") >= 0)
                 {
                     format.Alignment = StringAlignment.Center;
                 }
                 else if (this.mGStampDateAlign.IndexOf("Right") >= 0)
                 {
                     format.Alignment = StringAlignment.Far;
                 }
                 else
                 {
                     format.Alignment = StringAlignment.Near;
                 }
                 string s = "";
                 Calendar calendar = new JapaneseCalendar();
                 CultureInfo provider = new CultureInfo("ja-JP") {
                     DateTimeFormat = { Calendar = calendar }
                 };
                 try
                 {
                     s = DateTime.ParseExact(list[1].Trim(), "yyyy/MM/dd", null).ToString("yy.MM.dd", provider);
                 }
                 catch
                 {
                     s = "XX.XX.XX";
                 }
                 g.DrawString(s, font, brush, new RectangleF(new PointF(tf.X + tf3.X, tf.Y + tf3.Y), size), format);
             }
             if (list.Count > 2)
             {
                 g.DrawString(list[2], font, brush, new PointF(tf.X + tf4.X, tf.Y + tf4.Y));
             }
             if (list.Count > 3)
             {
                 g.DrawString(list[3], font, brush, new PointF(tf.X + tf5.X, tf.Y + tf5.Y));
             }
             if (list.Count > 4)
             {
                 g.DrawString(list[4], font, brush, new PointF(tf.X + tf6.X, tf.Y + tf6.Y));
             }
         }
         finally
         {
             format.Dispose();
             brush.Dispose();
             font.Dispose();
         }
     }
 }
        private void InitializeEraNames(string localeName, int calendarId)
        {
            switch (((CalendarId)((ushort)calendarId)))
            {
            case CalendarId.GREGORIAN:
                if (((this.saEraNames == null) || (this.saEraNames.Length == 0)) || string.IsNullOrEmpty(this.saEraNames[0]))
                {
                    this.saEraNames = new string[] { "A.D." };
                }
                return;

            case CalendarId.GREGORIAN_US:
            case CalendarId.JULIAN:
                this.saEraNames = new string[] { "A.D." };
                return;

            case CalendarId.JAPAN:
            case CalendarId.JAPANESELUNISOLAR:
                this.saEraNames = JapaneseCalendar.EraNames();
                return;

            case CalendarId.TAIWAN:
                if (!CultureInfo.IsTaiwanSku)
                {
                    this.saEraNames = new string[] { string.Empty };
                    return;
                }
                this.saEraNames = new string[] { "中華民國" };
                return;

            case CalendarId.KOREA:
                this.saEraNames = new string[] { "단기" };
                return;

            case CalendarId.HIJRI:
            case CalendarId.UMALQURA:
                if (!(localeName == "dv-MV"))
                {
                    this.saEraNames = new string[] { "بعد الهجرة" };
                    return;
                }
                this.saEraNames = new string[] { "ހިޖްރީ" };
                return;

            case CalendarId.THAI:
                this.saEraNames = new string[] { "พ.ศ." };
                return;

            case CalendarId.HEBREW:
                this.saEraNames = new string[] { "C.E." };
                return;

            case CalendarId.GREGORIAN_ME_FRENCH:
                this.saEraNames = new string[] { "ap. J.-C." };
                return;

            case CalendarId.GREGORIAN_ARABIC:
            case CalendarId.GREGORIAN_XLIT_ENGLISH:
            case CalendarId.GREGORIAN_XLIT_FRENCH:
                this.saEraNames = new string[] { "م" };
                return;
            }
            this.saEraNames = Invariant.saEraNames;
        }
 public void PosTest1()
 {
     DateTime actual = new JapaneseCalendar().MaxSupportedDateTime;
     DateTime expected = DateTime.MaxValue;
     Assert.Equal(expected, actual);
 }
 public void PosTest1()
 {
     DateTime actual = new JapaneseCalendar().MinSupportedDateTime;
     DateTime expected = new DateTime(1868, 9, 8);
     Assert.Equal(expected, actual);
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Globalization.JapaneseLunisolarCalendar" /> class. </summary>
 // Token: 0x06002F38 RID: 12088 RVA: 0x000B511A File Offset: 0x000B331A
 public JapaneseLunisolarCalendar()
 {
     this.helper = new GregorianCalendarHelper(this, JapaneseLunisolarCalendar.TrimEras(JapaneseCalendar.GetEraInfo()));
 }
Example #37
0
 internal CalendarData(string localeName, int calendarId, bool bUseUserOverrides)
 {
     this.bUseUserOverrides = bUseUserOverrides;
     if (!CalendarData.nativeGetCalendarData(this, localeName, calendarId))
     {
         if (this.sNativeName == null)
         {
             this.sNativeName = string.Empty;
         }
         if (this.saShortDates == null)
         {
             this.saShortDates = CalendarData.Invariant.saShortDates;
         }
         if (this.saYearMonths == null)
         {
             this.saYearMonths = CalendarData.Invariant.saYearMonths;
         }
         if (this.saLongDates == null)
         {
             this.saLongDates = CalendarData.Invariant.saLongDates;
         }
         if (this.sMonthDay == null)
         {
             this.sMonthDay = CalendarData.Invariant.sMonthDay;
         }
         if (this.saEraNames == null)
         {
             this.saEraNames = CalendarData.Invariant.saEraNames;
         }
         if (this.saAbbrevEraNames == null)
         {
             this.saAbbrevEraNames = CalendarData.Invariant.saAbbrevEraNames;
         }
         if (this.saAbbrevEnglishEraNames == null)
         {
             this.saAbbrevEnglishEraNames = CalendarData.Invariant.saAbbrevEnglishEraNames;
         }
         if (this.saDayNames == null)
         {
             this.saDayNames = CalendarData.Invariant.saDayNames;
         }
         if (this.saAbbrevDayNames == null)
         {
             this.saAbbrevDayNames = CalendarData.Invariant.saAbbrevDayNames;
         }
         if (this.saSuperShortDayNames == null)
         {
             this.saSuperShortDayNames = CalendarData.Invariant.saSuperShortDayNames;
         }
         if (this.saMonthNames == null)
         {
             this.saMonthNames = CalendarData.Invariant.saMonthNames;
         }
         if (this.saAbbrevMonthNames == null)
         {
             this.saAbbrevMonthNames = CalendarData.Invariant.saAbbrevMonthNames;
         }
     }
     this.saShortDates = CultureData.ReescapeWin32Strings(this.saShortDates);
     this.saLongDates  = CultureData.ReescapeWin32Strings(this.saLongDates);
     this.saYearMonths = CultureData.ReescapeWin32Strings(this.saYearMonths);
     this.sMonthDay    = CultureData.ReescapeWin32String(this.sMonthDay);
     if ((int)(ushort)calendarId == 4)
     {
         this.sNativeName = !CultureInfo.IsTaiwanSku ? string.Empty : "中華民國曆";
     }
     if (this.saMonthGenitiveNames == null || string.IsNullOrEmpty(this.saMonthGenitiveNames[0]))
     {
         this.saMonthGenitiveNames = this.saMonthNames;
     }
     if (this.saAbbrevMonthGenitiveNames == null || string.IsNullOrEmpty(this.saAbbrevMonthGenitiveNames[0]))
     {
         this.saAbbrevMonthGenitiveNames = this.saAbbrevMonthNames;
     }
     if (this.saLeapYearMonthNames == null || string.IsNullOrEmpty(this.saLeapYearMonthNames[0]))
     {
         this.saLeapYearMonthNames = this.saMonthNames;
     }
     this.InitializeEraNames(localeName, calendarId);
     this.InitializeAbbreviatedEraNames(localeName, calendarId);
     if (calendarId == 3)
     {
         this.saAbbrevEnglishEraNames = JapaneseCalendar.EnglishEraNames();
     }
     else
     {
         this.saAbbrevEnglishEraNames = new string[1] {
             ""
         }
     };
     this.iCurrentEra = this.saEraNames.Length;
 }
Example #38
0
        private void InitializeEraNames(string localeName, CalendarId calendarId)
        {
            // Note that the saEraNames only include "A.D."  We don't have localized names for other calendars available from windows
            switch (calendarId)
            {
            // For Localized Gregorian we really expect the data from the OS.
            case CalendarId.GREGORIAN:
                // Fallback for CoreCLR < Win7 or culture.dll missing
                if (this.saEraNames == null || this.saEraNames.Length == 0 || string.IsNullOrEmpty(this.saEraNames[0]))
                {
                    this.saEraNames = new string[] { "A.D." };
                }
                break;

            // The rest of the calendars have constant data, so we'll just use that
            case CalendarId.GREGORIAN_US:
            case CalendarId.JULIAN:
                this.saEraNames = new string[] { "A.D." };
                break;

            case CalendarId.HEBREW:
                this.saEraNames = new string[] { "C.E." };
                break;

            case CalendarId.HIJRI:
            case CalendarId.UMALQURA:
                if (localeName == "dv-MV")
                {
                    // Special case for Divehi
                    this.saEraNames = new string[] { "\x0780\x07a8\x0796\x07b0\x0783\x07a9" };
                }
                else
                {
                    this.saEraNames = new string[] { "\x0628\x0639\x062F \x0627\x0644\x0647\x062C\x0631\x0629" };
                }
                break;

            case CalendarId.GREGORIAN_ARABIC:
            case CalendarId.GREGORIAN_XLIT_ENGLISH:
            case CalendarId.GREGORIAN_XLIT_FRENCH:
                // These are all the same:
                this.saEraNames = new string[] { "\x0645" };
                break;

            case CalendarId.GREGORIAN_ME_FRENCH:
                this.saEraNames = new string[] { "ap. J.-C." };
                break;

            case CalendarId.TAIWAN:
                if (SystemSupportsTaiwaneseCalendar())
                {
                    this.saEraNames = new string[] { "\x4e2d\x83ef\x6c11\x570b" };
                }
                else
                {
                    this.saEraNames = new string[] { string.Empty };
                }
                break;

            case CalendarId.KOREA:
                this.saEraNames = new string[] { "\xb2e8\xae30" };
                break;

            case CalendarId.THAI:
                this.saEraNames = new string[] { "\x0e1e\x002e\x0e28\x002e" };
                break;

            case CalendarId.JAPAN:
            case CalendarId.JAPANESELUNISOLAR:
                this.saEraNames = JapaneseCalendar.EraNames();
                break;

            case CalendarId.PERSIAN:
                if (this.saEraNames == null || this.saEraNames.Length == 0 || string.IsNullOrEmpty(this.saEraNames[0]))
                {
                    this.saEraNames = new string[] { "\x0647\x002e\x0634" };
                }
                break;

            default:
                // Most calendars are just "A.D."
                this.saEraNames = Invariant.saEraNames;
                break;
            }
        }
Example #39
0
        public DateTimeFormatter(string dateTimePattern, string calendarName, string amDesignator, string pmDesignator)
        {
            Calendar calendar = null;
            switch (calendarName)
            {
                case "ChineseLunisolarCalendar":
                    calendar = new ChineseLunisolarCalendar();
                    break;

                case "GregorianCalendar":
                    calendar = new GregorianCalendar();
                    break;

                case "HebrewCalendar":
                    calendar = new HebrewCalendar();
                    break;

                case "HijriCalendar":
                    calendar = new HijriCalendar();
                    break;

                case "JapaneseCalendar":
                    calendar = new JapaneseCalendar();
                    break;

                case "JapaneseLunisolarCalendar":
                    calendar = new JapaneseLunisolarCalendar();
                    break;

                case "JulianCalendar":
                    calendar = new JulianCalendar();
                    break;

                case "KoreanCalendar":
                    calendar = new KoreanCalendar();
                    break;

                case "KoreanLunisolarCalendar":
                    calendar = new KoreanLunisolarCalendar();
                    break;

                case "PersianCalendar":
                    calendar = new PersianCalendar();
                    break;

                case "TaiwanCalendar":
                    calendar = new TaiwanCalendar();
                    break;

                case "TaiwanLunisolarCalendar":
                    calendar = new TaiwanLunisolarCalendar();
                    break;

                case "ThaiBuddhistCalendar":
                    calendar = new ThaiBuddhistCalendar();
                    break;

                case "UmAlQuraCalendar":
                    calendar = new UmAlQuraCalendar();
                    break;
            }

            Initialize(dateTimePattern, calendar, amDesignator, pmDesignator);
        }