Search in sources :

Example 11 with DateFormatSymbols

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
    }
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 12 with DateFormatSymbols

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());
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 13 with DateFormatSymbols

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;
    }
}
Also used : Calendar(java.util.Calendar) DateFormatSymbols(java.text.DateFormatSymbols) ZWaveCommandClassValueEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveCommandClassValueEvent) ZWaveEndpoint(org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint) Date(java.util.Date)

Example 14 with DateFormatSymbols

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);
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) DateFormatSymbols(java.text.DateFormatSymbols)

Example 15 with DateFormatSymbols

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DateFormatSymbols(java.text.DateFormatSymbols)

Aggregations

DateFormatSymbols (java.text.DateFormatSymbols)140 SimpleDateFormat (java.text.SimpleDateFormat)38 Date (java.util.Date)26 ArrayList (java.util.ArrayList)23 Locale (java.util.Locale)21 Resources (android.content.res.Resources)15 View (android.view.View)14 TextView (android.widget.TextView)12 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)9 List (java.util.List)8 OnClickListener (android.view.View.OnClickListener)7 Test (org.junit.Test)7 Typeface (android.graphics.Typeface)6 RelativeLayout (android.widget.RelativeLayout)6 LayoutParams (android.app.ActionBar.LayoutParams)5 IOException (java.io.IOException)5 TypedArray (android.content.res.TypedArray)4 AdapterView (android.widget.AdapterView)4 Button (android.widget.Button)4