Java Code Examples for java.util.Calendar.equals()

The following are Jave code examples for showing how to use equals() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: MaterialCalendarView.java   View Source Code Vote up 7 votes
/**
 * Dispatch a range of days to a listener, if set. First day must be before last Day.
 *
 * @param firstDay first day enclosing a range
 * @param lastDay  last day enclosing a range
 */
protected void dispatchOnRangeSelected(final CalendarDay firstDay, final CalendarDay lastDay) {
    final OnRangeSelectedListener listener = rangeListener;
    final List<CalendarDay> days = new ArrayList<>();

    final Calendar counter = Calendar.getInstance();
    counter.setTime(firstDay.getDate());  //  start from the first day and increment

    final Calendar end = Calendar.getInstance();
    end.setTime(lastDay.getDate());  //  for comparison

    while (counter.before(end) || counter.equals(end)) {
        final CalendarDay current = CalendarDay.from(counter);
        adapter.setDateSelected(current, true);
        days.add(current);
        counter.add(Calendar.DATE, 1);
    }

    if (listener != null) {
        listener.onRangeSelected(MaterialCalendarView.this, days);
    }
}
 
Example 2
Project: calendarview2   File: CalendarView2.java   View Source Code Vote up 7 votes
/**
     * Dispatch a range of days to a listener, if set. First day must be before last Day.
     *
     * @param firstDay first day enclosing a range
     * @param lastDay  last day enclosing a range
     */
    protected void dispatchOnRangeSelected(final CalendarDay firstDay, final CalendarDay lastDay) {
        final OnRangeSelectedListener listener = rangeListener;
        final List<CalendarDay> days = new ArrayList<>();

        final Calendar counter = Calendar.getInstance();
        counter.setTime(firstDay.getDate());  //  start from the first day and increment

        final Calendar end = Calendar.getInstance();
        end.setTime(lastDay.getDate());  //  for comparison

        while (counter.before(end) || counter.equals(end)) {
            final CalendarDay current = CalendarDay.from(counter);
//            adapter.setDateSelected(current, true);
            days.add(current);
            counter.add(Calendar.DATE, 1);
        }

        Collections.sort(days, new CalendarDayComparator());
        adapter.setDateRangeSelected(days);

        if (listener != null) {
            listener.onRangeSelected(CalendarView2.this, days);
        }
    }
 
Example 3
Project: incubator-netbeans   File: SchedulingPickerImpl.java   View Source Code Vote up 6 votes
private static boolean isThisWeek (Calendar scheduleDay, Calendar until) {
    Calendar weekStart = Calendar.getInstance();
    stripTime(weekStart);
    weekStart.set(Calendar.DAY_OF_WEEK, weekStart.getFirstDayOfWeek());
    Calendar weekEnd = Calendar.getInstance();
    weekEnd.setTime(weekStart.getTime());
    weekEnd.add(Calendar.DATE, 7);
    
    return scheduleDay.equals(weekStart) && until.equals(weekEnd);
}
 
Example 4
Project: incubator-netbeans   File: SchedulingPickerImpl.java   View Source Code Vote up 6 votes
private static boolean isNextWeek (Calendar scheduleDay, Calendar until) {
    Calendar weekStart = Calendar.getInstance();
    stripTime(weekStart);
    weekStart.set(Calendar.DAY_OF_WEEK, weekStart.getFirstDayOfWeek());
    weekStart.add(Calendar.DATE, 7);
    Calendar weekEnd = Calendar.getInstance();
    weekEnd.setTime(weekStart.getTime());
    weekEnd.add(Calendar.DATE, 7);
    
    return scheduleDay.equals(weekStart) && until.equals(weekEnd);
}
 
Example 5
Project: NeverLag   File: DateUtils.java   View Source Code Vote up 6 votes
public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
	boolean future = false;
	if (toDate.equals(fromDate)) {
		return I18N.tr("now");
	}
	if (toDate.after(fromDate)) {
		future = true;
	}
	StringBuilder sb = new StringBuilder();
	int[] types = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND };
	String[] names = {
		I18N.tr("year"), I18N.tr("years"),
		I18N.tr("month"), I18N.tr("months"),
		I18N.tr("day"), I18N.tr("days"),
		I18N.tr("hour"), I18N.tr("hours"),
		I18N.tr("minute"), I18N.tr("minutes"),
		I18N.tr("second"), I18N.tr("seconds")
	};
	int accuracy = 0;
	for (int i = 0; i < types.length; i++) {
		if (accuracy > 2) {
			break;
		}
		int diff = dateDiff(types[i], fromDate, toDate, future);
		if (diff > 0) {
			accuracy++;
			sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
		}
	}
	if (sb.length() == 0) {
		return "now";
	}
	return sb.toString().trim();
}
 
Example 6
Project: OperatieBRP   File: AbstractDBUnitUtil.java   View Source Code Vote up 6 votes
@Override
protected boolean skipCompare(final String columnName, final Object expectedValue, final Object actualValue) {
    final boolean result;
    if (actualValue instanceof Timestamp && TODAY.equals(expectedValue)) {
        final Calendar actualCalendar = Calendar.getInstance();
        final Calendar expectedCalendar = (Calendar) actualCalendar.clone();
        actualCalendar.setTimeInMillis(((Timestamp) actualValue).getTime());
        clearTime(actualCalendar);
        clearTime(expectedCalendar);
        result = actualCalendar.equals(expectedCalendar);
    } else {
        result = false;
    }
    return result;
}
 
Example 7
Project: Cognizant-Intelligent-Test-Scripter   File: Tools.java   View Source Code Vote up 6 votes
public static Date getScheduledTime() {

        Calendar startTime = Calendar.getInstance();
        Calendar now = Calendar.getInstance();
        startTime.set(Calendar.HOUR_OF_DAY, 0);
        startTime.set(Calendar.MINUTE, 0);
        startTime.set(Calendar.SECOND, 0);
        startTime.set(Calendar.MILLISECOND, 0);

        if (startTime.before(now) || startTime.equals(now)) {
            startTime.add(Calendar.DATE, 1);
        }

        return startTime.getTime();
    }
 
Example 8
Project: calendarview2   File: Range.java   View Source Code Vote up 6 votes
public List<CalendarDay> days() {
    List<CalendarDay> calendarDays = new ArrayList<>();
    Calendar from = Calendar.getInstance();
    this.from.copyTo(from);
    Calendar to = Calendar.getInstance();
    this.to.copyTo(to);

    while (from.before(to) || from.equals(to)) {
        calendarDays.add(CalendarDay.from(from));
        from.add(Calendar.DAY_OF_YEAR, 1);
    }

    return calendarDays;
}
 
Example 9
Project: openjdk-jdk10   File: CalendarRegression.java   View Source Code Vote up 6 votes
/**
 * 4080631: Calendar.hashCode is amazingly bad
 */
public void Test4080631() {
    Calendar cal = Calendar.getInstance();
    int h1 = cal.hashCode();
    cal.add(SECOND, +1);
    int h2 = cal.hashCode();
    Calendar cal2 = (Calendar) cal.clone();
    cal.add(MILLISECOND, +1);
    int h3 = cal.hashCode();
    logln("hash code: h1=" + h1 + ", h2=" + h2 + ", h3=" + h3);
    if (h1 == h2 || h1 == h3 || h2 == h3) {
        errln("hash code is poor: hashCode=" + h1);
    }
    h2 = cal2.hashCode();
    cal.add(MILLISECOND, -1);
    int h4 = cal.hashCode();
    logln("hash code: h2=" + h2 + ", h4=" + h4);
    if (cal.equals(cal2) && h2 != h4) {
        errln("broken hash code: h2=" + h2 + ", h4=" + h4);
    }
    int x = cal.getFirstDayOfWeek() + 3;
    if (x > SATURDAY) {
        x -= 7;
    }
    cal.setFirstDayOfWeek(x);
    int h5 = cal.hashCode();
    logln("hash code: h4=" + h4 + ", h5=" + h5);
    if (h4 == h5) {
        errln("has code is poor with first day of week param: hashCode=" + h4);
    }
}
 
Example 10
Project: Material-Calendar-View   File: DayRowClickListener.java   View Source Code Vote up 5 votes
private boolean isAnotherDaySelected(SelectedDay selectedDay, Calendar day) {
    return selectedDay != null && !day.equals(selectedDay.getCalendar())
            && isCurrentMonthDay(day) && isActiveDay(day);
}
 
Example 11
Project: openjdk-jdk10   File: CalendarRegression.java   View Source Code Vote up 5 votes
/**
 * Test whether Calendar can be serialized/deserialized correctly
 * even if invalid/customized TimeZone is used.
 */
public void Test4413980() {
    TimeZone savedTimeZone = TimeZone.getDefault();
    try {
        boolean pass = true;
        String[] IDs = new String[]{"Undefined", "PST", "US/Pacific",
            "GMT+3:00", "GMT-01:30"};
        for (int i = 0; i < IDs.length; i++) {
            TimeZone tz = TimeZone.getTimeZone(IDs[i]);
            TimeZone.setDefault(tz);

            Calendar c = Calendar.getInstance();

            // serialize
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ObjectOutputStream s = new ObjectOutputStream(out);
            s.writeObject(c);
            s.flush();

            // deserialize
            ObjectInputStream t = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));

            if (!c.equals(t.readObject())) {
                pass = false;
                logln("Calendar instance which uses TimeZone <"
                        + IDs[i] + "> is incorrectly serialized/deserialized.");
            } else {
                logln("Calendar instance which uses TimeZone <"
                        + IDs[i] + "> is correctly serialized/deserialized.");
            }
        }
        if (!pass) {
            errln("Fail: Calendar serialization/equality bug");
        }
    } catch (IOException | ClassNotFoundException e) {
        errln("Fail: " + e);
        e.printStackTrace();
    } finally {
        TimeZone.setDefault(savedTimeZone);
    }
}
 
Example 12
Project: Material-Calendar-View   File: DayColorsUtils.java   View Source Code Vote up 4 votes
/**
 * This method is used to set a color of texts, font types and backgrounds of TextView objects
 * in a current visible month. Visible day labels from previous and forward months are set using
 * setDayColors() method. It also checks if a day number is a day number of today and set it
 * a different color and bold face type.
 *
 * @param day                A calendar instance representing day date
 * @param today              A calendar instance representing today date
 * @param dayLabel           TextView containing a day number
 * @param calendarProperties A resource of a color used to mark today day
 */
public static void setCurrentMonthDayColors(Calendar day, Calendar today, TextView dayLabel,
                                            CalendarProperties calendarProperties) {
    if (today.equals(day)) {
        setDayColors(dayLabel, calendarProperties.getTodayLabelColor(), Typeface.BOLD,
                R.drawable.background_transparent);
    } else {
        setDayColors(dayLabel, calendarProperties.getDaysLabelsColor(), Typeface.NORMAL,
                R.drawable.background_transparent);
    }
}