use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestTicket9919Setter.
@Test
public void TestTicket9919Setter() {
// Creating a DateIntervalFormat with a custom DateIntervalInfo
// object used to corrupt the cache.
DateIntervalFormat dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);
Calendar from = Calendar.getInstance();
Calendar to = Calendar.getInstance();
from.set(2013, 3, 26);
to.set(2013, 3, 28);
// Save. This is the correct answer
String expected = dif.format(from, to, new StringBuffer(), new FieldPosition(0)).toString();
// Now create a DateIntervalFormat with same skeleton and
// locale, but with a custom DateIntervalInfo. This used
// to corrupt the cache.
DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(ULocale.ENGLISH);
dateIntervalInfo.setIntervalPattern("yMd", Calendar.DATE, "M/d/y \u2013 d");
DateIntervalFormat bad = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);
bad.setDateIntervalInfo(dateIntervalInfo);
// Now create a DateIntervalFormat with same skeleton and
// locale, but with default DateIntervalInfo. The cache should
// not be corrupted, and we should get the same answer as before.
dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);
assertEquals("Custom DateIntervalInfo objects should not mess up cache", expected, dif.format(from, to, new StringBuffer(), new FieldPosition(0)).toString());
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method expectUserDII.
private void expectUserDII(String[] data, int data_length) {
int i = 1;
while (i < data_length) {
String locName = data[i++];
ULocale loc = new ULocale(locName);
SimpleDateFormat ref = new SimpleDateFormat(data[0], loc);
// 'f'
String datestr = data[i++];
String datestr_2 = data[i++];
Date date, date_2;
try {
date = ref.parse(datestr);
date_2 = ref.parse(datestr_2);
} catch (ParseException e) {
errln("parse exception" + e);
continue;
}
DateInterval dtitv = new DateInterval(date.getTime(), date_2.getTime());
DateIntervalInfo dtitvinf = new DateIntervalInfo();
dtitvinf.setFallbackIntervalPattern("{0} --- {1}");
dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy MMM d - MMM y");
dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMM d HH:mm - HH:mm");
DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(DateFormat.YEAR_ABBR_MONTH_DAY, loc, dtitvinf);
String expected = data[i++];
String formatted = dtitvfmt.format(dtitv);
if (!formatted.equals(Utility.unescape(expected))) {
errln("userDII: \"" + locName + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected + "\tgot: " + formatted + "\n");
}
}
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestConstructor.
@Test
public void TestConstructor() {
DateIntervalInfo diiJapan = new DateIntervalInfo(ULocale.JAPAN);
DateIntervalInfo diiJapanJ = new DateIntervalInfo(Locale.JAPAN);
assertEquals("DateIntervalInfo constructors", diiJapan, diiJapanJ);
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestTicket9914.
@Test
public void TestTicket9914() {
DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(ULocale.ENGLISH);
Calendar from = Calendar.getInstance();
Calendar to = Calendar.getInstance();
from.set(113, 3, 26);
to.set(113, 3, 28);
DateIntervalFormat dif = DateIntervalFormat.getInstance("yyyyMd", ULocale.ENGLISH, dateIntervalInfo);
assertEquals("yyyyMd skeleton.", "4/26/0113 \u2013 4/28/0113", dif.format(from, to, new StringBuffer(), new FieldPosition(0)).toString());
dif = DateIntervalFormat.getInstance("yyMd", ULocale.ENGLISH, dateIntervalInfo);
assertEquals("yyMd skeleton.", "4/26/13 \u2013 4/28/13", dif.format(from, to, new StringBuffer(), new FieldPosition(0)).toString());
dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH, dateIntervalInfo);
assertEquals("yMd skeleton.", "4/26/113 \u2013 4/28/113", dif.format(from, to, new StringBuffer(), new FieldPosition(0)).toString());
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method expectUserCLDR.
private void expectUserCLDR(String[] data, int data_length) {
int i = 1;
while (i < data_length) {
String locName = data[i++];
ULocale loc = new ULocale(locName);
SimpleDateFormat ref = new SimpleDateFormat(data[0], loc);
// 'f'
String datestr = data[i++];
String datestr_2 = data[i++];
Date date, date_2;
try {
date = ref.parse(datestr);
date_2 = ref.parse(datestr_2);
} catch (ParseException e) {
errln("parse exception" + e);
continue;
}
DateInterval dtitv = new DateInterval(date.getTime(), date_2.getTime());
DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("yyyyMMMdd", loc);
// DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("yMd");
// SimpleDateFormat dtfmt = new SimpleDateFormat("yyyy 'year' MMM 'month' dd 'day'", loc);
// dtitvfmt.setDateFormat(dtfmt);
DateIntervalInfo dtitvinf = new DateIntervalInfo();
dtitvinf.setFallbackIntervalPattern("{0} --- {1}");
dtitvinf.setIntervalPattern("yMMMd", Calendar.YEAR, "'all diff'");
dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy 'diff' MMM d - MMM y");
dtitvinf.setIntervalPattern("yMMMd", Calendar.DATE, "yyyy MMM d ~ d");
dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMMd HH:mm ~ HH:mm");
dtitvfmt.setDateIntervalInfo(dtitvinf);
FieldPosition pos = new FieldPosition(0);
StringBuffer str = new StringBuffer("");
DateFormat dtfmt = dtitvfmt.getDateFormat();
Calendar fromCalendar = (Calendar) dtfmt.getCalendar().clone();
Calendar toCalendar = (Calendar) dtfmt.getCalendar().clone();
fromCalendar.setTimeInMillis(dtitv.getFromDate());
toCalendar.setTimeInMillis(dtitv.getToDate());
dtitvfmt.format(fromCalendar, toCalendar, str, pos);
String expected = data[i++];
String formatted = dtitvfmt.format(dtitv).toString();
if (!formatted.equals(Utility.unescape(expected))) {
errln("CLDR: \"" + locName + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected + "\tgot: " + formatted + "\n");
}
}
}
Aggregations