示例#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>
        /// Creates a new formatter that formats the requested fields using the
        /// provided locale and time zone.
        /// </summary>
        ///
        /// <param name="requestedFields_0">the requested fields</param>
        /// <param name="localeName_1">the locale to use</param>
        /// <param name="timeZone_2">the time zone to use</param>
        public YMDDateFormatter(String requestedFields_0, String localeName_1,
                                IBM.ICU.Util.TimeZone timeZone_2)
        {
            this.requestedFields = requestedFields_0;
            this.localeName      = localeName_1;
            this.timeZone        = timeZone_2;

            Locale locale = IBM.ICU.Impl.Duration.Impl.Utils.LocaleFromString(localeName_1);

            this.df = new SimpleDateFormat("yyyy/mm/dd", locale);
            this.df.SetTimeZone(timeZone_2);
        }
 public void Test_equalsLjava_lang_Object()
 {
     // Test for method boolean
     // java.text.IBM.ICU.Text.MessageFormat.equals(java.lang.Object)
     IBM.ICU.Text.MessageFormat format1_0 = new IBM.ICU.Text.MessageFormat("{0}");
     IBM.ICU.Text.MessageFormat format2_1 = new IBM.ICU.Text.MessageFormat("{1}");
     NUnit.Framework.Assert.IsTrue(!format1_0.Equals(format2_1), "Should not be equal");
     format2_1.ApplyPattern("{0}");
     NUnit.Framework.Assert.IsTrue(format1_0.Equals(format2_1), "Should be equal");
     IBM.ICU.Text.SimpleDateFormat date = (IBM.ICU.Text.SimpleDateFormat)IBM.ICU.Text.DateFormat.GetTimeInstance();
     format1_0.SetFormat(0, IBM.ICU.Text.DateFormat.GetTimeInstance());
     format2_1.SetFormat(0, new IBM.ICU.Text.SimpleDateFormat(date.ToPattern()));
     NUnit.Framework.Assert.IsTrue(format1_0.Equals(format2_1), "Should be equal2");
 }
示例#4
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()));
                }
            }
        }
示例#5
0
        /// <exclude/>
        /// <summary>
        /// The public version of this API only accepts LONG/SHORT, the internal
        /// version (which this calls) also accepts LONG_GENERIC/SHORT_GENERIC.
        /// </summary>
        ///
        private String _getDisplayName(bool daylight, int style, ULocale locale)
        {
            /*
             * NOTES: (1) We use SimpleDateFormat for simplicity; we could do this
             * more efficiently but it would duplicate the SimpleDateFormat code
             * here, which is undesirable. (2) Attempts to move the code from
             * SimpleDateFormat to here also run aground because this requires
             * SimpleDateFormat to keep a Locale object around, which it currently
             * doesn't; to synthesize such a locale upon resurrection; and to
             * somehow handle the special case of construction from a
             * DateFormatSymbols object.
             */

            // We keep a cache, indexed by locale. The cache contains a
            // SimpleDateFormat object, which we create on demand.
            WeakReference data = (WeakReference)cachedLocaleData[locale];

            IBM.ICU.Text.SimpleDateFormat format;
            if (data == null || (format = (IBM.ICU.Text.SimpleDateFormat)data.Target) == null)
            {
                format = new IBM.ICU.Text.SimpleDateFormat(null, locale);
                ILOG.J2CsMapping.Collections.Collections.Put(cachedLocaleData, locale, new WeakReference(format));
            }

            String[] patterns = { "z", "zzzz", "v", "vvvv" };
            format.ApplyPattern(patterns[style]);
            if (style >= 2)
            {
                // Generic names may change time to time even for a single time
                // zone.
                // This method returns the one used for the zone now.
                format.SetTimeZone(this);
                return(format.Format(DateTime.Now));
            }
            else
            {
                // Create a new SimpleTimeZone as a stand-in for this zone; the
                // stand-in
                // will have no DST, or DST during January, but the same ID and
                // offset,
                // and hence the same display name. We don't cache these because
                // they're small and cheap to create.
                SimpleTimeZone tz;
                if (daylight && UseDaylightTime())
                {
                    int savings = GetDSTSavings();
                    tz = new SimpleTimeZone(GetRawOffset(), GetID(),
                                            IBM.ICU.Util.Calendar.JANUARY, 1, 0, 0, IBM.ICU.Util.Calendar.FEBRUARY, 1, 0, 0,
                                            savings);
                }
                else
                {
                    tz = new SimpleTimeZone(GetRawOffset(), GetID());
                }
                format.SetTimeZone(tz);
                // Format a date in January. We use the value 10*ONE_DAY == Jan 11
                // 1970
                // 0:00 GMT.
                return(format.Format(new DateTime((864000000L) * 10000)));
            }
        }