/** * Creates a new <tt>CalendarDateSpinnerData</tt> bounded from * <tt>1900-01-01</tt> to <tt>2099-12-31</tt>. */ public CalendarDateSpinnerData() { this(new CalendarDate(1900, 0, 0), new CalendarDate(2099, 11, 30)); }
public boolean contains(CalendarDate calendarDate) { if (calendarDate == null) { throw new IllegalArgumentException("calendarDate is null."); } boolean contains; if (start.compareTo(end) < 0) { contains = (start.compareTo(calendarDate) <= 0 && end.compareTo(calendarDate) >= 0); } else { contains = (end.compareTo(calendarDate) <= 0 && start.compareTo(calendarDate) >= 0); } return contains; }
/** * Adds the specified number of days to this calendar date and returns the * resulting calendar date. The number of days may be negative, in which * case the result will be a date before this calendar date. * <p> * More formally, it is defined that given calendar dates <tt>c1</tt> and * <tt>c2</tt>, the following will return <tt>true</tt>: * <pre> * c1.add(c2.subtract(c1)).equals(c2); * </pre> * * @param days * The number of days to add to (or subtract from if negative) this * calendar date. * * @return * The resulting calendar date. */ public CalendarDate add(int days) { GregorianCalendar calendar = toCalendar(); calendar.add(Calendar.DAY_OF_YEAR, days); return new CalendarDate(calendar); }
/** * Gets the number of days in between this calendar date and the specified * calendar date. If this calendar date represents a day after the * specified calendar date, the difference will be positive. If this * calendar date represents a day before the specified calendar date, the * difference will be negative. If the two calendar dates represent the * same day, the difference will be zero. * <p> * More formally, it is defined that given calendar dates <tt>c1</tt> and * <tt>c2</tt>, the following will return <tt>true</tt>: * <pre> * c1.add(c2.subtract(c1)).equals(c2); * </pre> * * @param calendarDate * The calendar date to subtract from this calendar date. * * @return * The number of days in between this calendar date and * <tt>calendarDate</tt>. */ public int subtract(CalendarDate calendarDate) { GregorianCalendar c1 = toCalendar(); GregorianCalendar c2 = calendarDate.toCalendar(); long t1 = c1.getTimeInMillis(); long t2 = c2.getTimeInMillis(); return (int)((t1 - t2) / (1000l * 60 * 60 * 24)); }
public int getLength() { return Math.abs(this.start.subtract(this.end)) + 1; }
/** * Gets the number of days in between this calendar date and the specified * calendar date. If this calendar date represents a day after the * specified calendar date, the difference will be positive. If this * calendar date represents a day before the specified calendar date, the * difference will be negative. If the two calendar dates represent the * same day, the difference will be zero. * <p> * More formally, it is defined that given calendar dates <tt>c1</tt> and * <tt>c2</tt>, the following will return <tt>true</tt>: * <pre> * c1.add(c2.subtract(c1)).equals(c2); * </pre> * * @param calendarDate * The calendar date to subtract from this calendar date. * * @return * The number of days in between this calendar date and * <tt>calendarDate</tt>. */ public int subtract(CalendarDate calendarDate) { GregorianCalendar c1 = toCalendar(); GregorianCalendar c2 = calendarDate.toCalendar(); long t1 = c1.getTimeInMillis(); long t2 = c2.getTimeInMillis(); return (int)((t1 - t2) / (1000l * 60 * 60 * 24)); }
/** * Adds the specified number of days to this calendar date and returns the * resulting calendar date. The number of days may be negative, in which * case the result will be a date before this calendar date. * <p> * More formally, it is defined that given calendar dates <tt>c1</tt> and * <tt>c2</tt>, the following will return <tt>true</tt>: * <pre> * c1.add(c2.subtract(c1)).equals(c2); * </pre> * * @param days * The number of days to add to (or subtract from if negative) this * calendar date. * * @return * The resulting calendar date. */ public CalendarDate add(int days) { GregorianCalendar calendar = toCalendar(); calendar.add(Calendar.DAY_OF_YEAR, days); return new CalendarDate(calendar); }
public int getLength() { return Math.abs(start.subtract(end)) + 1; }
/** * Creates a new <tt>CalendarDateSpinnerData</tt> bounded from * <tt>1900-01-01</tt> to <tt>2099-12-31</tt>. */ public CalendarDateSpinnerData() { this(new CalendarDate(1900, 0, 0), new CalendarDate(2099, 11, 30)); }
public boolean contains(CalendarDate calendarDate) { if (calendarDate == null) { throw new IllegalArgumentException("calendarDate is null."); } boolean contains; if (this.start.compareTo(this.end) < 0) { contains = (this.start.compareTo(calendarDate) <= 0 && this.end.compareTo(calendarDate) >= 0); } else { contains = (this.end.compareTo(calendarDate) <= 0 && this.start.compareTo(calendarDate) >= 0); } return contains; }
/** * Translates this calendar date to an instance of * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and * <tt>dayOfMonth</tt> fields set in the default time zone with the default * locale. * * @return * This calendar date as a <tt>GregorianCalendar</tt>. */ public GregorianCalendar toCalendar() { return toCalendar(new Time(0, 0, 0)); }
/** * Sets the selected date to the date represented by the specified date * string. The date string must be in the <tt>ISO 8601</tt> "calendar date" * format, which is <tt>[YYYY]-[MM]-[DD]</tt>. * * @param selectedDate * A string in the form of <tt>[YYYY]-[MM]-[DD]</tt> (e.g. 2008-07-23) */ public final void setSelectedDate(String selectedDate) { if (selectedDate == null) { throw new IllegalArgumentException("selectedDate is null."); } setSelectedDate(CalendarDate.decode(selectedDate)); }
public CalendarButton() { this(new CalendarDate()); }
public boolean intersects(Range range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Range normalizedRange = range.normalize(); boolean intersects; if (this.start.compareTo(this.end) < 0) { intersects = (this.start.compareTo(normalizedRange.end) <= 0 && this.end.compareTo(normalizedRange.start) >= 0); } else { intersects = (this.end.compareTo(normalizedRange.end) <= 0 && this.start.compareTo(normalizedRange.start) >= 0); } return intersects; }
/** * Translates this calendar date to an instance of * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and * <tt>dayOfMonth</tt> fields set in the default time zone with the default * locale. * * @return * This calendar date as a <tt>GregorianCalendar</tt>. */ public GregorianCalendar toCalendar() { return toCalendar(new Time(0, 0, 0)); }
/** * Sets the selected date to the date represented by the specified date * string. The date string must be in the <tt>ISO 8601</tt> "calendar date" * format, which is <tt>[YYYY]-[MM]-[DD]</tt>. * * @param selectedDate * A string in the form of <tt>[YYYY]-[MM]-[DD]</tt> (e.g. 2008-07-23) */ public final void setSelectedDate(String selectedDate) { if (selectedDate == null) { throw new IllegalArgumentException("selectedDate is null."); } setSelectedDate(CalendarDate.decode(selectedDate)); }
public Calendar() { this(new CalendarDate()); }
public boolean intersects(Range range) { if (range == null) { throw new IllegalArgumentException("range is null."); } Range normalizedRange = range.normalize(); boolean intersects; if (start.compareTo(end) < 0) { intersects = (start.compareTo(normalizedRange.end) <= 0 && end.compareTo(normalizedRange.start) >= 0); } else { intersects = (end.compareTo(normalizedRange.end) <= 0 && start.compareTo(normalizedRange.start) >= 0); } return intersects; }