android.icu.text.SimpleDateFormat Java Examples

The following examples show how to use android.icu.text.SimpleDateFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4103340
 * @bug 4138203
 * This bug really only works in Locale.US, since that's what the locale
 * used for Date.toString() is.  Bug 4138203 reports that it fails on Korean
 * NT; it would actually have failed on any non-US locale.  Now it should
 * work on all locales.
 */
@Test
public void Test4103340() {

    // choose a date that is the FIRST of some month 
    // and some arbitrary time
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1997, 3, 1, 1, 1, 1);
    Date d = cal.getTime(); 
    SimpleDateFormat df = new SimpleDateFormat("MMMM", Locale.US);
    String s = d.toString();
    StringBuffer s2 = new StringBuffer("");
    FieldPosition pos = new FieldPosition(0);
    s2 = df.format(d, s2, pos);
    logln("Date=" + s); 
    logln("DF=" + s2);
    String substr = s2.substring(0,2);
    if (s.indexOf(substr) == -1)
      errln("Months should match");
}
 
Example #2
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestParsing() {
    String pattern = "EEE-WW-MMMM-yyyy";
    String text = "mon-02-march-2011";
    int expectedDay = 7;

    SimpleDateFormat format = new SimpleDateFormat(pattern);
    Calendar cal = GregorianCalendar.getInstance(Locale.US);
    ParsePosition pos = new ParsePosition(0);
    
    try {
        format.parse(text, cal, pos);
    } catch (Exception e) {
        errln("Fail parsing:  " + e);
    }

    if (cal.get(Calendar.DAY_OF_MONTH) != expectedDay) {
        errln("Parsing failed: day of month should be '7' with pattern: \"" + pattern + "\" for text: \"" + text + "\"");
    }
}
 
Example #3
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestT10906()
{
    String pattern = new String("MM-dd-yyyy");
    String text = new String("06-10-2014");
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    ParsePosition pp = new ParsePosition(-1);
    try {
        format.parse(text, pp);
        int errorIdx = pp.getErrorIndex();
        if (errorIdx == -1) {          
            errln("failed to report invalid (negative) starting parse position");
        }
    } catch(StringIndexOutOfBoundsException e) {
        errln("failed to fix invalid (negative) starting parse position");
    }

}
 
Example #4
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4104522
 * CANNOT REPRODUCE
 * According to the bug report, this test should throw a
 * StringIndexOutOfBoundsException during the second parse.  However,
 * this is not seen.
 */
@Test
public void Test4104522() {
    SimpleDateFormat sdf = new SimpleDateFormat();
    String pattern = "'time' hh:mm";
    sdf.applyPattern(pattern);
    logln("pattern: \"" + pattern + "\"");
    // works correctly
    ParsePosition pp = new ParsePosition(0);
    String text = "time ";
    Date dt = sdf.parse(text, pp);
    logln(" text: \"" + text + "\"" + " date: " + dt);
    // works wrong
    pp.setIndex(0);
    text = "time";
    dt = sdf.parse(text, pp);
    logln(" text: \"" + text + "\"" + " date: " + dt);    
}
 
Example #5
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4151706
 * 'z' at end of date format throws index exception in SimpleDateFormat
 * CANNOT REPRODUCE THIS BUG ON 1.2FCS
 */
@Test
public void Test4151706() {
    String dateString = "Thursday, 31-Dec-98 23:00:00 GMT";
    SimpleDateFormat fmt = new SimpleDateFormat("EEEE, dd-MMM-yy HH:mm:ss z", Locale.US);
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US);
    cal.clear();
    cal.set(1998, Calendar.DECEMBER, 31, 23, 0, 0);
    Date d = new Date();
    try {
        d = fmt.parse(dateString);
        // {sfb} what about next two lines?
        if (d.getTime() != cal.getTime().getTime())
            errln("Incorrect value: " + d);
    } catch (Exception e) {
        errln("Fail: " + e);
    }
    StringBuffer temp = new StringBuffer("");
    FieldPosition pos = new FieldPosition(0);
    logln(dateString + " . " + fmt.format(d, temp, pos));
}
 
Example #6
Source File: EthiopicTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestEraStart() {
    SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd, yyyy GG");
    fmt.setCalendar(new EthiopicCalendar());

    EthiopicCalendar cal = new EthiopicCalendar(1, 0, 1);
    assertEquals("Ethiopic Date", "Wed Jan 01, 0001 AD", fmt.format(cal));

    cal.set(Calendar.ERA, 0);
    cal.set(Calendar.YEAR, 5500);
    assertEquals("Ethiopic Date", "Tue Jan 01, 5500 BC", fmt.format(cal));

    // The gregorian calendar gets off by two days when
    // the date gets low, unless the gregorian changeover is set to 
    // very early.  The funny thing is, it's ok for dates in the year
    // 283, but not in the year 7, and it claims to be ok until the year 4.
    // should track down when the dates start to differ...
    
    GregorianCalendar gc = new GregorianCalendar();
    gc.setGregorianChange(new Date(Long.MIN_VALUE)); // act like proleptic Gregorian
    gc.setTime(cal.getTime());
    fmt.setCalendar(new GregorianCalendar());
    assertEquals("Gregorian Date", "Tue Aug 28, 0007 AD", fmt.format(gc));
}
 
Example #7
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4151631
 * SimpleDateFormat incorrect handling of 2 single quotes in format()
 */
@Test
public void Test4151631() {
    String pattern = 
        "'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'"; 
    logln("pattern=" + pattern);
    SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.US);
    StringBuffer result = new StringBuffer("");
    FieldPosition pos = new FieldPosition(0);
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1998, Calendar.JUNE, 30, 13, 30, 0);
    Date d = cal.getTime();
    result = format.format(d, result, pos); 
    if (!result.toString().equals("TO_DATE('30-06-1998 13:30:00' , 'DD-MM-YYYY HH:MI:SS')")) {
        errln("Fail: result=" + result);
    } else {
        logln("Pass: result=" + result);
    }
}
 
Example #8
Source File: TestCLDRVsICU.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private SimpleDateFormat getDateFormat(ULocale locale, int dateFormat, int timeFormat) {
    if (DEBUG)
        logln("Getting date/time format for " + locale);
    if (DEBUG && "ar_EG".equals(locale.toString())) {
        logln("debug here");
    }
    DateFormat dt;
    if (dateFormat == 0) {
        dt = DateFormat.getTimeInstance(DateFormatValues[timeFormat], locale);
        if (DEBUG)
            System.out.print("getTimeInstance");
    } else if (timeFormat == 0) {
        dt = DateFormat.getDateInstance(DateFormatValues[dateFormat], locale);
        if (DEBUG)
            System.out.print("getDateInstance");
    } else {
        dt = DateFormat.getDateTimeInstance(DateFormatValues[dateFormat], DateFormatValues[timeFormat],
                locale);
        if (DEBUG)
            System.out.print("getDateTimeInstance");
    }
    if (DEBUG)
        logln("\tinput:\t" + dateFormat + ", " + timeFormat + " => " + ((SimpleDateFormat) dt).toPattern());
    return (SimpleDateFormat) dt;
}
 
Example #9
Source File: DatePickerCalendarDelegate.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLocaleChanged(Locale locale) {
    final TextView headerYear = mHeaderYear;
    if (headerYear == null) {
        // Abort, we haven't initialized yet. This method will get called
        // again later after everything has been set up.
        return;
    }

    // Update the date formatter.
    final String datePattern = DateFormatFix.getBestDateTimePattern(mContext, locale, "EMMMd");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        mMonthDayFormat = new SimpleDateFormat(datePattern, locale);
        ((SimpleDateFormat) mMonthDayFormat).setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
        mYearFormat = new SimpleDateFormat("y", locale);
    } else {
        mMonthDayFormat = new java.text.SimpleDateFormat(datePattern, locale);
        mYearFormat = new java.text.SimpleDateFormat("y", locale);
    }

    // Clear out the lazily-initialized accessibility event formatter.
    mAccessibilityEventFormat = null;

    // Update the header text.
    onCurrentDateChanged(false);
}
 
Example #10
Source File: FileSystem.java    From pixelvisualcorecamera with Apache License 2.0 6 votes vote down vote up
File build() {
  File storageDir = getStorageDir();
  if (storageDir == null) {
    return null;
  }

  // Create a media file name
  StringBuilder imageFilePathBuilder = new StringBuilder(storageDir.getPath())
      .append(File.separator)
      .append("IMG_")
      .append(new SimpleDateFormat("yyyyMMdd_HHmmss_SSS").format(new Date()));
  if (api1) {
    imageFilePathBuilder.append("_1");
  } else if (api2) {
    imageFilePathBuilder.append("_2");
  }
  imageFilePathBuilder.append(".jpg");
  return new File(imageFilePathBuilder.toString());
}
 
Example #11
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4061476() {
    SimpleDateFormat fmt = new SimpleDateFormat("ddMMMyy", Locale.UK);
    Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), 
                                                 Locale.UK);
    fmt.setCalendar(cal);
    try
        {
            Date date = fmt.parse("29MAY97");
            cal.setTime(date);
        }
    catch (Exception e) {
        System.out.print("");
    }
    cal.set(Calendar.HOUR_OF_DAY, 13);
    logln("Hour: "+cal.get(Calendar.HOUR_OF_DAY));
    cal.add(Calendar.HOUR_OF_DAY, 6);
    logln("Hour: "+cal.get(Calendar.HOUR_OF_DAY));
    if (cal.get(Calendar.HOUR_OF_DAY) != 19)
        errln("Fail: Want 19 Got " + cal.get(Calendar.HOUR_OF_DAY));
}
 
Example #12
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for ticket 9968
 * subparse fails to return an error indication when start pos is 0 
 */
@Test
public void TestT9968() {
    SimpleDateFormat sdf0 = new SimpleDateFormat("-MMMM");
    ParsePosition pos0 = new ParsePosition(0);
    /* Date d0 = */ sdf0.parse("-September", pos0);
    logln("sdf0: " + pos0.getErrorIndex() + "/" + pos0.getIndex());
    assertTrue("Fail: failed a good test", pos0.getErrorIndex() == -1);

    SimpleDateFormat sdf1 = new SimpleDateFormat("-MMMM");
    ParsePosition pos1 = new ParsePosition(0);
    /* Date d1 = */ sdf1.parse("-????", pos1);
    logln("sdf1: " + pos1.getErrorIndex() + "/" + pos1.getIndex());
    assertTrue("Fail: failed to detect bad parse", pos1.getErrorIndex() == 1);

    SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM");
    ParsePosition pos2 = new ParsePosition(0);
    /* Date d2 = */ sdf2.parse("????", pos2);
    logln("sdf2: " + pos2.getErrorIndex() + "/" + pos2.getIndex());
    assertTrue("Fail: failed to detect bad parse", pos2.getErrorIndex() == 0);
}
 
Example #13
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4089106
 */
@Test
public void Test4089106() {
    TimeZone def = TimeZone.getDefault();
    try {
        TimeZone z = new SimpleTimeZone((int) (1.25 * 3600000), "FAKEZONE");
        TimeZone.setDefault(z);
        // Android patch (http://b/28949992) start.
        // ICU TimeZone.setDefault() not supported on Android.
        z = TimeZone.getDefault();
        // Android patch (http://b/28949992) end.
        SimpleDateFormat f = new SimpleDateFormat();
        if (!f.getTimeZone().equals(z))
            errln("Fail: SimpleTimeZone should use TimeZone.getDefault()");
    } finally {
        TimeZone.setDefault(def);
    }
}
 
Example #14
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void aux917(SimpleDateFormat fmt, String str) {

    String pat = fmt.toPattern();
    logln("==================");
    logln("testIt: pattern=" + pat + " string=" + str);
    ParsePosition pos = new ParsePosition(0);
    Object o = fmt.parseObject(str, pos);
    //logln( UnicodeString("Parsed object: ") + o );

    StringBuffer formatted = new StringBuffer("");
    FieldPosition poss = new FieldPosition(0);
    formatted = fmt.format(o, formatted, poss);

    logln("Formatted string: " + formatted);
    if (!formatted.toString().equals(str))
        errln("Fail: Want " + str + " Got " + formatted);
}
 
Example #15
Source File: DateTimeGeneratorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void DayMonthTest() {
    final ULocale locale = ULocale.FRANCE;

    // set up the generator
    DateTimePatternGenerator dtpgen
    = DateTimePatternGenerator.getInstance(locale);

    // get a pattern for an abbreviated month and day
    final String pattern = dtpgen.getBestPattern("MMMd");
    SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);

    // use it to format (or parse)
    String formatted = formatter.format(new Date());
    logln("formatted=" + formatted);
    // for French, the result is "13 sept."
}
 
Example #16
Source File: IntlTestSimpleDateFormatAPI.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestCoverage(){
    class StubDateFormat extends SimpleDateFormat{
        /**
         * For serialization
         */
        private static final long serialVersionUID = 8460897119491427934L;

        public void run(){
            if (!zeroPaddingNumber(12, 4, 6).equals("0012")){
                errln("SimpleDateFormat(zeroPaddingNumber(long , int , int )");
            }
        }
    }
    new StubDateFormat().run();
}
 
Example #17
Source File: TestMessageFormat.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestSetFormat() {
    MessageFormat ms = new MessageFormat("{number} {date}", ULocale.ENGLISH);
    final DecimalFormat decimalFormat = new DecimalFormat("000.000", DecimalFormatSymbols.getInstance(ULocale.ENGLISH));
    ms.setFormatByArgumentName("number", decimalFormat);
    final SimpleDateFormat dateFormat = new SimpleDateFormat("'year:'yy 'month:'MM 'day:'dd");
    dateFormat.setTimeZone(TimeZone.getTimeZone("Etc/GMT"));
    ms.setFormatByArgumentName("date", dateFormat);
    Map map = new HashMap();
    map.put("number", new Integer(1234));
    map.put("date", new Date(0,0,0));
    String result = ms.format(map);
    assertEquals("setFormatByArgumentName", "1234.000 year:99 month:12 day:31", result);
    Set formatNames = ms.getArgumentNames();
    assertEquals("Format Names match", formatNames, map.keySet());
    assertEquals("Decimal", decimalFormat, ms.getFormatByArgumentName("number"));
    assertEquals("Date", dateFormat, ms.getFormatByArgumentName("date"));
}
 
Example #18
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4148168() {
        Date d = new Date(1002705212906L);
        String[] ISOPattern = {
            "''yyyy-MM-dd-hh.mm.ss.S''", "''yyyy-MM-dd-hh.mm.ss.SS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSS''", "''yyyy-MM-dd-hh.mm.ss.SSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSSSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSS000''"};
        SimpleDateFormat aSimpleDF = (SimpleDateFormat)DateFormat.getDateTimeInstance();

        for(int i = 0; i<ISOPattern.length; i++) {
            aSimpleDF.applyPattern( ISOPattern[i] );
            logln( "Pattern = " + aSimpleDF.toPattern());
            logln( "Format = " + aSimpleDF.format(d));
        }
}
 
Example #19
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4253490() {
    Date d = new Date(1002705212231L);

    String[] ISOPattern = {
            "''yyyy-MM-dd-hh.mm.ss.S''", 
            "''yyyy-MM-dd-hh.mm.ss.SS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSSSS''"}; 

    SimpleDateFormat aSimpleDF = (SimpleDateFormat) DateFormat.getDateTimeInstance();
    for (int i = 0; i < ISOPattern.length; i++) {
        aSimpleDF.applyPattern(ISOPattern[i]);
        logln("Pattern = " + aSimpleDF.toPattern());
        logln("Format = " + aSimpleDF.format(d));
    }
}
 
Example #20
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void run() {
    SimpleDateFormat sdf = (SimpleDateFormat) sdf_.clone();
    TimeZone defaultTZ = TimeZone.getDefault();
    TimeZone PST = TimeZone.getTimeZone("PST");
    int defaultOffset = defaultTZ.getRawOffset();
    int PSTOffset = PST.getRawOffset();
    int offset = defaultOffset - PSTOffset;
    long ms = UTC_LONG - offset;
    try {
        int i = 0;
        while (i < 10000) {
            Date date = sdf.parse(TIME_STRING);
            long t = date.getTime();
            i++;
            if (t != ms) {
                throw new ParseException("Parse Error: " + i + " (" + sdf.format(date) 
                          + ") " + t + " != " + ms, 0);
            }
        }
    } catch (Exception e) {
        errln("parse error: " + e.getMessage());
    }
}
 
Example #21
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4358730() {
    SimpleDateFormat sdf = new SimpleDateFormat();
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(2001,11,10);
    Date today = cal.getTime();

    sdf.applyPattern("MM d y");
    logln(sdf.format(today));
    sdf.applyPattern("MM d yy");
    logln(sdf.format(today));

    sdf.applyPattern("MM d yyy");
    logln(sdf.format(today));

    sdf.applyPattern("MM d yyyy");
    logln(sdf.format(today));

    sdf.applyPattern("MM d yyyyy");
    logln(sdf.format(today));
}
 
Example #22
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4468663() {
    Date d =new Date(-93716671115767L);
    String origin_d = d.toString();
    String str;
    final String pattern = new String("EEEE, MMMM d, yyyy");
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);

    if (sdf.getTimeZone().useDaylightTime()) {
        logln("original date: " + origin_d.toString());
        str = sdf.format(d);
        logln(" after format----->" + str);
        
        d = sdf.parse(str, new ParsePosition(0));
        logln(" after parse----->" + d.toString());

        str = sdf.format(d);
        logln(" after format----->" + str);

        d = sdf.parse(str, new ParsePosition(0));
        logln(" after parse----->" + d.toString());

        str = sdf.format(d);
        logln(" after format----->" + str);        
    }
}
 
Example #23
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @bug 4101483
 */
@Test
public void Test4101483() {
    SimpleDateFormat sdf = new SimpleDateFormat("z", Locale.US);
    FieldPosition fp = new FieldPosition(DateFormat.TIMEZONE_FIELD);
    Date d = new Date(9234567890L);
    StringBuffer buf = new StringBuffer("");
    sdf.format(d, buf, fp);
    logln(sdf.format(d, buf, fp).toString());
    logln("beginIndex = " + fp.getBeginIndex());
    logln("endIndex = " + fp.getEndIndex());
    if (fp.getBeginIndex() == fp.getEndIndex())
        errln("Fail: Empty field");
}
 
Example #24
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @bug 4104136
 */
@Test
public void Test4104136() {
    SimpleDateFormat sdf = new SimpleDateFormat();
    String pattern = "'time' hh:mm";
    sdf.applyPattern(pattern);
    logln("pattern: \"" + pattern + "\"");
    String strings[] = {"time 10:30", "time 10:x", "time 10x"};
    ParsePosition ppos[] = {new ParsePosition(10), new ParsePosition(0), new ParsePosition(0)};
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1970, Calendar.JANUARY, 1, 10, 30);
    Date dates[] = {cal.getTime(), new Date(-1), new Date(-1)};
    for (int i = 0; i < 3; i++) {
        String text = strings[i];
        ParsePosition finish = ppos[i];
        Date exp = dates[i];
        ParsePosition pos = new ParsePosition(0);
        Date d = sdf.parse(text, pos);
        logln(" text: \"" + text + "\"");
        logln(" index: %d" + pos.getIndex());
        logln(" result: " + d);
        if (pos.getIndex() != finish.getIndex())
            errln("Fail: Expected pos " + finish.getIndex());
        if (!((d == null && exp.equals(new Date(-1))) || (d.equals(exp))))
            errln( "Fail: Expected result " + exp);
    }
}
 
Example #25
Source File: DateFormatRoundTripTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestDateFormatRoundTrip() {
    dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
    getFieldCal = Calendar.getInstance();
    ran = createRandom(); // use test framework's random seed

    final Locale[] avail = DateFormat.getAvailableLocales();
    int locCount = avail.length;
    logln("DateFormat available locales: " + locCount);
    if (quick) {
        if (locCount > 5)
            locCount = 5;
        logln("Quick mode: only testing first 5 Locales");
    }
    TimeZone tz = TimeZone.getDefault();
    logln("Default TimeZone:             " + tz.getID());

    if (INFINITE) {
        // Special infinite loop test mode for finding hard to reproduce errors
        Locale loc = Locale.getDefault();
        logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName());
        for (;;) {
            _test(loc);
        }
    } else {
        _test(Locale.getDefault());
        for (int i = 0; i < locCount; ++i) {
            _test(avail[i]);
        }
    }
}
 
Example #26
Source File: IntlTestDateFormat.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void describeTest() {
    if (fFormat == null) {
        errln("FAIL: no DateFormat");
        return;
    }

    // Assume it's a SimpleDateFormat and get some info
    SimpleDateFormat s = (SimpleDateFormat) fFormat;
    logln(fTestName + " Pattern " + s.toPattern());
}
 
Example #27
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void run() {            
    SimpleDateFormat sdf = (SimpleDateFormat) sdf_.clone();
    TimeZone tz = TimeZone.getTimeZone("PST");
    sdf.setTimeZone(tz);
    int i = 0;
    while (i < 10000) {
        i++;
        String s = sdf.format(new Date(UTC_LONG));
        if (!s.equals(TIME_STRING)) {
            errln("Format Error: " + i + " " + s + " != " 
                            + TIME_STRING);
        }
    }
}
 
Example #28
Source File: ULocaleTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestDateFormat() {
    checkService("de_CH_ZURICH", new ServiceFacade() {
        @Override
        public Object create(ULocale req) {
            return DateFormat.getDateInstance(DateFormat.DEFAULT, req);
        }
    }, new Subobject() {
        @Override
        public Object get(Object parent) {
            return ((SimpleDateFormat) parent).getDateFormatSymbols();
        }
    }, null);
}
 
Example #29
Source File: TestCLDRVsICU.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void handleResult(ULocale locale, String result) throws ParseException {
    for (Iterator it = settings.keySet().iterator(); it.hasNext();) {
        String attributeName = (String) it.next();
        String attributeValue = (String) settings.get(attributeName);
        if (attributeName.equals("date")) {
            date = attributeValue;
        } else if (attributeName.equals("field")) {
            pattern = attributeValue;
        } else if (attributeName.equals("zone")) {
            zone = attributeValue;
        } else if (attributeName.equals("parse")) {
            parse = attributeValue;
        }
    }
    
    if (!ZONE_MATCH.reset(zone).matches()) return;
    Date dateValue = iso.parse(date);
    SimpleDateFormat field = new SimpleDateFormat(pattern, locale);
    field.setTimeZone(TimeZone.getTimeZone(zone));
    String temp = field.format(dateValue).trim();
    // SKIP PARSE FOR NOW
    result = result.trim(); // HACK because of SAX
    if (!temp.equals(result)) {
        temp = field.format(dateValue).trim(); // call again for debugging
        logln("Zone Format: Locale: " + locale 
                + "\n\tZone: " + zone
                + "\n\tDate: " + date
                + "\n\tField: " + pattern
                + "\n\tParse: " + parse
                + "\n\tDraft: " + settings.get("draft")
                + "\n\tCLDR: <" + result
                + ">\n\tICU: <" + temp + ">");
    }
}
 
Example #30
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestT10110() {
    try {
        SimpleDateFormat formatter = new SimpleDateFormat("Gy年M月d日E", new Locale("zh_Hans"));
        /* Object parsed = */ formatter.parseObject("610000");
    }
    catch(ParseException pe) {
        return;
    }
    catch(Throwable t) {
        errln("ParseException not thrown for bad pattern! exception was: " + t.getLocalizedMessage());
        return;
    }
    errln("No exception thrown at all for bad pattern!");
}