示例#1
0
        private void CheckExpected(IBM.ICU.Util.Calendar c, int[] expected)
        {
            String[] FIELD_NAME = { "ERA",                  "YEAR",         "MONTH",         "WEEK_OF_YEAR",
                                    "WEEK_OF_MONTH",        "DAY_OF_MONTH", "DAY_OF_YEAR",   "DAY_OF_WEEK",
                                    "DAY_OF_WEEK_IN_MONTH", "AM_PM",        "HOUR",          "HOUR_OF_DAY",
                                    "MINUTE",               "SECOND",       "MILLISECOND",   "ZONE_OFFSET", "DST_OFFSET",
                                    "YEAR_WOY",             "DOW_LOCAL",    "EXTENDED_YEAR", "JULIAN_DAY",
                                    "MILLISECONDS_IN_DAY",  };

            for (int i = 0; i < expected.Length; i += 2)
            {
                int fieldNum    = expected[i + 0];
                int expectedVal = expected[i + 1];
                int actualVal   = c.Get(fieldNum);

                if (expectedVal == actualVal)
                {
                    Logln(FIELD_NAME[fieldNum] + ": " + actualVal);
                }
                else
                {
                    Errln("FAIL: " + FIELD_NAME[fieldNum] + ": expected "
                          + expectedVal + " got " + actualVal);
                }
            }
        }
示例#2
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);
            }
        }
        // NOTE: This API still exists; we just inherit it from SimpleDateFormat
        // as of ICU 3.0
        // /**
        // * @stable ICU 2.0
        // */
        // protected String subFormat(char ch, int count, int beginOffset,
        // FieldPosition pos, DateFormatSymbols formatData,
        // Calendar cal) {
        // switch (ch) {
        // case 'G': // 'G' - ERA
        // return zeroPaddingNumber(cal.get(Calendar.ERA), 1, 9);
        // case 'l': // 'l' - IS_LEAP_MONTH
        // {
        // ChineseDateFormatSymbols symbols =
        // (ChineseDateFormatSymbols) formatData;
        // return symbols.getLeapMonth(cal.get(
        // ChineseCalendar.IS_LEAP_MONTH));
        // }
        // default:
        // return super.subFormat(ch, count, beginOffset, pos, formatData, cal);
        // }
        // }

        /// <exclude/>
        /// <summary>
        ///
        /// </summary>
        ///
        protected internal override void SubFormat(StringBuilder buf, char ch, int count,
                                                   int beginOffset, FieldPosition pos, IBM.ICU.Util.Calendar cal)
        {
            switch ((int)ch)
            {
            case 'G':     // 'G' - ERA
                ZeroPaddingNumber(buf, cal.Get(IBM.ICU.Util.Calendar.ERA), 1, 9);
                break;

            case 'l':     // 'l' - IS_LEAP_MONTH
                buf.Append(((ChineseDateFormatSymbols)GetSymbols())
                           .GetLeapMonth(cal.Get(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH)));
                break;

            default:
                base.SubFormat(buf, ch, count, beginOffset, pos, cal);
                break;
            }

            // TODO: add code to set FieldPosition for 'G' and 'l' fields. This
            // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the
            // code that handles this at the end of SimpleDateFormat.subFormat.
            // The logic should be moved up into SimpleDateFormat.format.
        }