use of java.text.DateFormatSymbols in project robovm by robovm.
the class OldSimpleDateFormatTest method test_setDateFormatSymbolsLjava_text_DateFormatSymbols.
public void test_setDateFormatSymbolsLjava_text_DateFormatSymbols() {
// Test for method void
// java.text.SimpleDateFormat.setDateFormatSymbols(java.text.DateFormatSymbols)
SimpleDateFormat f1 = new SimpleDateFormat("a");
DateFormatSymbols symbols = new DateFormatSymbols();
symbols.setAmPmStrings(new String[] { "morning", "night" });
f1.setDateFormatSymbols(symbols);
DateFormatSymbols newSym = f1.getDateFormatSymbols();
assertTrue("Set incorrectly", newSym.equals(symbols));
assertTrue("Not a clone", f1.getDateFormatSymbols() != symbols);
String result = f1.format(new GregorianCalendar(1999, Calendar.JUNE, 12, 3, 0).getTime());
assertEquals("Incorrect symbols used", "morning", result);
symbols.setEras(new String[] { "before", "after" });
assertTrue("Identical symbols", !f1.getDateFormatSymbols().equals(symbols));
try {
f1.setDateFormatSymbols(null);
fail("NullPointerException was not thrown.");
} catch (NullPointerException npe) {
//expected
}
}
use of java.text.DateFormatSymbols in project robovm by robovm.
the class OldSimpleDateFormatTest method test_ConstructorLjava_lang_StringLjava_text_DateFormatSymbols.
/**
* java.text.SimpleDateFormat#SimpleDateFormat(java.lang.String,
* java.text.DateFormatSymbols)
*/
public void test_ConstructorLjava_lang_StringLjava_text_DateFormatSymbols() {
// Test for method java.text.SimpleDateFormat(java.lang.String,
// java.text.DateFormatSymbols)
DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
symbols.setEras(new String[] { "Before", "After" });
SimpleDateFormat f2 = new SimpleDateFormat("y'y'yy", symbols);
assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class);
assertEquals("Wrong pattern", "y'y'yy", f2.toPattern());
assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals(symbols));
assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class);
try {
new SimpleDateFormat(null, symbols);
fail("NullPointerException was not thrown.");
} catch (NullPointerException npe) {
//expected
}
try {
new SimpleDateFormat("eee", symbols);
fail("IllegalArgumentException was not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.text.DateFormatSymbols in project robovm by robovm.
the class OldAndroidLocaleTest method testICULocales.
// This one makes sure we have all necessary locales installed.
public void testICULocales() {
String[] locales = new String[] { // List of locales currently required for Android.
"en_US", "es_US", "en_GB", "fr_FR", "de_DE", "de_AT", "cs_CZ", "nl_NL" };
String[] mondays = new String[] { "Monday", "lunes", "Monday", "lundi", "Montag", "Montag", "pondělí", "maandag" };
String[] currencies = new String[] { "USD", "USD", "GBP", "EUR", "EUR", "EUR", "CZK", "EUR" };
for (int i = 0; i < locales.length; i++) {
Locale l = new Locale(locales[i].substring(0, 2), locales[i].substring(3));
// Check language part of locale.
DateFormatSymbols d = new DateFormatSymbols(l);
assertEquals("Monday name for " + locales[i] + " must match", mondays[i], d.getWeekdays()[2]);
// Check country part of locale.
Currency c = Currency.getInstance(l);
assertEquals("Currency code for " + locales[i] + " must match", currencies[i], c.getCurrencyCode());
}
}
use of java.text.DateFormatSymbols in project XobotOS by xamarin.
the class Date method parse.
/**
* Returns the millisecond value of the date and time parsed from the
* specified {@code String}. Many date/time formats are recognized, including IETF
* standard syntax, i.e. Tue, 22 Jun 1999 12:16:00 GMT-0500
*
* @param string
* the String to parse.
* @return the millisecond value parsed from the String.
*
* @deprecated use {@link DateFormat}
*/
@Deprecated
public static long parse(String string) {
if (string == null) {
throw new IllegalArgumentException("The string argument is null");
}
char sign = 0;
int commentLevel = 0;
int offset = 0, length = string.length(), state = 0;
int year = -1, month = -1, date = -1;
int hour = -1, minute = -1, second = -1, zoneOffset = 0, minutesOffset = 0;
boolean zone = false;
final int PAD = 0, LETTERS = 1, NUMBERS = 2;
StringBuilder buffer = new StringBuilder();
while (offset <= length) {
char next = offset < length ? string.charAt(offset) : '\r';
offset++;
if (next == '(') {
commentLevel++;
}
if (commentLevel > 0) {
if (next == ')') {
commentLevel--;
}
if (commentLevel == 0) {
next = ' ';
} else {
continue;
}
}
int nextState = PAD;
if ('a' <= next && next <= 'z' || 'A' <= next && next <= 'Z') {
nextState = LETTERS;
} else if ('0' <= next && next <= '9') {
nextState = NUMBERS;
} else if (!Character.isSpace(next) && ",+-:/".indexOf(next) == -1) {
throw new IllegalArgumentException();
}
if (state == NUMBERS && nextState != NUMBERS) {
int digit = Integer.parseInt(buffer.toString());
buffer.setLength(0);
if (sign == '+' || sign == '-') {
if (zoneOffset == 0) {
zone = true;
if (next == ':') {
minutesOffset = sign == '-' ? -Integer.parseInt(string.substring(offset, offset + 2)) : Integer.parseInt(string.substring(offset, offset + 2));
offset += 2;
}
zoneOffset = sign == '-' ? -digit : digit;
sign = 0;
} else {
throw new IllegalArgumentException();
}
} else if (digit >= 70) {
if (year == -1 && (Character.isSpace(next) || next == ',' || next == '/' || next == '\r')) {
year = digit;
} else {
throw new IllegalArgumentException();
}
} else if (next == ':') {
if (hour == -1) {
hour = digit;
} else if (minute == -1) {
minute = digit;
} else {
throw new IllegalArgumentException();
}
} else if (next == '/') {
if (month == -1) {
month = digit - 1;
} else if (date == -1) {
date = digit;
} else {
throw new IllegalArgumentException();
}
} else if (Character.isSpace(next) || next == ',' || next == '-' || next == '\r') {
if (hour != -1 && minute == -1) {
minute = digit;
} else if (minute != -1 && second == -1) {
second = digit;
} else if (date == -1) {
date = digit;
} else if (year == -1) {
year = digit;
} else {
throw new IllegalArgumentException();
}
} else if (year == -1 && month != -1 && date != -1) {
year = digit;
} else {
throw new IllegalArgumentException();
}
} else if (state == LETTERS && nextState != LETTERS) {
String text = buffer.toString().toUpperCase(Locale.US);
buffer.setLength(0);
if (text.length() == 1) {
throw new IllegalArgumentException();
}
if (text.equals("AM")) {
if (hour == 12) {
hour = 0;
} else if (hour < 1 || hour > 12) {
throw new IllegalArgumentException();
}
} else if (text.equals("PM")) {
if (hour == 12) {
hour = 0;
} else if (hour < 1 || hour > 12) {
throw new IllegalArgumentException();
}
hour += 12;
} else {
DateFormatSymbols symbols = new DateFormatSymbols(Locale.US);
String[] weekdays = symbols.getWeekdays(), months = symbols.getMonths();
int value;
if (parse(text, weekdays) != -1) {
/* empty */
} else if (month == -1 && (month = parse(text, months)) != -1) {
/* empty */
} else if (text.equals("GMT") || text.equals("UT") || text.equals("UTC")) {
zone = true;
zoneOffset = 0;
} else if ((value = zone(text)) != 0) {
zone = true;
zoneOffset = value;
} else {
throw new IllegalArgumentException();
}
}
}
if (next == '+' || (year != -1 && next == '-')) {
sign = next;
} else if (!Character.isSpace(next) && next != ',' && nextState != NUMBERS) {
sign = 0;
}
if (nextState == LETTERS || nextState == NUMBERS) {
buffer.append(next);
}
state = nextState;
}
if (year != -1 && month != -1 && date != -1) {
if (hour == -1) {
hour = 0;
}
if (minute == -1) {
minute = 0;
}
if (second == -1) {
second = 0;
}
if (year < (creationYear - 80)) {
year += 2000;
} else if (year < 100) {
year += 1900;
}
minute -= minutesOffset;
if (zone) {
if (zoneOffset >= 24 || zoneOffset <= -24) {
hour -= zoneOffset / 100;
minute -= zoneOffset % 100;
} else {
hour -= zoneOffset;
}
return UTC(year - 1900, month, date, hour, minute, second);
}
return new Date(year - 1900, month, date, hour, minute, second).getTime();
}
throw new IllegalArgumentException();
}
use of java.text.DateFormatSymbols in project XobotOS by xamarin.
the class Calendar method getDisplayNameArray.
private String[] getDisplayNameArray(int field, int style, Locale locale) {
if (field < 0 || field >= FIELD_COUNT) {
throw new IllegalArgumentException("bad field " + field);
}
checkStyle(style);
DateFormatSymbols dfs = DateFormatSymbols.getInstance(locale);
switch(field) {
case AM_PM:
return dfs.getAmPmStrings();
case DAY_OF_WEEK:
return (style == LONG) ? dfs.getWeekdays() : dfs.getShortWeekdays();
case ERA:
return dfs.getEras();
case MONTH:
return (style == LONG) ? dfs.getMonths() : dfs.getShortMonths();
}
return null;
}
Aggregations