Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
 public void TestLimits()
 {
     IBM.ICU.Util.Calendar cal = IBM.ICU.Util.Calendar.GetInstance();
     cal.Set(2007, IBM.ICU.Util.Calendar.JANUARY, 1);
     IBM.ICU.Util.HebrewCalendar hebrew = new IBM.ICU.Util.HebrewCalendar();
     DoLimitsTest(hebrew, null, cal.GetTime());
     DoTheoreticalLimitsTest(hebrew, true);
 }
Ejemplo n.º 3
0
        public void TestLimits()
        {
            IBM.ICU.Util.Calendar cal = IBM.ICU.Util.Calendar.GetInstance();
            cal.Set(2007, IBM.ICU.Util.Calendar.JANUARY, 1);
            IslamicCalendar islamic = NewCivil();

            DoLimitsTest(islamic, null, cal.GetTime());
            DoTheoreticalLimitsTest(islamic, true);
        }
Ejemplo n.º 4
0
 public void TestLimits()
 {
     IBM.ICU.Util.Calendar cal = IBM.ICU.Util.Calendar.GetInstance();
     cal.Set(2007, IBM.ICU.Util.Calendar.JANUARY, 1);
     CopticCalendar coptic = new CopticCalendar();
     if (!SkipIfBeforeICU(3, 9, 0))
     {
         DoLimitsTest(coptic, null, cal.GetTime());
     }
     DoTheoreticalLimitsTest(coptic, true);
 }
Ejemplo n.º 5
0
        public void TestLimits()
        {
            // The number of days and the start date can be adjusted
            // arbitrarily to either speed up the test or make it more
            // thorough, but try to test at least a full year, preferably a
            // full non-leap and a full leap year.

            // Final parameter is either number of days, if > 0, or test
            // duration in seconds, if < 0.
            IBM.ICU.Util.Calendar tempcal = IBM.ICU.Util.Calendar.GetInstance();
            tempcal.Clear();
            tempcal.Set(1989, IBM.ICU.Util.Calendar.NOVEMBER, 1);
            ChineseCalendar chinese = new ChineseCalendar();

            if (!SkipIfBeforeICU(3, 9, 0))
            {
                DoLimitsTest(chinese, null, tempcal.GetTime());
            }
            DoTheoreticalLimitsTest(chinese, true);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        public void TestFormat()
        {
            ChineseCalendar cal = new ChineseCalendar();
            DateFormat      fmt = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal,
                                                                              IBM.ICU.Text.DateFormat.DEFAULT, IBM.ICU.Text.DateFormat.DEFAULT);

            IBM.ICU.Util.Calendar tempcal = IBM.ICU.Util.Calendar.GetInstance();
            tempcal.Clear();

            DateTime[] DATA = new DateTime[2];
            tempcal.Set(2001, IBM.ICU.Util.Calendar.MAY, 22);
            DATA[0] = tempcal.GetTime();
            tempcal.Set(2001, IBM.ICU.Util.Calendar.MAY, 23);
            DATA[1] = tempcal.GetTime();
            // Wed May 23 2001 = Month 4(leap), Day 1, Year 18, Cycle 78

            for (int i = 0; i < DATA.Length; ++i)
            {
                String s = fmt.Format(DATA[i]);
                try
                {
                    DateTime e = fmt.Parse(s);
                    if (e.Equals(DATA[i]))
                    {
                        Logln("Ok: " + DATA[i] + " -> " + s + " -> " + e);
                    }
                    else
                    {
                        Errln("FAIL: " + DATA[i] + " -> " + s + " -> " + e);
                    }
                }
                catch (ILOG.J2CsMapping.Util.ParseException e_0)
                {
                    Errln("Fail: " + s + " -> parse failure at "
                          + e_0.GetErrorOffset());
                    Errln(e_0.ToString());
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        ///
        /// @stable ICU 2.0
        protected internal override int SubParse(String text, int start, char ch, int count,
                                                 bool obeyCount, bool allowNegative, bool[] ambiguousYear,
                                                 IBM.ICU.Util.Calendar cal)
        {
            if (ch != 'G' && ch != 'l' && ch != 'y')
            {
                return(base.SubParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal));
            }

            // Skip whitespace
            start = IBM.ICU.Impl.Utility.SkipWhitespace(text, start);

            ParsePosition pos = new ParsePosition(start);

            switch ((int)ch)
            {
            case 'G':     // 'G' - ERA
            case 'y':     // 'y' - YEAR, but without the 2-digit Y2K adjustment
            {
                object number = null;
                if (obeyCount)
                {
                    if ((start + count) > text.Length)
                    {
                        return(-start);
                    }
                    number = numberFormat.Parse(text.Substring(0, (start + count) - (0)),
                                                pos);
                }
                else
                {
                    number = numberFormat.Parse(text, pos);
                }
                if (number == null)
                {
                    return(-start);
                }
                int value_ren = System.Convert.ToInt32(number);
                cal.Set((ch == 'G') ? IBM.ICU.Util.Calendar.ERA : IBM.ICU.Util.Calendar.YEAR, value_ren);
                return(pos.GetIndex());
            }

            case 'l':     // 'l' - IS_LEAP_MONTH
            {
                ChineseDateFormatSymbols symbols = (ChineseDateFormatSymbols)GetSymbols();
                int result = MatchString(text, start,
                                         IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, symbols.isLeapMonth, cal);
                // Treat the absence of any matching string as setting
                // IS_LEAP_MONTH to false.
                if (result < 0)
                {
                    cal.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, 0);
                    result = start;
                }
                return(result);
            }

            default:
                // /CLOVER:OFF
                return(0);    // This can never happen
                // /CLOVER:ON
            }
        }
Ejemplo n.º 9
0
        // 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.
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Construct a ChineseDateFormatSymbols for the provided calendar and
 /// locale.
 /// </summary>
 ///
 /// <param name="cal">the Calendar</param>
 /// <param name="locale">the locale</param>
 /// @stable ICU 3.2
 public ChineseDateFormatSymbols(IBM.ICU.Util.Calendar cal, ULocale locale)
     : base((cal == null) ? null : ((object)cal).GetType(), locale)
 {
 }
Ejemplo n.º 11
0
        public void TestMapping()
        {
            int[] DATA =
            {
                // (Note: months are 1-based)
                // Gregorian Chinese
                1964,  9,    4, 4601,    7,  0,   28, 1964,  9,    5, 4601,    7, 0,   29, 1964,
                9,     6, 4601,    8,    0,  1, 1964,    9,  7, 4601,    8,    0, 2, 1961,   12, 25,
                4598, 11,    0,   18, 1999,  6,    4, 4636,  4,    0,   21,

                1990,  5,   23, 4627,    4,  0,   29, 1990,  5,   24, 4627,    5, 0,    1, 1990,
                6,    22, 4627,    5,    0, 30, 1990,    6, 23, 4627,    5,    1, 1, 1990,    7, 20,
                4627,  5,    1,   28, 1990,  7,   21, 4627,  5,    1,   29, 1990, 7,   22, 4627,
                6,     0,    1,
            };

            ChineseCalendar cal = new ChineseCalendar();
            StringBuilder   buf = new StringBuilder();

            Logln("Gregorian -> Chinese");
            // java.util.Calendar grego = java.util.Calendar.getInstance();
            IBM.ICU.Util.Calendar grego = IBM.ICU.Util.Calendar.GetInstance();
            grego.Clear();
            for (int i = 0; i < DATA.Length;)
            {
                grego.Set(DATA[i++], DATA[i++] - 1, DATA[i++]);
                DateTime date = grego.GetTime();
                cal.SetTime(date);
                int y  = cal.Get(IBM.ICU.Util.Calendar.EXTENDED_YEAR);
                int m  = cal.Get(IBM.ICU.Util.Calendar.MONTH) + 1; // 0-based -> 1-based
                int L  = cal.Get(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH);
                int d  = cal.Get(IBM.ICU.Util.Calendar.DAY_OF_MONTH);
                int yE = DATA[i++]; // Expected y, m, isLeapMonth, d
                int mE = DATA[i++]; // 1-based
                int LE = DATA[i++];
                int dE = DATA[i++];
                buf.Length = 0;
                buf.Append(date + " -> ");
                buf.Append(y + "/" + m + ((L == 1) ? "(leap)" : "") + "/" + d);
                if (y == yE && m == mE && L == LE && d == dE)
                {
                    Logln("OK: " + buf.ToString());
                }
                else
                {
                    Errln("Fail: " + buf.ToString() + ", expected " + yE + "/" + mE
                          + ((LE == 1) ? "(leap)" : "") + "/" + dE);
                }
            }

            Logln("Chinese -> Gregorian");
            for (int i_0 = 0; i_0 < DATA.Length;)
            {
                grego.Set(DATA[i_0++], DATA[i_0++] - 1, DATA[i_0++]);
                DateTime dexp         = grego.GetTime();
                int      cyear        = DATA[i_0++];
                int      cmonth       = DATA[i_0++];
                int      cisleapmonth = DATA[i_0++];
                int      cdayofmonth  = DATA[i_0++];
                cal.Clear();
                cal.Set(IBM.ICU.Util.Calendar.EXTENDED_YEAR, cyear);
                cal.Set(IBM.ICU.Util.Calendar.MONTH, cmonth - 1);
                cal.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, cisleapmonth);
                cal.Set(IBM.ICU.Util.Calendar.DAY_OF_MONTH, cdayofmonth);
                DateTime date_1 = cal.GetTime();
                buf.Length = 0;
                buf.Append(cyear + "/" + cmonth
                           + ((cisleapmonth == 1) ? "(leap)" : "") + "/" + cdayofmonth);
                buf.Append(" -> " + date_1);
                if (date_1.Equals(dexp))
                {
                    Logln("OK: " + buf.ToString());
                }
                else
                {
                    Errln("Fail: " + buf.ToString() + ", expected " + dexp);
                }
            }
        }