android.icu.util.Calendar Java Examples
The following examples show how to use
android.icu.util.Calendar.
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: CompatibilityTest.java From j2objc with Apache License 2.0 | 6 votes |
void verify765(String msg, Calendar c, int year, int month, int day) { int cy = c.get(Calendar.YEAR); // NEWCAL int cm = c.get(Calendar.MONTH); int cd = c.get(Calendar.DATE); if (cy == year && cm == month && cd == day) { logln("PASS: " + msg + c.getTime()); } else { errln("FAIL: " + msg + cy + "/" + (cm+1) + "/" + cd + "=" + c.getTime() + "; expected " + year + "/" + (month+1) + "/" + day); } }
Example #2
Source File: DatePickerCalendarDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void setMinDate(long minDate) { mTempDate.setTimeInMillis(minDate); if (mTempDate.get(Calendar.YEAR) == mMinDate.get(Calendar.YEAR) && mTempDate.get(Calendar.DAY_OF_YEAR) == mMinDate.get(Calendar.DAY_OF_YEAR)) { // Same day, no-op. return; } if (mCurrentDate.before(mTempDate)) { mCurrentDate.setTimeInMillis(minDate); onDateChanged(false, true); } mMinDate.setTimeInMillis(minDate); mDayPickerView.setMinDate(minDate); mYearPickerView.setRange(mMinDate, mMaxDate); }
Example #3
Source File: DatePickerCalendarDelegate.java From DateTimePicker with Apache License 2.0 | 6 votes |
@Override public void onYearChanged(YearPickerView view, int year) { // If the newly selected month / year does not contain the // currently selected day number, change the selected day number // to the last day of the selected month or year. // e.g. Switching from Mar to Apr when Mar 31 is selected -> Apr 30 // e.g. Switching from 2012 to 2013 when Feb 29, 2012 is selected -> Feb 28, 2013 final int day = mCurrentDate.get(Calendar.DAY_OF_MONTH); final int month = mCurrentDate.get(Calendar.MONTH); final int daysInMonth = getDaysInMonth(month, year); if (day > daysInMonth) { mCurrentDate.set(Calendar.DAY_OF_MONTH, daysInMonth); } mCurrentDate.set(Calendar.YEAR, year); onDateChanged(true, true); // Automatically switch to day picker. setCurrentView(VIEW_MONTH_DAY); // Switch focus back to the year text. mHeaderYear.requestFocus(); }
Example #4
Source File: SimpleMonthView.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final Resources res = context.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize( R.dimen.date_picker_day_selector_radius); // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); setAccessibilityDelegate(mTouchHelper); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); mLocale = res.getConfiguration().locale; mCalendar = Calendar.getInstance(mLocale); mDayFormatter = NumberFormat.getIntegerInstance(mLocale); updateMonthYearLabel(); updateDayOfWeekLabels(); initPaints(res); }
Example #5
Source File: SimpleDateFormat.java From j2objc with Apache License 2.0 | 6 votes |
/** * Formats a date or time, which is the standard millis * since January 1, 1970, 00:00:00 GMT. * <p>Example: using the US locale: * "yyyy.MM.dd G 'at' HH:mm:ss zzz" ->> 1996.07.10 AD at 15:08:56 PDT * @param cal the calendar whose date-time value is to be formatted into a date-time string * @param toAppendTo where the new date-time text is to be appended * @param pos the formatting position. On input: an alignment field, * if desired. On output: the offsets of the alignment field. * @return the formatted date-time string. * @see DateFormat */ @Override public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition pos) { TimeZone backupTZ = null; if (cal != calendar && !cal.getType().equals(calendar.getType())) { // Different calendar type // We use the time and time zone from the input calendar, but // do not use the input calendar for field calculation. calendar.setTimeInMillis(cal.getTimeInMillis()); backupTZ = calendar.getTimeZone(); calendar.setTimeZone(cal.getTimeZone()); cal = calendar; } StringBuffer result = format(cal, getContext(DisplayContext.Type.CAPITALIZATION), toAppendTo, pos, null); if (backupTZ != null) { // Restore the original time zone calendar.setTimeZone(backupTZ); } return result; }
Example #6
Source File: CompatibilityTest.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void TestGregorianChange768() { boolean b; GregorianCalendar c = new GregorianCalendar(); logln("With cutoff " + c.getGregorianChange()); logln(" isLeapYear(1800) = " + (b=c.isLeapYear(1800))); logln(" (should be FALSE)"); if (b != false) errln("FAIL"); java.util.Calendar tempcal = java.util.Calendar.getInstance(); tempcal.clear(); tempcal.set(1900, 0, 1); c.setGregorianChange(tempcal.getTime()); // Jan 1 1900 logln("With cutoff " + c.getGregorianChange()); logln(" isLeapYear(1800) = " + (b=c.isLeapYear(1800))); logln(" (should be TRUE)"); if (b != true) errln("FAIL"); }
Example #7
Source File: ChineseTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * Test minimum and maximum functions. */ @Test public void TestLimits() { // The number of days and the start date can be adjusted // arbitrarily to either speed up the test or make it more // thorough, but try to test at least a full year, preferably a // full non-leap and a full leap year. // Final parameter is either number of days, if > 0, or test // duration in seconds, if < 0. java.util.Calendar tempcal = java.util.Calendar.getInstance(); tempcal.clear(); tempcal.set(1989, Calendar.NOVEMBER, 1); ChineseCalendar chinese = new ChineseCalendar(); doLimitsTest(chinese, null, tempcal.getTime()); doTheoreticalLimitsTest(chinese, true); }
Example #8
Source File: TestCase.java From j2objc with Apache License 2.0 | 6 votes |
/** * Initialize a TestCase object using a julian day number and * the corresponding fields for the calendar being tested. * * @param era The ERA field of tested calendar on the given julian day * @param year The YEAR field of tested calendar on the given julian day * @param month The MONTH (1-based) field of tested calendar on the given julian day * @param day The DAY_OF_MONTH field of tested calendar on the given julian day * @param dayOfWeek The DAY_OF_WEEK field of tested calendar on the given julian day * @param hour The HOUR field of tested calendar on the given julian day * @param min The MINUTE field of tested calendar on the given julian day * @param sec The SECOND field of tested calendar on the given julian day */ public TestCase(double julian, int era, int year, int month, int day, int dayOfWeek, int hour, int min, int sec) { setTime(new Date(JULIAN_EPOCH + (long)(ONE_DAY * julian))); set(Calendar.ERA, era); set(Calendar.YEAR, year); set(Calendar.MONTH, month - 1); set(Calendar.DATE, day); set(Calendar.DAY_OF_WEEK, dayOfWeek); set(Calendar.HOUR, hour); set(Calendar.MINUTE, min); set(Calendar.SECOND, sec); }
Example #9
Source File: ChineseDateFormat.java From j2objc with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * @deprecated This API is ICU internal only. * @hide draft / provisional / internal are hidden on Android */ @Override @Deprecated protected void subFormat(StringBuffer buf, char ch, int count, int beginOffset, int fieldNum, DisplayContext capitalizationContext, FieldPosition pos, Calendar cal) { // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat, // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we // just use its implementation super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal); // The following is no longer an issue for this subclass... // TODO: add code to set FieldPosition for 'G' and 'l' fields. This // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the // code that handles this at the end of SimpleDateFormat.subFormat. // The logic should be moved up into SimpleDateFormat.format. }
Example #10
Source File: CompatibilityTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestActualMinMax() { Calendar cal = new GregorianCalendar(1967, Calendar.MARCH, 10); cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.setMinimalDaysInFirstWeek(3); if (cal.getActualMinimum(Calendar.DAY_OF_MONTH) != 1) errln("Actual minimum date for 3/10/1967 should have been 1; got " + cal.getActualMinimum(Calendar.DAY_OF_MONTH)); if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) != 31) errln("Actual maximum date for 3/10/1967 should have been 31; got " + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.MONTH, Calendar.FEBRUARY); if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) != 28) errln("Actual maximum date for 2/10/1967 should have been 28; got " + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); if (cal.getActualMaximum(Calendar.DAY_OF_YEAR) != 365) errln("Number of days in 1967 should have been 365; got " + cal.getActualMaximum(Calendar.DAY_OF_YEAR)); cal.set(Calendar.YEAR, 1968); if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) != 29) errln("Actual maximum date for 2/10/1968 should have been 29; got " + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); if (cal.getActualMaximum(Calendar.DAY_OF_YEAR) != 366) errln("Number of days in 1968 should have been 366; got " + cal.getActualMaximum(Calendar.DAY_OF_YEAR)); // Using week settings of SUNDAY/3 (see above) if (cal.getActualMaximum(Calendar.WEEK_OF_YEAR) != 52) errln("Number of weeks in 1968 should have been 52; got " + cal.getActualMaximum(Calendar.WEEK_OF_YEAR)); cal.set(Calendar.YEAR, 1976); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); // Added - Liu 11/6/00 // Using week settings of SUNDAY/3 (see above) if (cal.getActualMaximum(Calendar.WEEK_OF_YEAR) != 53) errln("Number of weeks in 1976 should have been 53; got " + cal.getActualMaximum(Calendar.WEEK_OF_YEAR)); }
Example #11
Source File: SimpleDateFormat.java From j2objc with Apache License 2.0 | 5 votes |
private static synchronized String getDefaultPattern() { ULocale defaultLocale = ULocale.getDefault(Category.FORMAT); if (!defaultLocale.equals(cachedDefaultLocale)) { cachedDefaultLocale = defaultLocale; Calendar cal = Calendar.getInstance(cachedDefaultLocale); try { // Load the calendar data directly. ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance( ICUData.ICU_BASE_NAME, cachedDefaultLocale); String resourcePath = "calendar/" + cal.getType() + "/DateTimePatterns"; ICUResourceBundle patternsRb= rb.findWithFallback(resourcePath); if (patternsRb == null) { patternsRb = rb.findWithFallback("calendar/gregorian/DateTimePatterns"); } if (patternsRb == null || patternsRb.getSize() < 9) { cachedDefaultPattern = FALLBACKPATTERN; } else { int defaultIndex = 8; if (patternsRb.getSize() >= 13) { defaultIndex += (SHORT + 1); } String basePattern = patternsRb.getString(defaultIndex); cachedDefaultPattern = SimpleFormatterImpl.formatRawPattern( basePattern, 2, 2, patternsRb.getString(SHORT), patternsRb.getString(SHORT + 4)); } } catch (MissingResourceException e) { cachedDefaultPattern = FALLBACKPATTERN; } } return cachedDefaultPattern; }
Example #12
Source File: CompatibilityTest.java From j2objc with Apache License 2.0 | 5 votes |
private void auxMapping(Calendar cal, int y, int m, int d) { cal.clear(); cal.set(y, m, d); long millis = cal.getTime().getTime(); cal.setTime(new Date(millis)); int year2 = cal.get(Calendar.YEAR); int month2 = cal.get(Calendar.MONTH); int dom2 = cal.get(Calendar.DAY_OF_MONTH); if (y != year2 || m != month2 || dom2 != d) errln("Round-trip failure: " + y + "-" + (m+1) + "-"+d+" =>ms=> " + year2 + "-" + (month2+1) + "-" + dom2); }
Example #13
Source File: TimePicker.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public final AutofillValue getAutofillValue() { if (mAutofilledValue != 0) { return AutofillValue.forDate(mAutofilledValue); } final Calendar cal = Calendar.getInstance(mLocale); cal.set(Calendar.HOUR_OF_DAY, getHour()); cal.set(Calendar.MINUTE, getMinute()); return AutofillValue.forDate(cal.getTimeInMillis()); }
Example #14
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void Test4040996() { try { String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); calendar.set(Calendar.MONTH,3); calendar.set(Calendar.DAY_OF_MONTH,18); calendar.set(Calendar.SECOND, 30); logln("MONTH: " + calendar.get(Calendar.MONTH)); logln("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); logln("MINUTE: " + calendar.get(Calendar.MINUTE)); logln("SECOND: " + calendar.get(Calendar.SECOND)); calendar.add(Calendar.SECOND,6); //This will print out todays date for MONTH and DAY_OF_MONTH //instead of the date it was set to. //This happens when adding MILLISECOND or MINUTE also logln("MONTH: " + calendar.get(Calendar.MONTH)); logln("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); logln("MINUTE: " + calendar.get(Calendar.MINUTE)); logln("SECOND: " + calendar.get(Calendar.SECOND)); if (calendar.get(Calendar.MONTH) != 3 || calendar.get(Calendar.DAY_OF_MONTH) != 18 || calendar.get(Calendar.SECOND) != 36) errln("Fail: Calendar.add misbehaves"); } catch (Exception e) { warnln("Could not load data. "+ e.getMessage()); } }
Example #15
Source File: IntlTestDateFormatAPI.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestEquals() { // Create two objects at different system times DateFormat a = DateFormat.getInstance(); Date start = Calendar.getInstance().getTime(); while (true) { // changed to remove compiler warnings. if (!start.equals(Calendar.getInstance().getTime())) { break; // Wait for time to change } } DateFormat b = DateFormat.getInstance(); if (!(a.equals(b))) errln("FAIL: DateFormat objects created at different times are unequal."); // Why has this test been disabled??? - aliu // if (b instanceof SimpleDateFormat) // { // //double ONE_YEAR = 365*24*60*60*1000.0; //The variable is never used // try { // ((SimpleDateFormat)b).setTwoDigitStartDate(start.getTime() + 50*ONE_YEAR); // if (a.equals(b)) // errln("FAIL: DateFormat objects with different two digit start dates are equal."); // } // catch (Exception e) { // errln("FAIL: setTwoDigitStartDate failed."); // } // } }
Example #16
Source File: CalendarViewLegacyDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @return Returns the number of weeks between the current <code>date</code> * and the <code>mMinDate</code>. */ private int getWeeksSinceMinDate(Calendar date) { if (date.before(mMinDate)) { throw new IllegalArgumentException("fromDate: " + mMinDate.getTime() + " does not precede toDate: " + date.getTime()); } long endTimeMillis = date.getTimeInMillis() + date.getTimeZone().getOffset(date.getTimeInMillis()); long startTimeMillis = mMinDate.getTimeInMillis() + mMinDate.getTimeZone().getOffset(mMinDate.getTimeInMillis()); long dayOffsetMillis = (mMinDate.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek) * MILLIS_IN_DAY; return (int) ((endTimeMillis - startTimeMillis + dayOffsetMillis) / MILLIS_IN_WEEK); }
Example #17
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestT5555() throws Exception { Calendar cal = Calendar.getInstance(); // Set date to Wednesday, February 21, 2007 cal.set(2007, Calendar.FEBRUARY, 21); try { // Advance month by three years cal.add(Calendar.MONTH, 36); // Move to last Wednesday of month. cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1); cal.getTime(); } catch (Exception e) { errln("Got an exception calling getTime()."); } int yy, mm, dd, ee; yy = cal.get(Calendar.YEAR); mm = cal.get(Calendar.MONTH); dd = cal.get(Calendar.DATE); ee = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH); if (yy != 2010 || mm != Calendar.FEBRUARY || dd != 24 || ee != Calendar.WEDNESDAY) { errln("Got date " + yy + "/" + (mm + 1) + "/" + dd + ", expected 2010/2/24"); } }
Example #18
Source File: DateIntervalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestSetIntervalPatternNoSideEffect() { PatternInfo patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE); String expectedPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart(); new DateIntervalInfo(ULocale.ENGLISH).setIntervalPattern( "yMd", Calendar.DATE, "M/d/y \u2013 d"); patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE); String actualPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart(); assertEquals( "setIntervalPattern should not have side effects", expectedPattern, actualPattern); }
Example #19
Source File: IBMCalendarTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * Verify that TaiwanCalendar shifts years to Minguo Era but otherwise * behaves like GregorianCalendar. */ @Test public void TestTaiwan() { quasiGregorianTest(new TaiwanCalendar(), new int[] { TaiwanCalendar.BEFORE_MINGUO, 8, 1904, Calendar.FEBRUARY, 29, TaiwanCalendar.MINGUO, 1, 1912, Calendar.JUNE, 4, TaiwanCalendar.MINGUO, 3, 1914, Calendar.FEBRUARY, 12, TaiwanCalendar.MINGUO, 96,2007, Calendar.FEBRUARY, 12, }); }
Example #20
Source File: DateIntervalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
private void expectUserDII(String[] data, int data_length) { int i = 1; while (i<data_length) { String locName = data[i++]; ULocale loc = new ULocale(locName); SimpleDateFormat ref = new SimpleDateFormat(data[0], loc); // 'f' String datestr = data[i++]; String datestr_2 = data[i++]; Date date, date_2; try { date = ref.parse(datestr); date_2 = ref.parse(datestr_2); } catch ( ParseException e ) { errln("parse exception" + e); continue; } DateInterval dtitv = new DateInterval(date.getTime(), date_2.getTime()); DateIntervalInfo dtitvinf = new DateIntervalInfo(); dtitvinf.setFallbackIntervalPattern("{0} --- {1}"); dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy MMM d - MMM y"); dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMM d HH:mm - HH:mm"); DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance( DateFormat.YEAR_ABBR_MONTH_DAY, loc, dtitvinf); String expected = data[i++]; String formatted = dtitvfmt.format(dtitv); if ( !formatted.equals(Utility.unescape(expected)) ) { errln("userDII: \"" + locName + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected +"\tgot: " + formatted + "\n"); } } }
Example #21
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * This is a bug in the validation code of GregorianCalendar. As reported, * the bug seems worse than it really is, due to a bug in the way the bug * report test was written. In reality the bug is restricted to the * DAY_OF_YEAR field. - liu 6/29/98 */ @Test public void Test4147269() { GregorianCalendar calendar = new GregorianCalendar(); calendar.setLenient(false); java.util.Calendar tempcal = java.util.Calendar.getInstance(); tempcal.clear(); tempcal.set(1996, Calendar.JANUARY, 3); // Arbitrary date Date date = tempcal.getTime(); for (int field = 0; field < calendar.getFieldCount(); field++) { calendar.setTime(date); // Note: In the bug report, getActualMaximum() was called instead // of getMaximum() -- this was an error. The validation code doesn't // use getActualMaximum(), since that's too costly. int max = calendar.getMaximum(field); int value = max+1; calendar.set(field, value); try { calendar.getTime(); // Force time computation // We expect an exception to be thrown. If we fall through // to the next line, then we have a bug. errln("Test failed with field " + FIELD_NAME[field] + ", date before: " + date + ", date after: " + calendar.getTime() + ", value: " + value + " (max = " + max +")"); } catch (IllegalArgumentException e) { System.out.print(""); } } }
Example #22
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void Test4095407() { GregorianCalendar a = new GregorianCalendar(1997,Calendar.NOVEMBER, 13); int dow = a.get(Calendar.DAY_OF_WEEK); if (dow != Calendar.THURSDAY) errln("Fail: Want THURSDAY Got " + dow); }
Example #23
Source File: IBMCalendarTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * Verify that BuddhistCalendar shifts years to Buddhist Era but otherwise * behaves like GregorianCalendar. */ @Test public void TestBuddhist() { quasiGregorianTest(new BuddhistCalendar(), new int[] { // BE 2542 == 1999 CE 0, 2542, 1999, Calendar.JUNE, 4 }); }
Example #24
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void Test4059654() { // try { // work around bug for jdk1.4 on solaris 2.6, which uses funky // timezone names // jdk1.4.1 will drop support for 2.6 so we should be ok when it // comes out java.util.TimeZone javazone = java.util.TimeZone.getTimeZone("GMT"); TimeZone icuzone = TimeZone.getTimeZone("GMT"); GregorianCalendar gc = new GregorianCalendar(icuzone); gc.set(1997, 3, 1, 15, 16, 17); // April 1, 1997 gc.set(Calendar.HOUR, 0); gc.set(Calendar.AM_PM, Calendar.AM); gc.set(Calendar.MINUTE, 0); gc.set(Calendar.SECOND, 0); gc.set(Calendar.MILLISECOND, 0); Date cd = gc.getTime(); java.util.Calendar cal = java.util.Calendar.getInstance(javazone); cal.clear(); cal.set(1997, 3, 1, 0, 0, 0); Date exp = cal.getTime(); if (!cd.equals(exp)) errln("Fail: Calendar.set broken. Got " + cd + " Want " + exp); // } catch (RuntimeException e) { // TODO Auto-generated catch block // e.printStackTrace(); // } }
Example #25
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void Test4100311() { GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance(); cal.set(Calendar.YEAR, 1997); cal.set(Calendar.DAY_OF_YEAR, 1); Date d = cal.getTime(); // Should be Jan 1 logln(d.toString()); if (cal.get(Calendar.DAY_OF_YEAR) != 1) errln("Fail: DAY_OF_YEAR not set"); }
Example #26
Source File: IBMCalendarTest.java From j2objc with Apache License 2.0 | 5 votes |
boolean isEquivalentTo(Calendar cal) { return year == cal.get(Calendar.YEAR) && month == cal.get(Calendar.MONTH) + 1 && day == cal.get(Calendar.DAY_OF_MONTH) && hour == cal.get(Calendar.HOUR_OF_DAY) && min == cal.get(Calendar.MINUTE) && sec == cal.get(Calendar.SECOND) && ms == cal.get(Calendar.MILLISECOND); }
Example #27
Source File: DateIntervalFormat.java From j2objc with Apache License 2.0 | 5 votes |
private final StringBuffer fallbackFormat(Calendar fromCalendar, Calendar toCalendar, boolean fromToOnSameDay, StringBuffer appendTo, FieldPosition pos, String fullPattern) { String originalPattern = fDateFormat.toPattern(); fDateFormat.applyPattern(fullPattern); fallbackFormat(fromCalendar, toCalendar, fromToOnSameDay, appendTo, pos); fDateFormat.applyPattern(originalPattern); return appendTo; }
Example #28
Source File: DatePickerSpinnerDelegate.java From DateTimePicker with Apache License 2.0 | 5 votes |
/** * Parses the given <code>date</code> and in case of success sets the result * to the <code>outDate</code>. * * @return True if the date was parsed. */ private boolean parseDate(String date, Calendar outDate) { try { outDate.setTime(mDateFormat.parse(date)); return true; } catch (ParseException e) { e.printStackTrace(); return false; } }
Example #29
Source File: DayPickerPagerAdapter.java From DateTimePicker with Apache License 2.0 | 5 votes |
@Override public void onDayClick(SimpleMonthView view, Calendar day) { if (day != null) { setSelectedDay(day); if (mOnDaySelectedListener != null) { mOnDaySelectedListener.onDaySelected(DayPickerPagerAdapter.this, day); } } }
Example #30
Source File: DayPickerPagerAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private int getPositionForDay(@Nullable Calendar day) { if (day == null) { return -1; } final int yearOffset = day.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR); final int monthOffset = day.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH); final int position = yearOffset * MONTHS_IN_YEAR + monthOffset; return position; }