Java Code Examples for android.icu.util.Calendar#SUNDAY
The following examples show how to use
android.icu.util.Calendar#SUNDAY .
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: RelativeDateTimeFormatter.java From j2objc with Apache License 2.0 | 6 votes |
/** * Formats a relative date without a quantity. * @param direction NEXT, LAST, THIS, etc. * @param unit e.g SATURDAY, DAY, MONTH * @return the formatted string. If direction has a value that is documented as not being * fully supported in every locale (for example NEXT_2 or LAST_2) then this function may * return null to signal that no formatted string is available. * @throws IllegalArgumentException if the direction is incompatible with * unit this can occur with NOW which can only take PLAIN. */ public String format(Direction direction, AbsoluteUnit unit) { if (unit == AbsoluteUnit.NOW && direction != Direction.PLAIN) { throw new IllegalArgumentException("NOW can only accept direction PLAIN."); } String result; // Get plain day of week names from DateFormatSymbols. if ((direction == Direction.PLAIN) && (AbsoluteUnit.SUNDAY.ordinal() <= unit.ordinal() && unit.ordinal() <= AbsoluteUnit.SATURDAY.ordinal())) { // Convert from AbsoluteUnit days to Calendar class indexing. int dateSymbolsDayOrdinal = (unit.ordinal() - AbsoluteUnit.SUNDAY.ordinal()) + Calendar.SUNDAY; String[] dayNames = dateFormatSymbols.getWeekdays(DateFormatSymbols.STANDALONE, styleToDateFormatSymbolsWidth[style.ordinal()]); result = dayNames[dateSymbolsDayOrdinal]; } else { // Not PLAIN, or not a weekday. result = getAbsoluteUnitString(style, unit, direction); } return result != null ? adjustForContext(result) : null; }
Example 2
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * Get the associated date starting from a specified date NOTE: the * unnecessary "getTime()'s" below are a work-around for a bug in jdk 1.1.3 * (and probably earlier versions also) * <p> * * @param d * The date to start from */ public static Date getAssociatedDate(Date d) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(d); //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH // cal.getTime(); // <--- REMOVE THIS TO SEE BUG while (true) { int wd = cal.get(Calendar.DAY_OF_WEEK); if (wd == Calendar.SATURDAY || wd == Calendar.SUNDAY) { cal.add(Calendar.DATE, 1); // cal.getTime(); } else break; } return cal.getTime(); }
Example 3
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 6 votes |
void dowTest(boolean lenient) { GregorianCalendar cal = new GregorianCalendar(); cal.set(1997, Calendar.AUGUST, 12); // Wednesday // cal.getTime(); // Force update cal.setLenient(lenient); cal.set(1996, Calendar.DECEMBER, 1); // Set the date to be December 1, // 1996 int dow = cal.get(Calendar.DAY_OF_WEEK); int min = cal.getMinimum(Calendar.DAY_OF_WEEK); int max = cal.getMaximum(Calendar.DAY_OF_WEEK); logln(cal.getTime().toString()); if (min != Calendar.SUNDAY || max != Calendar.SATURDAY) errln("FAIL: Min/max bad"); if (dow < min || dow > max) errln("FAIL: Day of week " + dow + " out of range"); if (dow != Calendar.SUNDAY) errln("FAIL: Day of week should be SUNDAY Got " + dow); }
Example 4
Source File: TimeZoneRuleTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestT8943() { String id = "Ekaterinburg Time"; String stdName = "Ekaterinburg Standard Time"; String dstName = "Ekaterinburg Daylight Time"; InitialTimeZoneRule initialRule = new InitialTimeZoneRule(stdName, 18000000, 0); RuleBasedTimeZone rbtz = new RuleBasedTimeZone(id, initialRule); DateTimeRule dtRule = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 10800000, DateTimeRule.WALL_TIME); AnnualTimeZoneRule atzRule = new AnnualTimeZoneRule(stdName, 18000000, 0, dtRule, 2000, 2010); rbtz.addTransitionRule(atzRule); dtRule = new DateTimeRule(Calendar.MARCH, -1, Calendar.SUNDAY, 7200000, DateTimeRule.WALL_TIME); atzRule = new AnnualTimeZoneRule(dstName, 18000000, 3600000, dtRule, 2000, 2010); rbtz.addTransitionRule(atzRule); dtRule = new DateTimeRule(Calendar.JANUARY, 1, 0, DateTimeRule.WALL_TIME); atzRule = new AnnualTimeZoneRule(stdName, 21600000, 0, dtRule, 2011, AnnualTimeZoneRule.MAX_YEAR); rbtz.addTransitionRule(atzRule); dtRule = new DateTimeRule(Calendar.JANUARY, 1, 1, DateTimeRule.WALL_TIME); atzRule = new AnnualTimeZoneRule(dstName, 21600000, 0, dtRule, 2011, AnnualTimeZoneRule.MAX_YEAR); rbtz.addTransitionRule(atzRule); int[] expected = {21600000, 0}; int[] offsets = new int[2]; try { rbtz.getOffset(1293822000000L /* 2010-12-31 19:00:00 UTC */, false, offsets); if (offsets[0] != expected[0] || offsets[1] != expected[1]) { errln("Fail: Wrong offsets: " + offsets[0] + "/" + offsets[1] + " Expected: " + expected[0] + "/" + expected[1]); } } catch (Exception e) { errln("Fail: Exception thrown - " + e.getMessage()); } }
Example 5
Source File: OlsonTimeZone.java From j2objc with Apache License 2.0 | 5 votes |
/** * TimeZone API. */ public int getOffset(int era, int year, int month,int dom, int dow, int millis, int monthLength){ if ((era != GregorianCalendar.AD && era != GregorianCalendar.BC) || month < Calendar.JANUARY || month > Calendar.DECEMBER || dom < 1 || dom > monthLength || dow < Calendar.SUNDAY || dow > Calendar.SATURDAY || millis < 0 || millis >= Grego.MILLIS_PER_DAY || monthLength < 28 || monthLength > 31) { throw new IllegalArgumentException(); } if (era == GregorianCalendar.BC) { year = -year; } if (finalZone != null && year >= finalStartYear) { return finalZone.getOffset(era, year, month, dom, dow, millis); } // Compute local epoch millis from input fields long time = Grego.fieldsToDay(year, month, dom) * Grego.MILLIS_PER_DAY + millis; int[] offsets = new int[2]; getHistoricalOffset(time, true, LOCAL_DST, LOCAL_STD, offsets); return offsets[0] + offsets[1]; }
Example 6
Source File: CompatibilityTest.java From j2objc with Apache License 2.0 | 5 votes |
void dowTest(boolean lenient) { GregorianCalendar cal = new GregorianCalendar(); cal.set(1997, Calendar.AUGUST, 12); // Wednesday cal.getTime(); // Force update cal.setLenient(lenient); cal.set(1996, Calendar.DECEMBER, 1); // Set the date to be December 1, 1996 int dow = cal.get(Calendar.DAY_OF_WEEK); int min = cal.getMinimum(Calendar.DAY_OF_WEEK); int max = cal.getMaximum(Calendar.DAY_OF_WEEK); if (dow < min || dow > max) errln("FAIL: Day of week " + dow + " out of range"); if (dow != Calendar.SUNDAY) { errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime()); } if (min != Calendar.SUNDAY || max != Calendar.SATURDAY) errln("FAIL: Min/max bad"); }
Example 7
Source File: IBMCalendarTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestWeekData() { // Each line contains two locales using the same set of week rule data. final String LOCALE_PAIRS[] = { "en", "en_US", "de", "de_DE", "de_DE", "en_DE", "en_GB", "und_GB", "ar_EG", "en_EG", "ar_SA", "fr_SA", }; for (int i = 0; i < LOCALE_PAIRS.length; i += 2) { Calendar cal1 = Calendar.getInstance(new ULocale(LOCALE_PAIRS[i])); Calendar cal2 = Calendar.getInstance(new ULocale(LOCALE_PAIRS[i + 1])); // First day of week int dow1 = cal1.getFirstDayOfWeek(); int dow2 = cal2.getFirstDayOfWeek(); if (dow1 != dow2) { errln("getFirstDayOfWeek: " + LOCALE_PAIRS[i] + "->" + dow1 + ", " + LOCALE_PAIRS[i + 1] + "->" + dow2); } // Minimum days in first week int minDays1 = cal1.getMinimalDaysInFirstWeek(); int minDays2 = cal2.getMinimalDaysInFirstWeek(); if (minDays1 != minDays2) { errln("getMinimalDaysInFirstWeek: " + LOCALE_PAIRS[i] + "->" + minDays1 + ", " + LOCALE_PAIRS[i + 1] + "->" + minDays2); } // Weekdays and Weekends for (int d = Calendar.SUNDAY; d <= Calendar.SATURDAY; d++) { int wdt1 = cal1.getDayOfWeekType(d); int wdt2 = cal2.getDayOfWeekType(d); if (wdt1 != wdt2) { errln("getDayOfWeekType(" + d + "): " + LOCALE_PAIRS[i] + "->" + wdt1 + ", " + LOCALE_PAIRS[i + 1] + "->" + wdt2); } } } }
Example 8
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void Test4070502() { java.util.Calendar tempcal = java.util.Calendar.getInstance(); tempcal.clear(); tempcal.set(1998, 0, 30); Date d = getAssociatedDate(tempcal.getTime()); Calendar cal = new GregorianCalendar(); cal.setTime(d); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) errln("Fail: Want weekday Got " + d); }
Example 9
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * GregorianCalendar.getActualMaximum() does not account for first day of * week. */ @Test public void Test4166109() { /* * Test month: * * March 1998 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 * 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 */ boolean passed = true; int field = Calendar.WEEK_OF_MONTH; GregorianCalendar calendar = new GregorianCalendar(Locale.US); calendar.set(1998, Calendar.MARCH, 1); calendar.setMinimalDaysInFirstWeek(1); logln("Date: " + calendar.getTime()); int firstInMonth = calendar.get(Calendar.DAY_OF_MONTH); for (int firstInWeek = Calendar.SUNDAY; firstInWeek <= Calendar.SATURDAY; firstInWeek++) { calendar.setFirstDayOfWeek(firstInWeek); int returned = calendar.getActualMaximum(field); int expected = (31 + ((firstInMonth - firstInWeek + 7)% 7) + 6) / 7; logln("First day of week = " + firstInWeek + " getActualMaximum(WEEK_OF_MONTH) = " + returned + " expected = " + expected + ((returned == expected) ? " ok" : " FAIL")); if (returned != expected) { passed = false; } } if (!passed) { errln("Test failed"); } }
Example 10
Source File: TimeZoneRuleTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestT6669() { // getNext/PreviousTransition implementation in SimpleTimeZone // used to use a bad condition for detecting if DST is enabled or not. SimpleTimeZone stz = new SimpleTimeZone(0, "CustomID", Calendar.JANUARY, 1, Calendar.SUNDAY, 0, Calendar.JULY, 1, Calendar.SUNDAY, 0); long t = 1230681600000L; //2008-12-31T00:00:00 long expectedNext = 1231027200000L; //2009-01-04T00:00:00 long expectedPrev = 1215298800000L; //2008-07-06T00:00:00 TimeZoneTransition tzt = stz.getNextTransition(t, false); if (tzt == null) { errln("FAIL: No transition returned by getNextTransition."); } else if (tzt.getTime() != expectedNext){ errln("FAIL: Wrong transition time returned by getNextTransition - " + tzt.getTime() + " Expected: " + expectedNext); } tzt = stz.getPreviousTransition(t, true); if (tzt == null) { errln("FAIL: No transition returned by getPreviousTransition."); } else if (tzt.getTime() != expectedPrev){ errln("FAIL: Wrong transition time returned by getPreviousTransition - " + tzt.getTime() + " Expected: " + expectedPrev); } }
Example 11
Source File: TimeZoneBoundaryTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Test new rule formats. */ @Test public void TestNewRules() { //logln(Locale.getDefault().getDisplayName()); //logln(TimeZone.getDefault().getID()); //logln(new Date(0)); if (true) { // Doesn't matter what the default TimeZone is here, since we // are creating our own TimeZone objects. SimpleTimeZone tz; java.util.Calendar tempcal = java.util.Calendar.getInstance(); tempcal.clear(); logln("-----------------------------------------------------------------"); logln("Aug 2ndTues .. Mar 15"); tz = new SimpleTimeZone(-8*ONE_HOUR, "Test_1", Calendar.AUGUST, 2, Calendar.TUESDAY, 2*ONE_HOUR, Calendar.MARCH, 15, 0, 2*ONE_HOUR); //logln(tz.toString()); logln("========================================"); tempcal.set(1997, 0, 1); _testUsingBinarySearch(tz, tempcal.getTime(), 858416400000L); logln("========================================"); tempcal.set(1997, 6, 1); _testUsingBinarySearch(tz, tempcal.getTime(), 871380000000L); logln("-----------------------------------------------------------------"); logln("Apr Wed>=14 .. Sep Sun<=20"); tz = new SimpleTimeZone(-8*ONE_HOUR, "Test_2", Calendar.APRIL, 14, -Calendar.WEDNESDAY, 2*ONE_HOUR, Calendar.SEPTEMBER, -20, -Calendar.SUNDAY, 2*ONE_HOUR); //logln(tz.toString()); logln("========================================"); tempcal.set(1997, 0, 1); _testUsingBinarySearch(tz, tempcal.getTime(), 861184800000L); logln("========================================"); tempcal.set(1997, 6, 1); _testUsingBinarySearch(tz, tempcal.getTime(), 874227600000L); } /* if (true) { logln("========================================"); logln("Stepping using millis"); _testUsingMillis(new Date(97,0,1), false); } if (true) { logln("========================================"); logln("Stepping using fields"); _testUsingFields(1997, false); } if (false) { cal.clear(); cal.set(1997, 3, 5, 10, 0); // cal.inDaylightTime(); logln("Date = " + cal.getTime()); logln("Millis = " + cal.getTime().getTime()/3600000); } */ }
Example 12
Source File: TimeZoneRegressionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * SimpleTimeZone.getOffset accepts illegal arguments. */ @Test public void Test4154650() { final int GOOD=1, BAD=0; final int GOOD_ERA=GregorianCalendar.AD, GOOD_YEAR=1998, GOOD_MONTH=Calendar.AUGUST; final int GOOD_DAY=2, GOOD_DOW=Calendar.SUNDAY, GOOD_TIME=16*3600000; int[] DATA = { GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GregorianCalendar.BC, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GregorianCalendar.AD, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GregorianCalendar.BC-1, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GregorianCalendar.AD+1, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.DECEMBER, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY-1, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.DECEMBER+1, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 1, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 31, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 0, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 32, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SUNDAY, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SUNDAY-1, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY+1, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 0, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 24*3600000-1, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, -1, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 24*3600000, }; TimeZone tz = TimeZone.getDefault(); for (int i=0; i<DATA.length; i+=7) { boolean good = DATA[i] == GOOD; IllegalArgumentException e = null; try { /*int offset =*/ tz.getOffset(DATA[i+1], DATA[i+2], DATA[i+3], DATA[i+4], DATA[i+5], DATA[i+6]); //offset = 0; } catch (IllegalArgumentException ex) { e = ex; } if (good != (e == null)) { errln("Fail: getOffset(" + DATA[i+1] + ", " + DATA[i+2] + ", " + DATA[i+3] + ", " + DATA[i+4] + ", " + DATA[i+5] + ", " + DATA[i+6] + (good ? (") threw " + e) : ") accepts invalid args")); } } }
Example 13
Source File: TimeZoneRegressionTest.java From j2objc with Apache License 2.0 | 4 votes |
boolean checkCalendar314(GregorianCalendar testCal, TimeZone testTZ) { // GregorianCalendar testCal = (GregorianCalendar)aCal.clone(); final int ONE_DAY = 24*60*60*1000; int tzOffset, tzRawOffset; Float tzOffsetFloat,tzRawOffsetFloat; // Here is where the user made an error. They were passing in the value of // the MILLSECOND field; you need to pass in the millis in the day in STANDARD // time. int millis = testCal.get(Calendar.MILLISECOND) + 1000 * (testCal.get(Calendar.SECOND) + 60 * (testCal.get(Calendar.MINUTE) + 60 * (testCal.get(Calendar.HOUR_OF_DAY)))) - testCal.get(Calendar.DST_OFFSET); /* Fix up millis to be in range. ASSUME THAT WE ARE NOT AT THE * BEGINNING OR END OF A MONTH. We must add this code because * getOffset() has been changed to be more strict about the parameters * it receives -- it turns out that this test was passing in illegal * values. */ int date = testCal.get(Calendar.DATE); int dow = testCal.get(Calendar.DAY_OF_WEEK); while (millis < 0) { millis += ONE_DAY; --date; dow = Calendar.SUNDAY + ((dow - Calendar.SUNDAY + 6) % 7); } while (millis >= ONE_DAY) { millis -= ONE_DAY; ++date; dow = Calendar.SUNDAY + ((dow - Calendar.SUNDAY + 1) % 7); } tzOffset = testTZ.getOffset(testCal.get(Calendar.ERA), testCal.get(Calendar.YEAR), testCal.get(Calendar.MONTH), date, dow, millis); tzRawOffset = testTZ.getRawOffset(); tzOffsetFloat = new Float((float)tzOffset/(float)3600000); tzRawOffsetFloat = new Float((float)tzRawOffset/(float)3600000); Date testDate = testCal.getTime(); boolean inDaylightTime = testTZ.inDaylightTime(testDate); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm"); sdf.setCalendar(testCal); String inDaylightTimeString; boolean passed; if (inDaylightTime) { inDaylightTimeString = " DST "; passed = (tzOffset == (tzRawOffset + 3600000)); } else { inDaylightTimeString = " "; passed = (tzOffset == tzRawOffset); } String output = testTZ.getID() + " " + sdf.format(testDate) + " Offset(" + tzOffsetFloat + ")" + " RawOffset(" + tzRawOffsetFloat + ")" + " " + millis/(float)3600000 + " " + inDaylightTimeString; if (passed) output += " "; else output += "ERROR"; if (passed) logln(output); else errln(output); return passed; }
Example 14
Source File: TimeZoneTest.java From j2objc with Apache License 2.0 | 4 votes |
@Test public void TestObservesDaylightTime() { boolean observesDaylight; long current = System.currentTimeMillis(); // J2ObjC change: time zones going through adjustments are problematic when comparing // the ICU tz data vs. the operating system tz data. Set<String> unstableTzids = new HashSet<>(); // https://github.com/eggert/tz/blob/379f7ba9b81eee97f0209a322540b4a522122b5d/africa#L847 unstableTzids.add("Africa/Casablanca"); unstableTzids.add("Africa/El_Aaiun"); String[] tzids = TimeZone.getAvailableIDs(); for (String tzid : tzids) { // OlsonTimeZone TimeZone tz = TimeZone.getTimeZone(tzid, TimeZone.TIMEZONE_ICU); observesDaylight = tz.observesDaylightTime(); if (observesDaylight != isDaylightTimeAvailable(tz, current)) { errln("Fail: [OlsonTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + tzid); } // RuleBasedTimeZone RuleBasedTimeZone rbtz = createRBTZ((BasicTimeZone)tz, current); boolean observesDaylightRBTZ = rbtz.observesDaylightTime(); if (observesDaylightRBTZ != isDaylightTimeAvailable(rbtz, current)) { errln("Fail: [RuleBasedTimeZone] observesDaylightTime() returned " + observesDaylightRBTZ + " for " + rbtz.getID()); } else if (observesDaylight != observesDaylightRBTZ) { errln("Fail: RuleBasedTimeZone " + rbtz.getID() + " returns " + observesDaylightRBTZ + ", but different from match OlsonTimeZone"); } // JavaTimeZone tz = TimeZone.getTimeZone(tzid, TimeZone.TIMEZONE_JDK); observesDaylight = tz.observesDaylightTime(); if (!unstableTzids.contains(tzid) && observesDaylight != isDaylightTimeAvailable(tz, current)) { errln("Fail: [JavaTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + tzid); } // VTimeZone tz = VTimeZone.getTimeZone(tzid); observesDaylight = tz.observesDaylightTime(); if (observesDaylight != isDaylightTimeAvailable(tz, current)) { errln("Fail: [VTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + tzid); } } // SimpleTimeZone SimpleTimeZone[] stzs = { new SimpleTimeZone(0, "STZ0"), new SimpleTimeZone(-5*60*60*1000, "STZ-5D", Calendar.MARCH, 2, Calendar.SUNDAY, 2*60*60*1000, Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2*60*60*1000), }; for (SimpleTimeZone stz : stzs) { observesDaylight = stz.observesDaylightTime(); if (observesDaylight != isDaylightTimeAvailable(stz, current)) { errln("Fail: [SimpleTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + stz.getID()); } } }
Example 15
Source File: TimeZoneTest.java From j2objc with Apache License 2.0 | 4 votes |
@Test public void TestFebruary() { // Time zone with daylight savings time from the first Sunday in November // to the last Sunday in February. // Similar to the new rule for Brazil (Sao Paulo) in tzdata2006n. // // Note: In tzdata2007h, the rule had changed, so no actual zones uses // lastSun in Feb anymore. SimpleTimeZone tz1 = new SimpleTimeZone( -3 * MILLIS_PER_HOUR, // raw offset: 3h before (west of) GMT "nov-feb", Calendar.NOVEMBER, 1, Calendar.SUNDAY, // start: November, first, Sunday 0, // midnight wall time Calendar.FEBRUARY, -1, Calendar.SUNDAY, // end: February, last, Sunday 0); // midnight wall time // Now hardcode the same rules as for Brazil in tzdata 2006n, so that // we cover the intended code even when in the future zoneinfo hardcodes // these transition dates. SimpleTimeZone tz2= new SimpleTimeZone( -3 * MILLIS_PER_HOUR, // raw offset: 3h before (west of) GMT "nov-feb2", Calendar.NOVEMBER, 1, -Calendar.SUNDAY, // start: November, 1 or after, Sunday 0, // midnight wall time Calendar.FEBRUARY, -29, -Calendar.SUNDAY,// end: February, 29 or before, Sunday 0); // midnight wall time // Gregorian calendar with the UTC time zone for getting sample test date/times. GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("Etc/GMT")); // "Unable to create the UTC calendar: %s" int[] data = { // UTC time (6 fields) followed by // expected time zone offset in hours after GMT (negative=before GMT). // int year, month, day, hour, minute, second, offsetHours 2006, Calendar.NOVEMBER, 5, 02, 59, 59, -3, 2006, Calendar.NOVEMBER, 5, 03, 00, 00, -2, 2007, Calendar.FEBRUARY, 25, 01, 59, 59, -2, 2007, Calendar.FEBRUARY, 25, 02, 00, 00, -3, 2007, Calendar.NOVEMBER, 4, 02, 59, 59, -3, 2007, Calendar.NOVEMBER, 4, 03, 00, 00, -2, 2008, Calendar.FEBRUARY, 24, 01, 59, 59, -2, 2008, Calendar.FEBRUARY, 24, 02, 00, 00, -3, 2008, Calendar.NOVEMBER, 2, 02, 59, 59, -3, 2008, Calendar.NOVEMBER, 2, 03, 00, 00, -2, 2009, Calendar.FEBRUARY, 22, 01, 59, 59, -2, 2009, Calendar.FEBRUARY, 22, 02, 00, 00, -3, 2009, Calendar.NOVEMBER, 1, 02, 59, 59, -3, 2009, Calendar.NOVEMBER, 1, 03, 00, 00, -2, 2010, Calendar.FEBRUARY, 28, 01, 59, 59, -2, 2010, Calendar.FEBRUARY, 28, 02, 00, 00, -3 }; TimeZone timezones[] = { tz1, tz2 }; TimeZone tz; Date dt; int t, i, raw, dst; int[] offsets = new int[2]; // raw = offsets[0], dst = offsets[1] for (t = 0; t < timezones.length; ++t) { tz = timezones[t]; for (i = 0; i < data.length; i+=7) { gc.set(data[i], data[i+1], data[i+2], data[i+3], data[i+4], data[i+5]); dt = gc.getTime(); tz.getOffset(dt.getTime(), false, offsets); raw = offsets[0]; dst = offsets[1]; if ((raw + dst) != data[i+6] * MILLIS_PER_HOUR) { errln("test case " + t + "." + (i/7) + ": " + "tz.getOffset(" + data[i] + "-" + (data[i+1] + 1) + "-" + data[i+2] + " " + data[i+3] + ":" + data[i+4] + ":" + data[i+5] + ") returns " + raw + "+" + dst + " != " + data[i+6] * MILLIS_PER_HOUR); } } } }
Example 16
Source File: SimpleMonthView.java From DateTimePicker with Apache License 2.0 | 4 votes |
private static boolean isValidDayOfWeek(int day) { return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY; }
Example 17
Source File: SimpleMonthView.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static boolean isValidDayOfWeek(int day) { return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY; }
Example 18
Source File: DatePicker.java From DateTimePicker with Apache License 2.0 | 3 votes |
/** * Sets the first day of week. * * @param firstDayOfWeek The first day of the week conforming to the * {@link CalendarView} APIs. * @attr ref android.R.styleable#DatePicker_firstDayOfWeek * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY */ public void setFirstDayOfWeek(int firstDayOfWeek) { if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) { throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7"); } mDelegate.setFirstDayOfWeek(firstDayOfWeek); }
Example 19
Source File: DatePicker.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Sets the first day of week. * * @param firstDayOfWeek The first day of the week conforming to the * {@link CalendarView} APIs. * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * * @attr ref android.R.styleable#DatePicker_firstDayOfWeek */ public void setFirstDayOfWeek(int firstDayOfWeek) { if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) { throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7"); } mDelegate.setFirstDayOfWeek(firstDayOfWeek); }