use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestSetIntervalPatternNoSideEffect.
@Test
public void TestSetIntervalPatternNoSideEffect() {
PatternInfo patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
String expectedPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
new DateIntervalInfo(ULocale.ENGLISH).setIntervalPattern("yMd", Calendar.DATE, "M/d/y \u2013 d");
patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
String actualPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
assertEquals("setIntervalPattern should not have side effects", expectedPattern, actualPattern);
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestDateIntervalFormatCoverage.
@Test
public void TestDateIntervalFormatCoverage() throws Exception {
long date1 = 1299090600000L;
long date2 = 1299115800000L;
DateInterval dtitv = new DateInterval(date1, date2);
DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("MMMd", Locale.ENGLISH);
DateIntervalInfo dtintinf = new DateIntervalInfo(ULocale.ENGLISH);
// Check the default private constructor
checkDefaultPrivateConstructor(DateIntervalFormat.class);
// Check clone
DateIntervalFormat dtitvfmtClone = (DateIntervalFormat) dtitvfmt.clone();
assertEquals("DateIntervalFormat.clone() failed", dtitvfmt.format(dtitv), dtitvfmtClone.format(dtitv));
// Coverage for getInstance
assertNotNull("Expected DateIntervalFormat object", DateIntervalFormat.getInstance("MMMd", dtintinf));
assertNotNull("Expected DateIntervalFormat object", DateIntervalFormat.getInstance("MMMdHHmm", Locale.ENGLISH, dtintinf));
// Coverage for parseObject. Exception expected.
try {
dtitvfmt.parseObject("", new ParsePosition(0));
errln("Exception was expected when calling DateIntervalFormat.parseObject()");
} catch (Exception e) {
/* No op */
}
// Check getPatterns()
Output<String> secondPart = new Output<String>();
Calendar fromCalendar = Calendar.getInstance(Locale.ENGLISH);
fromCalendar.set(2016, 5, 22);
Calendar toCalendar = Calendar.getInstance(Locale.ENGLISH);
toCalendar.set(2016, 5, 23);
assertEquals("Date interval pattern mismatch.", dtitvfmt.getPatterns(fromCalendar, toCalendar, secondPart), "MMM d – ");
assertEquals("Date interval pattern mismatch.", secondPart.value, "d");
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestClone.
/* Tests the method
* public boolean clone()
*/
@Test
public void TestClone() {
DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
DateIntervalInfo dii_clone = (DateIntervalInfo) dii.clone();
dii_clone.freeze();
// Tests when "if ( frozen )" is true
if (!dii.equals(dii_clone)) {
errln("DateIntervalInfo.clone() is suppose to return true for " + "an original DateIntervalInfo object and a clone of the " + "original DateIntervalInfo object.");
}
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method TestSetIntervalPattern.
/* Tests the method
* public void setIntervalPattern(String skeleton, int lrgDiffCalUnit, String intervalPattern)
*/
@Test
public void TestSetIntervalPattern() {
DateIntervalInfo dii = new DateIntervalInfo();
// Tests when "if ( frozen )" is true
try {
dii.freeze();
dii.setIntervalPattern("", 0, "");
errln("DateIntervalInfo.setIntervalPattern(String,int,String) " + "was suppose to return an exception when the " + "DateIntervalInfo object is frozen.");
} catch (Exception e) {
}
// MINIMUM_SUPPORTED_CALENDAR_FIELD = Calendar.SECOND;
try {
dii = (DateIntervalInfo) dii.cloneAsThawed();
dii.setIntervalPattern("", Calendar.SECOND + 1, "");
errln("DateIntervalInfo.setIntervalPattern(String,int,String) " + "was suppose to return an exception when the " + "variable 'lrgDiffCalUnit' is greater than " + "MINIMUM_SUPPORTED_CALENDAR_FIELD.");
} catch (Exception e) {
}
}
use of android.icu.text.DateIntervalInfo in project j2objc by google.
the class DateIntervalFormatTest method testGetInstance_String_DateIntervalInfo.
@Test
public void testGetInstance_String_DateIntervalInfo() {
DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(new ULocale("ca"));
DateIntervalFormat dateIntervalFormat = DateIntervalFormat.getInstance(DateFormat.YEAR_MONTH, Locale.ENGLISH, dateIntervalInfo);
Calendar from = Calendar.getInstance();
from.set(2000, Calendar.JANUARY, 1, 12, 0);
Calendar to = Calendar.getInstance();
to.set(2001, Calendar.FEBRUARY, 1, 12, 0);
DateInterval interval = new DateInterval(from.getTimeInMillis(), to.getTimeInMillis());
dateIntervalFormat.setTimeZone(from.getTimeZone());
// Month names are default (English), format is Catalan
assertEquals("Wrong date interval", "January de 2000 – February de 2001", dateIntervalFormat.format(interval));
}
Aggregations