Пример #1
0
 public void TestEraStart()
 {
     CopticCalendar cal = new CopticCalendar(0, 0, 1);
     IBM.ICU.Text.SimpleDateFormat fmt = new IBM.ICU.Text.SimpleDateFormat("EEE MMM dd, yyyy GG");
     AssertEquals("Coptic Date", "Thu Jan 01, 0000 AD", fmt.FormatObject(cal));
     AssertEquals("Gregorian Date", "Thu Aug 30, 0283 AD",
             fmt.Format(cal.GetTime()));
 }
Пример #2
0
 /// <summary>
 /// Returns a string representing the formatted date.
 /// </summary>
 ///
 /// <param name="date">the date</param>
 public virtual String Format(DateTime date)
 {
     lock (this) {
         if (df == null)
         {
             // ignores requested fields
             // todo: make this really work
         }
     }
     return(df.Format(date));
 }
Пример #3
0
        /// <summary>
        /// Iterates through a list of calendar <c>TestCase</c> objects and
        /// makes sure that the time-to-fields and fields-to-time calculations work
        /// correnctly for the values in each test case.
        /// </summary>
        ///
        public void DoTestCases(TestCase[] cases, Calendar cal)
        {
            cal.SetTimeZone(UTC);

            // Get a format to use for printing dates in the calendar system we're
            // testing
            IBM.ICU.Text.DateFormat format = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal,
                                                                                         IBM.ICU.Text.DateFormat.SHORT, -1, ILOG.J2CsMapping.Util.Locale.GetDefault());

            String pattern = (cal  is  ChineseCalendar) ? "E MMl/dd/y G HH:mm:ss.S z"
                        : "E, MM/dd/yyyy G HH:mm:ss.S z";

            ((IBM.ICU.Text.SimpleDateFormat)format).ApplyPattern(pattern);

            // This format is used for printing Gregorian dates.
            IBM.ICU.Text.DateFormat gregFormat = new IBM.ICU.Text.SimpleDateFormat(pattern);
            gregFormat.SetTimeZone(UTC);

            GregorianCalendar pureGreg = new GregorianCalendar(UTC);

            pureGreg.SetGregorianChange(ILOG.J2CsMapping.Util.DateUtil.DateFromJavaMillis(Int64.MinValue));
            IBM.ICU.Text.DateFormat pureGregFmt = new IBM.ICU.Text.SimpleDateFormat("E M/d/yyyy G");
            pureGregFmt.SetCalendar(pureGreg);

            // Now iterate through the test cases and see what happens
            for (int i = 0; i < cases.Length; i++)
            {
                Logln("\ntest case: " + i);
                //throw new NotImplementedException();

                TestCase test = cases[i];

                //
                // First we want to make sure that the millis -> fields calculation
                // works
                // test.applyTime will call setTime() on the calendar object, and
                // test.fieldsEqual will retrieve all of the field values and make
                // sure
                // that they're the same as the ones in the testcase
                //
                test.ApplyTime(cal);
                if (!test.FieldsEqual(cal, this))
                {
                    Errln("Fail: (millis=>fields) "
                          + gregFormat.Format(test.GetTime()) + " => "
                          + format.Format(cal.GetTime()) + ", expected " + test);
                }

                //
                // If that was OK, check the fields -> millis calculation
                // test.applyFields will set all of the calendar's fields to
                // match those in the test case.
                //
                cal.Clear();
                test.ApplyFields(cal);
                if (!test.Equals(cal))
                {
                    Errln("Fail: (fields=>millis) " + test + " => "
                          + pureGregFmt.Format(cal.GetTime()) + ", expected "
                          + pureGregFmt.Format(test.GetTime()));
                }
            }
        }