Ejemplo n.º 1
0
        public void Test3860()
        {
            ULocale loc = new ULocale("ja_JP@calendar=japanese");

            IBM.ICU.Util.Calendar cal       = new IBM.ICU.Util.JapaneseCalendar(loc);
            DateFormat            enjformat = cal.GetDateTimeFormat(0, 0, new ULocale(
                                                                        "en_JP@calendar=japanese"));
            DateFormat format = cal.GetDateTimeFormat(0, 0, loc);

            ((SimpleDateFormat)format).ApplyPattern("y.M.d"); // Note: just 'y'
            // doesn't work here.
            ILOG.J2CsMapping.Text.ParsePosition pos = new ILOG.J2CsMapping.Text.ParsePosition(0);
            DateTime aDate = format.Parse("1.1.9", pos); // after the start of heisei
            // accession. Jan 1, 1H
            // wouldn't work because it is
            // actually showa 64
            String inEn = enjformat.Format(aDate);

            cal.Clear();
            cal.SetTime(aDate);
            int gotYear = cal.Get(IBM.ICU.Util.Calendar.YEAR);
            int gotEra  = cal.Get(IBM.ICU.Util.Calendar.ERA);

            int expectYear = 1;
            int expectEra  = IBM.ICU.Util.JapaneseCalendar.CURRENT_ERA;

            if ((gotYear != expectYear) || (gotEra != expectEra))
            {
                Errln("Expected year " + expectYear + ", era " + expectEra
                      + ", but got year " + gotYear + " and era " + gotEra
                      + ", == " + inEn);
            }
            else
            {
                Logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
            }
        }
Ejemplo n.º 2
0
        public void TestCoverage()
        {
            {
                // new JapaneseCalendar(TimeZone)
                IBM.ICU.Util.JapaneseCalendar cal = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.TimeZone.GetDefault());
                if (cal == null)
                {
                    Errln("could not create JapaneseCalendar with TimeZone");
                }
            }

            {
                // new JapaneseCalendar(ULocale)
                IBM.ICU.Util.JapaneseCalendar cal_0 = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.ULocale.GetDefault());
                if (cal_0 == null)
                {
                    Errln("could not create JapaneseCalendar with ULocale");
                }
            }

            {
                // new JapaneseCalendar(TimeZone, ULocale)
                IBM.ICU.Util.JapaneseCalendar cal_1 = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.TimeZone.GetDefault(),
                                                                                        IBM.ICU.Util.ULocale.GetDefault());
                if (cal_1 == null)
                {
                    Errln("could not create JapaneseCalendar with TimeZone ULocale");
                }
            }

            {
                // new JapaneseCalendar(Locale)
                IBM.ICU.Util.JapaneseCalendar cal_2 = new IBM.ICU.Util.JapaneseCalendar(ILOG.J2CsMapping.Util.Locale.GetDefault());
                if (cal_2 == null)
                {
                    Errln("could not create JapaneseCalendar with Locale");
                }
            }

            {
                // new JapaneseCalendar(TimeZone, Locale)
                IBM.ICU.Util.JapaneseCalendar cal_3 = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.TimeZone.GetDefault(),
                                                                                        ILOG.J2CsMapping.Util.Locale.GetDefault());
                if (cal_3 == null)
                {
                    Errln("could not create JapaneseCalendar with TimeZone Locale");
                }
            }

            {
                // new JapaneseCalendar(Date)
                IBM.ICU.Util.JapaneseCalendar cal_4 = new IBM.ICU.Util.JapaneseCalendar(DateTime.Now);
                if (cal_4 == null)
                {
                    Errln("could not create JapaneseCalendar with Date");
                }
            }

            {
                // new JapaneseCalendar(int year, int month, int date)
                IBM.ICU.Util.JapaneseCalendar cal_5 = new IBM.ICU.Util.JapaneseCalendar(1868, IBM.ICU.Util.Calendar.JANUARY,
                                                                                        1);
                if (cal_5 == null)
                {
                    Errln("could not create JapaneseCalendar with year,month,date");
                }
            }

            {
                // new JapaneseCalendar(int era, int year, int month, int date)
                IBM.ICU.Util.JapaneseCalendar cal_6 = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.JapaneseCalendar.MEIJI,
                                                                                        43, IBM.ICU.Util.Calendar.JANUARY, 1);
                if (cal_6 == null)
                {
                    Errln("could not create JapaneseCalendar with era,year,month,date");
                }
            }

            {
                // new JapaneseCalendar(int year, int month, int date, int hour, int
                // minute, int second)
                IBM.ICU.Util.JapaneseCalendar cal_7 = new IBM.ICU.Util.JapaneseCalendar(1868, IBM.ICU.Util.Calendar.JANUARY,
                                                                                        1, 1, 1, 1);
                if (cal_7 == null)
                {
                    Errln("could not create JapaneseCalendar with year,month,date,hour,min,second");
                }
            }

            {
                // limits
                IBM.ICU.Util.JapaneseCalendar cal_8 = new IBM.ICU.Util.JapaneseCalendar();
                DateFormat fmt = cal_8.GetDateTimeFormat(IBM.ICU.Text.DateFormat.FULL,
                                                         IBM.ICU.Text.DateFormat.FULL, new ILOG.J2CsMapping.Util.Locale("en"));

                cal_8.Set(IBM.ICU.Util.Calendar.ERA, IBM.ICU.Util.JapaneseCalendar.MEIJI);
                Logln("date: " + cal_8.GetTime());
                Logln("min era: " + cal_8.GetMinimum(IBM.ICU.Util.Calendar.ERA));
                Logln("min year: " + cal_8.GetMinimum(IBM.ICU.Util.Calendar.YEAR));
                cal_8.Set(IBM.ICU.Util.Calendar.YEAR, cal_8.GetActualMaximum(IBM.ICU.Util.Calendar.YEAR));
                Logln("date: " + fmt.Format(cal_8.GetTime()));
                cal_8.Add(IBM.ICU.Util.Calendar.YEAR, 1);
                Logln("date: " + fmt.Format(cal_8.GetTime()));
            }

            {
                // data
                IBM.ICU.Util.JapaneseCalendar cal_9 = new IBM.ICU.Util.JapaneseCalendar(1868, IBM.ICU.Util.Calendar.JANUARY,
                                                                                        1);
                DateTime time = cal_9.GetTime();

                String[] calendarLocales = { "en", "ja_JP" };

                String[] formatLocales = { "en", "ja" };
                for (int i = 0; i < calendarLocales.Length; ++i)
                {
                    String calLocName = calendarLocales[i];
                    ILOG.J2CsMapping.Util.Locale calLocale = IBM.ICU.Impl.LocaleUtility.GetLocaleFromName(calLocName);
                    cal_9 = new IBM.ICU.Util.JapaneseCalendar(calLocale);

                    for (int j = 0; j < formatLocales.Length; ++j)
                    {
                        String locName = formatLocales[j];
                        ILOG.J2CsMapping.Util.Locale formatLocale = IBM.ICU.Impl.LocaleUtility
                                                                    .GetLocaleFromName(locName);
                        DateFormat format = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal_9,
                                                                                        IBM.ICU.Text.DateFormat.FULL, IBM.ICU.Text.DateFormat.FULL, formatLocale);
                        Logln(calLocName + "/" + locName + " --> "
                              + format.Format(time));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Test5345parse()
        {
            // Test parse with incomplete information
            DateFormat fmt2 = IBM.ICU.Text.DateFormat.GetDateInstance(); // DateFormat.LONG,

            // Locale.US);
            IBM.ICU.Util.JapaneseCalendar c = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.TimeZone.GetDefault(),
                                                                                new ULocale("en_US"));
            SimpleDateFormat fmt = (SimpleDateFormat)c.GetDateTimeFormat(1, 1,
                                                                         new ULocale("en_US@calendar=japanese"));

            fmt.ApplyPattern("G y");
            Logln("fmt's locale = " + fmt.GetLocale(IBM.ICU.Util.ULocale.ACTUAL_LOCALE));
            // SimpleDateFormat fmt = new SimpleDateFormat("G y", new
            // Locale("en_US@calendar=japanese"));
            long     aDateLong = -3197120400000L + 3600000L;                                   // compensate for DST
            DateTime aDate     = ILOG.J2CsMapping.Util.DateUtil.DateFromJavaMillis(aDateLong); // 08 Sept 1868

            Logln("aDate: " + aDate.ToString() + ", from " + aDateLong);
            String str;

            str = fmt2.Format(aDate);
            Logln("Test Date: " + str);
            str = fmt.Format(aDate);
            Logln("as Japanese Calendar: " + str);
            String expected = "Meiji 1";

            if (!str.Equals(expected))
            {
                Errln("FAIL: Expected " + expected + " but got " + str);
            }
            DateTime otherDate;

            try
            {
                otherDate = fmt.Parse(expected);
                if (!otherDate.Equals(aDate))
                {
                    String str3;
                    // ParsePosition pp;
                    DateTime dd = fmt.Parse(expected);
                    str3 = fmt.Format(otherDate);
                    long oLong = ILOG.J2CsMapping.Util.DateUtil.DotNetDateToJavaMillis(otherDate);
                    long aLong = ILOG.J2CsMapping.Util.DateUtil.DotNetDateToJavaMillis(aDate);

                    Errln("FAIL: Parse incorrect of " + expected + ":  wanted "
                          + aDate + " (" + aLong + "), but got " + " "
                          + otherDate + " (" + oLong + ") = " + str3 + " not "
                          + dd.ToString());
                }
                else
                {
                    Logln("Parsed OK: " + expected);
                }
            }
            catch (ILOG.J2CsMapping.Util.ParseException pe)
            {
                Errln("FAIL: ParseException: " + pe.ToString());
                Console.Error.WriteLine(pe.StackTrace);
            }
        }