Java Code Examples for android.icu.util.Calendar#WeekData

The following examples show how to use android.icu.util.Calendar#WeekData . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestWeekendData_10560() {
    final Calendar.WeekData worldWeekData = new Calendar.WeekData(2, 1, 7, 0, 1, 86400000);
    final Calendar.WeekData usWeekData = new Calendar.WeekData(1, 1, 7, 0, 1, 86400000);
    final Calendar.WeekData testWeekData = new Calendar.WeekData(1, 2, 3, 4, 5, 86400000);

    assertEquals("World", worldWeekData, Calendar.getWeekDataForRegion("001"));
    assertEquals("Illegal code => world", Calendar.getWeekDataForRegion("001"), Calendar.getWeekDataForRegion("xx"));
    assertEquals("FR = DE", Calendar.getWeekDataForRegion("FR"), Calendar.getWeekDataForRegion("DE"));
    assertNotEquals("IN ≠ world", Calendar.getWeekDataForRegion("001"), Calendar.getWeekDataForRegion("IN"));
    assertNotEquals("FR ≠ EG", Calendar.getWeekDataForRegion("FR"), Calendar.getWeekDataForRegion("EG"));  
    
    Calendar aCalendar = Calendar.getInstance(Locale.US);
    assertEquals("US", usWeekData, aCalendar.getWeekData());
    Calendar rgusCalendar = Calendar.getInstance(new ULocale("hi_IN@rg=USzzzz"));
    assertEquals("IN@rg=US", usWeekData, rgusCalendar.getWeekData());
    
    aCalendar.setWeekData(testWeekData);
    assertEquals("Custom", testWeekData, aCalendar.getWeekData());
}
 
Example 2
Source File: WeekFields.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an instance of {@code WeekFields} appropriate for a locale.
 * <p>
 * This will look up appropriate values from the provider of localization data.
 *
 * @param locale  the locale to use, not null
 * @return the week-definition, not null
 */
public static WeekFields of(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    // Android-changed: get Week data from ICU4J
    ULocale ulocale = ULocale.forLocale(locale);
    String region = ULocale.getRegionForSupplementalData(ulocale, /* inferRegion */ true);
    Calendar.WeekData weekData = Calendar.getWeekDataForRegion(region);
    DayOfWeek dow = DayOfWeek.SUNDAY.plus(weekData.firstDayOfWeek - 1);
    return WeekFields.of(dow, weekData.minimalDaysInFirstWeek);
}