Example #1
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);
            }
        }