use of java.text.DateFormatSymbols in project robovm by robovm.
the class OldSimpleDateFormatTest method test_ConstructorLjava_lang_StringLjava_util_Locale.
public void test_ConstructorLjava_lang_StringLjava_util_Locale() {
// Test for method java.text.SimpleDateFormat(java.lang.String,
// java.util.Locale)
SimpleDateFormat f2 = new SimpleDateFormat("'yyyy' MM yy", Locale.GERMAN);
assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class);
assertEquals("Wrong pattern", "'yyyy' MM yy", f2.toPattern());
assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals(new DateFormatSymbols(Locale.GERMAN)));
assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class);
try {
new SimpleDateFormat(null, Locale.GERMAN);
fail("NullPointerException was not thrown.");
} catch (NullPointerException npe) {
//expected
}
try {
new SimpleDateFormat("eee", Locale.GERMAN);
fail("IllegalArgumentException was not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.text.DateFormatSymbols in project robovm by robovm.
the class OldSimpleDateFormatTest method test_hashCode.
public void test_hashCode() {
SimpleDateFormat format = (SimpleDateFormat) DateFormat.getInstance();
SimpleDateFormat clone = (SimpleDateFormat) format.clone();
assertTrue("clone has not equal hash code", clone.hashCode() == format.hashCode());
format.format(new Date());
assertTrue("clone has not equal hash code after format", clone.hashCode() == format.hashCode());
DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
symbols.setEras(new String[] { "Before", "After" });
SimpleDateFormat format2 = new SimpleDateFormat("y'y'yy", symbols);
assertFalse("objects has equal hash code", format2.hashCode() == format.hashCode());
}
use of java.text.DateFormatSymbols in project openhab1-addons by openhab.
the class ZWaveClockCommandClass method handleApplicationCommandRequest.
/**
* {@inheritDoc}
*
* @throws ZWaveSerialMessageException
*/
@Override
public void handleApplicationCommandRequest(SerialMessage serialMessage, int offset, int endpoint) {
logger.debug("NODE {}: Received CLOCK command V{}", getNode().getNodeId(), getVersion());
int command = serialMessage.getMessagePayloadByte(offset);
switch(command) {
case CLOCK_REPORT:
int day = serialMessage.getMessagePayloadByte(offset + 1) >> 5;
int hour = serialMessage.getMessagePayloadByte(offset + 1) & 0x1f;
int minute = serialMessage.getMessagePayloadByte(offset + 2);
String[] days = new DateFormatSymbols().getWeekdays();
int javaDay = day == 7 ? 1 : day + 1;
logger.debug(String.format("NODE %d: Received clock report: %s %02d:%02d", getNode().getNodeId(), days[javaDay], hour, minute));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, javaDay);
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
Date nodeTime = cal.getTime();
ZWaveCommandClassValueEvent zEvent = new ZWaveCommandClassValueEvent(getNode().getNodeId(), endpoint, getCommandClass(), nodeTime);
getController().notifyEventListeners(zEvent);
break;
default:
logger.warn(String.format("NODE %d: Unsupported Command %d for command class %s (0x%02X).", getNode().getNodeId(), command, getCommandClass().getLabel(), getCommandClass().getKey()));
break;
}
}
use of java.text.DateFormatSymbols in project robovm by robovm.
the class OldAndroidLocaleTest method testResourceBundles.
public void testResourceBundles() throws Exception {
Locale eng = new Locale("en", "US");
DateFormatSymbols engSymbols = new DateFormatSymbols(eng);
Locale deu = new Locale("de", "DE");
DateFormatSymbols deuSymbols = new DateFormatSymbols(deu);
TimeZone berlin = TimeZone.getTimeZone("Europe/Berlin");
assertEquals("January", engSymbols.getMonths()[0]);
assertEquals("Januar", deuSymbols.getMonths()[0]);
assertEquals("Sunday", engSymbols.getWeekdays()[Calendar.SUNDAY]);
assertEquals("Sonntag", deuSymbols.getWeekdays()[Calendar.SUNDAY]);
assertEquals("Central European Standard Time", berlin.getDisplayName(false, TimeZone.LONG, eng));
assertEquals("Central European Summer Time", berlin.getDisplayName(true, TimeZone.LONG, eng));
assertEquals("Mitteleuropäische Normalzeit", berlin.getDisplayName(false, TimeZone.LONG, deu));
assertEquals("Mitteleuropäische Sommerzeit", berlin.getDisplayName(true, TimeZone.LONG, deu));
assertTrue(engSymbols.getZoneStrings().length > 100);
}
use of java.text.DateFormatSymbols in project jdk8u_jdk by JetBrains.
the class Calendar method getDisplayNamesImpl.
private Map<String, Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
String[] strings = getFieldStrings(field, style, symbols);
if (strings != null) {
Map<String, Integer> names = new HashMap<>();
for (int i = 0; i < strings.length; i++) {
if (strings[i].length() == 0) {
continue;
}
names.put(strings[i], i);
}
return names;
}
return null;
}
Aggregations