use of android.icu.text.DateFormat in project j2objc by google.
the class GlobalizationPreferences method guessDateFormat.
/**
* This function can be overridden by subclasses to use different heuristics.
* <b>It MUST return a 'safe' value,
* one whose modification will not affect this object.</b>
*
* @param dateStyle
* @param timeStyle
* @hide draft / provisional / internal are hidden on Android
*/
protected DateFormat guessDateFormat(int dateStyle, int timeStyle) {
DateFormat result;
ULocale dfLocale = getAvailableLocale(TYPE_DATEFORMAT);
if (dfLocale == null) {
dfLocale = ULocale.ROOT;
}
if (timeStyle == DF_NONE) {
result = DateFormat.getDateInstance(getCalendar(), dateStyle, dfLocale);
} else if (dateStyle == DF_NONE) {
result = DateFormat.getTimeInstance(getCalendar(), timeStyle, dfLocale);
} else {
result = DateFormat.getDateTimeInstance(getCalendar(), dateStyle, timeStyle, dfLocale);
}
return result;
}
use of android.icu.text.DateFormat in project j2objc by google.
the class NumberFormatRegressionTest method TestJ691.
/**
* DateFormat should call setIntegerParseOnly(TRUE) on adopted
* NumberFormat objects.
*/
@Test
public void TestJ691() {
Locale loc = new Locale("fr", "CH");
// set up the input date string & expected output
String udt = "11.10.2000";
String exp = "11.10.00";
// create a Calendar for this locale
Calendar cal = Calendar.getInstance(loc);
// create a NumberFormat for this locale
NumberFormat nf = NumberFormat.getInstance(loc);
// *** Here's the key: We don't want to have to do THIS:
// nf.setParseIntegerOnly(true);
// create the DateFormat
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, loc);
df.setCalendar(cal);
df.setNumberFormat(nf);
// set parsing to lenient & parse
Date ulocdat = new Date();
df.setLenient(true);
try {
ulocdat = df.parse(udt);
} catch (java.text.ParseException pe) {
errln(pe.getMessage());
}
// format back to a string
String outString = df.format(ulocdat);
if (!outString.equals(exp)) {
errln("FAIL: " + udt + " => " + outString);
}
}
use of android.icu.text.DateFormat in project j2objc by google.
the class LocaleAliasTest method TestDateFormat.
@Test
public void TestDateFormat() {
ULocale defLoc = ULocale.getDefault();
ULocale.setDefault(_DEFAULT_LOCALE);
for (int i = 0; i < _LOCALE_NUMBER; i++) {
ULocale oldLoc = _LOCALES[i][0];
ULocale newLoc = _LOCALES[i][1];
if (availableMap.get(_LOCALES[i][1]) == null) {
logln(_LOCALES[i][1] + " is not available. Skipping!");
continue;
}
DateFormat df1 = DateFormat.getDateInstance(DateFormat.FULL, oldLoc);
DateFormat df2 = DateFormat.getDateInstance(DateFormat.FULL, newLoc);
// Test function "getLocale"
ULocale l1 = df1.getLocale(ULocale.VALID_LOCALE);
ULocale l2 = df2.getLocale(ULocale.VALID_LOCALE);
if (!newLoc.equals(l1)) {
errln("DateFormatTest: newLoc!=l1: newLoc= " + newLoc + " l1= " + l1);
}
if (!l1.equals(l2)) {
errln("DateFormatTest: l1!=l2: l1= " + l1 + " l2= " + l2);
}
if (!df1.equals(df2)) {
errln("DateFormatTest: df1!=df2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
}
TestFmwk.logln("DateFormat(getLocale) old:" + l1 + " new:" + l2);
// Test function "format"
// Date d = new Date();
// String d1 = df1.format(d);
// String d2 = df2.format(d);
// if (!d1.equals(d2)) {
// pass = false;
// }
// this.logln("DateFormat(format) old:"+d1+" new:"+d2);
}
ULocale.setDefault(defLoc);
}
use of android.icu.text.DateFormat in project j2objc by google.
the class TestMessageFormat method TestDateFormatHashCode.
public void TestDateFormatHashCode() {
DateFormat testDF = DateFormat.getDateInstance(DateFormat.DEFAULT, ULocale.GERMAN);
NumberFormat testNF = testDF.getNumberFormat();
int expectedResult = testNF.getMaximumIntegerDigits() * 37 + testNF.getMaximumFractionDigits();
int actualHashResult = testDF.hashCode();
assertEquals("DateFormat hashCode", expectedResult, actualHashResult);
}
use of android.icu.text.DateFormat in project android_frameworks_base by DirtyUnicorns.
the class DateView method updateClock.
protected void updateClock() {
if (mDateFormat == null) {
final Locale l = Locale.getDefault();
DateFormat format = DateFormat.getInstanceForSkeleton(mDatePattern, l);
format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
mDateFormat = format;
}
mCurrentTime.setTime(System.currentTimeMillis());
final String text = mDateFormat.format(mCurrentTime);
if (!text.equals(mLastText)) {
setText(text);
mLastText = text;
}
}
Aggregations