Esempio n. 1
0
        public void TestJapaneseYear3282()
        {
            IBM.ICU.Util.Calendar c = IBM.ICU.Util.Calendar.GetInstance(IBM.ICU.Util.ULocale.ENGLISH);
            c.Set(2003, IBM.ICU.Util.Calendar.SEPTEMBER, 25);
            IBM.ICU.Util.JapaneseCalendar jcal = new IBM.ICU.Util.JapaneseCalendar();
            // jcal.setTime(new Date(1187906308151L)); alternate value
            jcal.SetTime(c.GetTime());
            Logln("Now is: " + jcal.GetTime());
            c.SetTime(jcal.GetTime());
            int nowYear = c.Get(IBM.ICU.Util.Calendar.YEAR);

            Logln("Now year: " + nowYear);
            SimpleDateFormat jdf = (SimpleDateFormat)IBM.ICU.Text.DateFormat
                                   .GetDateInstance(jcal, IBM.ICU.Text.DateFormat.DEFAULT,
                                                    ILOG.J2CsMapping.Util.Locale.GetDefault());

            jdf.ApplyPattern("G yy/MM/dd");
            String text = jdf.Format(jcal.GetTime());

            Logln("Now is: " + text + " (in Japan)");
            try
            {
                DateTime date = jdf.Parse(text);
                Logln("But is this not the date?: " + date);
                c.SetTime(date);
                int thenYear = c.Get(IBM.ICU.Util.Calendar.YEAR);
                Logln("Then year: " + thenYear);
                if (thenYear != nowYear)
                {
                    Errln("Nowyear " + nowYear + " is not thenyear " + thenYear);
                }
                else
                {
                    Logln("Nowyear " + nowYear + " == thenyear " + thenYear);
                }
            }
            catch (ILOG.J2CsMapping.Util.ParseException ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
            }
        }
Esempio 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));
                    }
                }
            }
        }