java.util.Calendar

Here are the examples of the java api class java.util.Calendar taken from open source projects.

1. AndroidWeekViewActivity#onMonthChange()

View license
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    // Populate the week view with some events.
    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    Calendar endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR, 1);
    endTime.set(Calendar.MONTH, newMonth - 1);
    WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_01));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 30);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.HOUR_OF_DAY, 4);
    endTime.set(Calendar.MINUTE, 30);
    endTime.set(Calendar.MONTH, newMonth - 1);
    event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_02));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 4);
    startTime.set(Calendar.MINUTE, 20);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.HOUR_OF_DAY, 5);
    endTime.set(Calendar.MINUTE, 0);
    event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_03));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 5);
    startTime.set(Calendar.MINUTE, 30);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 2);
    endTime.set(Calendar.MONTH, newMonth - 1);
    event = new WeekViewEvent(2, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_02));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 5);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    startTime.add(Calendar.DATE, 1);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    endTime.set(Calendar.MONTH, newMonth - 1);
    event = new WeekViewEvent(3, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_03));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 15);
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    event = new WeekViewEvent(4, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_04));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 1);
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    event = new WeekViewEvent(5, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_01));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH));
    startTime.set(Calendar.HOUR_OF_DAY, 15);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    event = new WeekViewEvent(5, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_02));
    events.add(event);
    return events;
}

2. AndroidWeekViewActivity#onMonthChange()

View license
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    // Populate the week view with some events.
    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    Calendar endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR, 1);
    endTime.set(Calendar.MONTH, newMonth - 1);
    WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_01));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 30);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.HOUR_OF_DAY, 4);
    endTime.set(Calendar.MINUTE, 30);
    endTime.set(Calendar.MONTH, newMonth - 1);
    event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_02));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 4);
    startTime.set(Calendar.MINUTE, 20);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.HOUR_OF_DAY, 5);
    endTime.set(Calendar.MINUTE, 0);
    event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_03));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 5);
    startTime.set(Calendar.MINUTE, 30);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 2);
    endTime.set(Calendar.MONTH, newMonth - 1);
    event = new WeekViewEvent(2, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_02));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 5);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    startTime.add(Calendar.DATE, 1);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    endTime.set(Calendar.MONTH, newMonth - 1);
    event = new WeekViewEvent(3, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_03));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 15);
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    event = new WeekViewEvent(4, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_04));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 1);
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    event = new WeekViewEvent(5, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_01));
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH));
    startTime.set(Calendar.HOUR_OF_DAY, 15);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR_OF_DAY, 3);
    event = new WeekViewEvent(5, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.android_view_color_02));
    events.add(event);
    return events;
}

3. CalendarUtil#initDates()

Project: sakai
Source File: CalendarUtil.java
View license
// CalendarUtil
void initDates() {
    Calendar calendarSunday = Calendar.getInstance();
    Calendar calendarMonday = Calendar.getInstance();
    Calendar calendarTuesday = Calendar.getInstance();
    Calendar calendarWednesday = Calendar.getInstance();
    Calendar calendarThursday = Calendar.getInstance();
    Calendar calendarFriday = Calendar.getInstance();
    Calendar calendarSaturday = Calendar.getInstance();
    calendarSunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    calendarMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    calendarTuesday.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
    calendarWednesday.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
    calendarThursday.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
    calendarFriday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
    calendarSaturday.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    dateSunday = calendarSunday.getTime();
    dateMonday = calendarMonday.getTime();
    dateTuesday = calendarTuesday.getTime();
    dateWednesday = calendarWednesday.getTime();
    dateThursday = calendarThursday.getTime();
    dateFriday = calendarFriday.getTime();
    dateSaturday = calendarSaturday.getTime();
    Calendar calendarJanuary = Calendar.getInstance();
    Calendar calendarFebruary = Calendar.getInstance();
    Calendar calendarMarch = Calendar.getInstance();
    Calendar calendarApril = Calendar.getInstance();
    Calendar calendarMay = Calendar.getInstance();
    Calendar calendarJune = Calendar.getInstance();
    Calendar calendarJuly = Calendar.getInstance();
    Calendar calendarAugust = Calendar.getInstance();
    Calendar calendarSeptember = Calendar.getInstance();
    Calendar calendarOctober = Calendar.getInstance();
    Calendar calendarNovember = Calendar.getInstance();
    Calendar calendarDecember = Calendar.getInstance();
    calendarJanuary.set(Calendar.MONTH, Calendar.JANUARY);
    calendarFebruary.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendarMarch.set(Calendar.MONTH, Calendar.MARCH);
    calendarApril.set(Calendar.MONTH, Calendar.APRIL);
    calendarMay.set(Calendar.MONTH, Calendar.MAY);
    calendarJune.set(Calendar.MONTH, Calendar.JUNE);
    calendarJuly.set(Calendar.MONTH, Calendar.JULY);
    calendarAugust.set(Calendar.MONTH, Calendar.AUGUST);
    calendarSeptember.set(Calendar.MONTH, Calendar.SEPTEMBER);
    calendarOctober.set(Calendar.MONTH, Calendar.OCTOBER);
    calendarNovember.set(Calendar.MONTH, Calendar.NOVEMBER);
    calendarDecember.set(Calendar.MONTH, Calendar.DECEMBER);
    dateJanuary = calendarJanuary.getTime();
    dateFebruary = calendarFebruary.getTime();
    dateMarch = calendarMarch.getTime();
    dateApril = calendarApril.getTime();
    dateMay = calendarMay.getTime();
    dateJune = calendarJune.getTime();
    dateJuly = calendarJuly.getTime();
    dateAugust = calendarAugust.getTime();
    dateSeptember = calendarSeptember.getTime();
    dateOctober = calendarOctober.getTime();
    dateNovember = calendarNovember.getTime();
    dateDecember = calendarDecember.getTime();
}

4. DatumDependentDuration#getAgo()

Project: groovy
Source File: DatumDependentDuration.java
View license
public Date getAgo() {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -this.getYears());
    cal.add(Calendar.MONTH, -this.getMonths());
    cal.add(Calendar.DAY_OF_YEAR, -this.getDays());
    cal.add(Calendar.HOUR_OF_DAY, -this.getHours());
    cal.add(Calendar.MINUTE, -this.getMinutes());
    cal.add(Calendar.SECOND, -this.getSeconds());
    cal.add(Calendar.MILLISECOND, -this.getMillis());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new Date(cal.getTimeInMillis());
}

5. DatumDependentDuration#getAgo()

View license
public Date getAgo() {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -this.getYears());
    cal.add(Calendar.MONTH, -this.getMonths());
    cal.add(Calendar.DAY_OF_YEAR, -this.getDays());
    cal.add(Calendar.HOUR_OF_DAY, -this.getHours());
    cal.add(Calendar.MINUTE, -this.getMinutes());
    cal.add(Calendar.SECOND, -this.getSeconds());
    cal.add(Calendar.MILLISECOND, -this.getMillis());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new Date(cal.getTimeInMillis());
}

6. Weather#getNumDaysFrom()

Project: forecastie
Source File: Weather.java
View license
public long getNumDaysFrom(Date initialDate) {
    Calendar initial = Calendar.getInstance();
    initial.setTime(initialDate);
    initial.set(Calendar.MILLISECOND, 0);
    initial.set(Calendar.SECOND, 0);
    initial.set(Calendar.MINUTE, 0);
    initial.set(Calendar.HOUR, 0);
    Calendar me = Calendar.getInstance();
    me.setTime(this.date);
    me.set(Calendar.MILLISECOND, 0);
    me.set(Calendar.SECOND, 0);
    me.set(Calendar.MINUTE, 0);
    me.set(Calendar.HOUR, 0);
    return Math.round((me.getTimeInMillis() - initial.getTimeInMillis()) / 86400000.0);
}

7. Weather#getNumDaysFrom()

Project: TruWeather
Source File: Weather.java
View license
public long getNumDaysFrom(Date initialDate) {
    Calendar initial = Calendar.getInstance();
    initial.setTime(initialDate);
    initial.set(Calendar.MILLISECOND, 0);
    initial.set(Calendar.SECOND, 0);
    initial.set(Calendar.MINUTE, 0);
    initial.set(Calendar.HOUR, 0);
    Calendar me = Calendar.getInstance();
    me.setTime(this.date);
    me.set(Calendar.MILLISECOND, 0);
    me.set(Calendar.SECOND, 0);
    me.set(Calendar.MINUTE, 0);
    me.set(Calendar.HOUR, 0);
    return Math.round((me.getTimeInMillis() - initial.getTimeInMillis()) / 86400000.0);
}

8. DateTimeUtils#getRange()

Project: openhab
Source File: DateTimeUtils.java
View license
/**
     * Creates a Range object within the specified months and days. The start
     * time is midnight, the end time is end of the day.
     */
public static Range getRange(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay) {
    Calendar start = Calendar.getInstance();
    start.set(Calendar.YEAR, startYear);
    start.set(Calendar.MONTH, startMonth);
    start.set(Calendar.DAY_OF_MONTH, startDay);
    start = truncateToMidnight(start);
    Calendar end = Calendar.getInstance();
    end.set(Calendar.YEAR, endYear);
    end.set(Calendar.MONTH, endMonth);
    end.set(Calendar.DAY_OF_MONTH, endDay);
    end.set(Calendar.HOUR_OF_DAY, 23);
    end.set(Calendar.MINUTE, 59);
    end.set(Calendar.SECOND, 59);
    end.set(Calendar.MILLISECOND, 999);
    return new Range(start, end);
}

9. DateTimeUtils#getRange()

Project: openhab2-addons
Source File: DateTimeUtils.java
View license
/**
	 * Creates a Range object within the specified months and days. The start
	 * time is midnight, the end time is end of the day.
	 */
public static Range getRange(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay) {
    Calendar start = Calendar.getInstance();
    start.set(Calendar.YEAR, startYear);
    start.set(Calendar.MONTH, startMonth);
    start.set(Calendar.DAY_OF_MONTH, startDay);
    start = truncateToMidnight(start);
    Calendar end = Calendar.getInstance();
    end.set(Calendar.YEAR, endYear);
    end.set(Calendar.MONTH, endMonth);
    end.set(Calendar.DAY_OF_MONTH, endDay);
    end.set(Calendar.HOUR_OF_DAY, 23);
    end.set(Calendar.MINUTE, 59);
    end.set(Calendar.SECOND, 59);
    end.set(Calendar.MILLISECOND, 999);
    return new Range(start, end);
}

10. TestUtil#createTestCalendar()

Project: modeshape
Source File: TestUtil.java
View license
private static Calendar createTestCalendar() {
    Calendar cal_instance = new GregorianCalendar();
    cal_instance.clear();
    cal_instance.setTimeZone(TimeZone.getTimeZone(TIME_ZONE));
    cal_instance.set(Calendar.MONTH, Calendar.JUNE);
    cal_instance.set(Calendar.DAY_OF_MONTH, 30);
    cal_instance.set(Calendar.YEAR, 2004);
    cal_instance.set(Calendar.HOUR_OF_DAY, 2);
    cal_instance.set(Calendar.MINUTE, 39);
    cal_instance.set(Calendar.SECOND, 10);
    cal_instance.set(Calendar.MILLISECOND, 201);
    cal_instance.set(Calendar.AM_PM, Calendar.AM);
    return cal_instance;
}

11. DurationTest#testDuration1()

Project: ode
Source File: DurationTest.java
View license
public void testDuration1() {
    String TEST = "P10Y10M10DT10H10M10.1S";
    Duration d = new Duration(TEST);
    long time = System.currentTimeMillis();
    Calendar c1 = Calendar.getInstance();
    c1.setTimeInMillis(time);
    Calendar c2 = Calendar.getInstance();
    c2.setTimeInMillis(time);
    d.addTo(c1);
    c2.add(Calendar.YEAR, 10);
    c2.add(Calendar.MONTH, 10);
    c2.add(Calendar.DAY_OF_MONTH, 10);
    c2.add(Calendar.HOUR, 10);
    c2.add(Calendar.MINUTE, 10);
    c2.add(Calendar.SECOND, 10);
    c2.add(Calendar.MILLISECOND, 100);
    assertEquals(c2.getTimeInMillis(), c1.getTimeInMillis());
}

12. JavaSqlDateValueSemanticsProvider#add()

View license
@Override
protected Date add(final Date original, final int years, final int months, final int days, final int hours, final int minutes) {
    final Date date = original;
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.AM_PM, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.add(Calendar.YEAR, years);
    cal.add(Calendar.MONTH, months);
    cal.add(Calendar.DAY_OF_MONTH, days);
    return setDate(cal.getTime());
}

13. ZonelessDatetime#getJdbcTimestamp()

Project: calcite
Source File: ZonelessDatetime.java
View license
/**
   * Gets the value of this datetime as a milliseconds value for
   * {@link java.sql.Timestamp}.
   *
   * @param zone time zone in which to generate a time value for
   */
public long getJdbcTimestamp(TimeZone zone) {
    Calendar cal = getCalendar(DateTimeUtils.GMT_ZONE);
    cal.setTimeInMillis(internalTime);
    int year = cal.get(Calendar.YEAR);
    int doy = cal.get(Calendar.DAY_OF_YEAR);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int second = cal.get(Calendar.SECOND);
    int millis = cal.get(Calendar.MILLISECOND);
    cal.clear();
    cal.setTimeZone(zone);
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.DAY_OF_YEAR, doy);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millis);
    return cal.getTimeInMillis();
}

14. DateTimeField#changeTimeZone()

Project: wicket
Source File: DateTimeField.java
View license
/**
	 * Change a date in another timezone
	 * 
	 * @param date
	 *            The input date.
	 * @param zone
	 *            The target timezone.
	 * @return A new converted date.
	 */
public static Date changeTimeZone(Date date, TimeZone zone) {
    Calendar first = Calendar.getInstance(zone);
    first.setTimeInMillis(date.getTime());
    Calendar output = Calendar.getInstance();
    output.set(Calendar.YEAR, first.get(Calendar.YEAR));
    output.set(Calendar.MONTH, first.get(Calendar.MONTH));
    output.set(Calendar.DAY_OF_MONTH, first.get(Calendar.DAY_OF_MONTH));
    output.set(Calendar.HOUR_OF_DAY, first.get(Calendar.HOUR_OF_DAY));
    output.set(Calendar.MINUTE, first.get(Calendar.MINUTE));
    output.set(Calendar.SECOND, first.get(Calendar.SECOND));
    output.set(Calendar.MILLISECOND, first.get(Calendar.MILLISECOND));
    return output.getTime();
}

15. CalendarTest#test_compareToLjava_util_Calendar()

Project: j2objc
Source File: CalendarTest.java
View license
/**
	 * java.util.Calendar#compareTo(Calendar)
	 */
public void test_compareToLjava_util_Calendar() {
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1997, 12, 13, 23, 57);
    Calendar anotherCal = Calendar.getInstance();
    anotherCal.clear();
    anotherCal.set(1997, 12, 13, 23, 57);
    assertEquals(0, cal.compareTo(anotherCal));
    anotherCal = Calendar.getInstance();
    anotherCal.clear();
    anotherCal.set(1997, 11, 13, 24, 57);
    assertEquals(1, cal.compareTo(anotherCal));
    anotherCal = Calendar.getInstance();
    anotherCal.clear();
    anotherCal.set(1997, 12, 13, 23, 58);
    assertEquals(-1, cal.compareTo(anotherCal));
}

16. Dates#countDaysBetween()

Project: hudson-2.x
Source File: Dates.java
View license
public static long countDaysBetween(final Date start, final Date end) {
    checkNotNull(start);
    checkNotNull(end);
    //reset all hours mins and secs to zero on start date
    Calendar startCal = GregorianCalendar.getInstance();
    startCal.setTime(start);
    startCal.set(Calendar.HOUR_OF_DAY, 0);
    startCal.set(Calendar.MINUTE, 0);
    startCal.set(Calendar.SECOND, 0);
    long startTime = startCal.getTimeInMillis();
    //reset all hours mins and secs to zero on end date
    Calendar endCal = GregorianCalendar.getInstance();
    endCal.setTime(end);
    endCal.set(Calendar.HOUR_OF_DAY, 0);
    endCal.set(Calendar.MINUTE, 0);
    endCal.set(Calendar.SECOND, 0);
    long endTime = endCal.getTimeInMillis();
    return (endTime - startTime) / MILLISECONDS_IN_DAY;
}

17. DateUtil#createDate()

Project: encog-java-core
Source File: DateUtil.java
View license
/**
	 * Create a Date object with the specified date.
	 * 
	 * @param month
	 *            The month, starting with 1 for Jan.
	 * @param day
	 *            The day of the month.
	 * @param year
	 *            The year.
	 * @return The newly created Date.
	 */
public static Date createDate(final int month, final int day, final int year) {
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.AM_PM, Calendar.AM);
    return cal.getTime();
}

18. z_F4JInternalStringUtilTest#formatISO8601Datetime()

View license
@Test
public void formatISO8601Datetime() throws Exception {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2012);
    cal.set(Calendar.MONTH, 5);
    cal.set(Calendar.DAY_OF_MONTH, 15);
    cal.set(Calendar.HOUR_OF_DAY, 16);
    cal.set(Calendar.MINUTE, 17);
    cal.set(Calendar.SECOND, 18);
    cal.set(Calendar.MILLISECOND, 0);
    cal.setTimeZone(TimeZone.getTimeZone("JST"));
    String actual1 = z_F4JInternalStringUtil.formatISO8601Datetime(cal);
    assertThat(actual1, is("2012-06-15T16:17:18+0900"));
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    String actual2 = z_F4JInternalStringUtil.formatISO8601Datetime(cal);
    //16-9=7
    assertThat(actual2, is("2012-06-15T07:17:18+0000"));
    JSONObject json = new JSONObject("{\"datetime1\": \"" + actual1 + "\", \"datetime2\": \"" + actual2 + "\"}");
    Date d1 = z_F4JInternalParseUtil.getISO8601Datetime("datetime1", json);
    Date d2 = z_F4JInternalParseUtil.getISO8601Datetime("datetime2", json);
    assertThat(d1, is(d2));
}

19. BaseDuration#plus()

Project: groovy
Source File: BaseDuration.java
View license
public Date plus(final Date date) {
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.YEAR, this.years);
    cal.add(Calendar.MONTH, this.months);
    cal.add(Calendar.DAY_OF_YEAR, this.days);
    cal.add(Calendar.HOUR_OF_DAY, this.hours);
    cal.add(Calendar.MINUTE, this.minutes);
    cal.add(Calendar.SECOND, this.seconds);
    cal.add(Calendar.MILLISECOND, this.millis);
    return cal.getTime();
}

20. Duration#getAgo()

Project: groovy
Source File: Duration.java
View license
public Date getAgo() {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, -this.getDays());
    cal.add(Calendar.HOUR_OF_DAY, -this.getHours());
    cal.add(Calendar.MINUTE, -this.getMinutes());
    cal.add(Calendar.SECOND, -this.getSeconds());
    cal.add(Calendar.MILLISECOND, -this.getMillis());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new Date(cal.getTimeInMillis());
}

21. TimeCategory#minus()

Project: groovy
Source File: TimeCategory.java
View license
public static Date minus(final Date date, final BaseDuration duration) {
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.YEAR, -duration.getYears());
    cal.add(Calendar.MONTH, -duration.getMonths());
    cal.add(Calendar.DAY_OF_YEAR, -duration.getDays());
    cal.add(Calendar.HOUR_OF_DAY, -duration.getHours());
    cal.add(Calendar.MINUTE, -duration.getMinutes());
    cal.add(Calendar.SECOND, -duration.getSeconds());
    cal.add(Calendar.MILLISECOND, -duration.getMillis());
    return cal.getTime();
}

22. Dates#internalDate()

Project: groovy
Source File: Dates.java
View license
private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int miliseconds) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MILLISECOND, miliseconds);
    calendar.setTimeZone(tz);
    return calendar.getTime();
}

23. BaseDuration#plus()

Project: groovy-core
Source File: BaseDuration.java
View license
public Date plus(final Date date) {
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.YEAR, this.years);
    cal.add(Calendar.MONTH, this.months);
    cal.add(Calendar.DAY_OF_YEAR, this.days);
    cal.add(Calendar.HOUR_OF_DAY, this.hours);
    cal.add(Calendar.MINUTE, this.minutes);
    cal.add(Calendar.SECOND, this.seconds);
    cal.add(Calendar.MILLISECOND, this.millis);
    return cal.getTime();
}

24. Duration#getAgo()

Project: groovy-core
Source File: Duration.java
View license
public Date getAgo() {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, -this.getDays());
    cal.add(Calendar.HOUR_OF_DAY, -this.getHours());
    cal.add(Calendar.MINUTE, -this.getMinutes());
    cal.add(Calendar.SECOND, -this.getSeconds());
    cal.add(Calendar.MILLISECOND, -this.getMillis());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new Date(cal.getTimeInMillis());
}

25. TimeCategory#minus()

Project: groovy-core
Source File: TimeCategory.java
View license
public static Date minus(final Date date, final BaseDuration duration) {
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.YEAR, -duration.getYears());
    cal.add(Calendar.MONTH, -duration.getMonths());
    cal.add(Calendar.DAY_OF_YEAR, -duration.getDays());
    cal.add(Calendar.HOUR_OF_DAY, -duration.getHours());
    cal.add(Calendar.MINUTE, -duration.getMinutes());
    cal.add(Calendar.SECOND, -duration.getSeconds());
    cal.add(Calendar.MILLISECOND, -duration.getMillis());
    return cal.getTime();
}

26. Dates#internalDate()

Project: groovy-core
Source File: Dates.java
View license
private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int miliseconds) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MILLISECOND, miliseconds);
    calendar.setTimeZone(tz);
    return calendar.getTime();
}

27. Week#getFirstMillisecond()

Project: jfreechart-fse
Source File: Week.java
View license
/**
     * Returns the first millisecond of the week, evaluated using the supplied
     * calendar (which determines the time zone).
     *
     * @param calendar  the calendar (<code>null</code> not permitted).
     *
     * @return The first millisecond of the week.
     *
     * @throws NullPointerException if {@code calendar} is {@code null}.
     */
@Override
public long getFirstMillisecond(Calendar calendar) {
    Calendar c = (Calendar) calendar.clone();
    c.clear();
    c.set(Calendar.YEAR, this.year);
    c.set(Calendar.WEEK_OF_YEAR, this.week);
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

28. JSONDeserializerTest#testUnixEpoch()

Project: jodd
Source File: JSONDeserializerTest.java
View license
@Test
public void testUnixEpoch() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    cal.set(Calendar.YEAR, 1970);
    cal.set(Calendar.MONTH, 0);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Person hank = new Person("Hank", "Paulsen", cal.getTime(), null, null);
    String json = new JsonSerializer().serialize(hank);
    Person deHank = new JsonParser().parse(json, Person.class);
    assertEquals(hank.getFirstname(), deHank.getFirstname());
    assertEquals(hank.getLastname(), deHank.getLastname());
    assertEquals(hank.getBirthdate(), deHank.getBirthdate());
}

29. TimestampWithTimezoneTest#testDateToDateConversion2()

View license
@Test
public void testDateToDateConversion2() {
    Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("America/Chicago"));
    localTime.set(Calendar.MONTH, Calendar.JUNE);
    localTime.set(Calendar.DAY_OF_MONTH, 22);
    localTime.set(Calendar.YEAR, 2004);
    localTime.set(Calendar.HOUR, 23);
    localTime.set(Calendar.MINUTE, 15);
    localTime.set(Calendar.SECOND, 20);
    localTime.set(Calendar.AM_PM, Calendar.PM);
    //$NON-NLS-1$ 
    Date converted = TimestampWithTimezone.createDate(localTime, Calendar.getInstance(TimeZone.getTimeZone("Europe/London")));
    Calendar cal = Calendar.getInstance();
    cal.setTime(converted);
    assertThat(cal.get(Calendar.MILLISECOND), is(0));
}

30. DateUtils#get()

Project: metamodel
Source File: DateUtils.java
View license
public static Date get(int year, Month month, int dayOfMonth) {
    Calendar c = createCalendar();
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month.getCalendarConstant());
    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.AM_PM, 0);
    return c.getTime();
}

31. CalendarBean#sameDay()

Project: sakai
Source File: CalendarBean.java
View license
private boolean sameDay(Calendar date1, Date date2) {
    Calendar cal1 = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale());
    cal1.setTime(date1.getTime());
    cal1.set(Calendar.HOUR_OF_DAY, 0);
    cal1.set(Calendar.MINUTE, 0);
    cal1.set(Calendar.SECOND, 0);
    Calendar cal2 = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale());
    cal2.setTime(date2);
    cal2.set(Calendar.HOUR_OF_DAY, 0);
    cal2.set(Calendar.MINUTE, 0);
    cal2.set(Calendar.SECOND, 0);
    return (cal2.get(Calendar.YEAR) == cal1.get(Calendar.YEAR)) && (cal2.get(Calendar.MONTH) == cal1.get(Calendar.MONTH)) && (cal2.get(Calendar.DAY_OF_MONTH) == cal1.get(Calendar.DAY_OF_MONTH));
}

32. DotNETDateTest#getCalendar()

View license
private Calendar getCalendar(final int year, final int month, final int day, final int hour, final int min, final int sec, final int millis) {
    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.AM_PM, Calendar.AM);
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR, hour);
    calendar.set(Calendar.MINUTE, min);
    calendar.set(Calendar.SECOND, sec);
    calendar.set(Calendar.MILLISECOND, millis);
    //$NON-NLS-1$
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    return calendar;
}

33. CalendarTest#test_compareToLjava_util_Calendar()

Project: teavm
Source File: CalendarTest.java
View license
/**
     * @tests java.util.Calendar#compareTo(Calendar)
     */
@Test
public void test_compareToLjava_util_Calendar() {
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1997, 12, 13, 23, 57);
    Calendar anotherCal = Calendar.getInstance();
    anotherCal.clear();
    anotherCal.set(1997, 12, 13, 23, 57);
    assertEquals(0, cal.compareTo(anotherCal));
    anotherCal = Calendar.getInstance();
    anotherCal.clear();
    anotherCal.set(1997, 11, 13, 24, 57);
    assertEquals(1, cal.compareTo(anotherCal));
    anotherCal = Calendar.getInstance();
    anotherCal.clear();
    anotherCal.set(1997, 12, 13, 23, 58);
    assertEquals(-1, cal.compareTo(anotherCal));
}

34. Dates#internalDate()

Project: boon
Source File: Dates.java
View license
private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.setTimeZone(tz);
    return calendar.getTime();
}

35. Dates#internalDate()

Project: boon
Source File: Dates.java
View license
private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int miliseconds) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MILLISECOND, miliseconds);
    calendar.setTimeZone(tz);
    return calendar.getTime();
}

36. MainActivity#onStart()

View license
@Override
protected void onStart() {
    super.onStart();
    Calendar end = Calendar.getInstance();
    end.add(Calendar.MINUTE, 4);
    end.add(Calendar.SECOND, 5);
    Calendar start = Calendar.getInstance();
    start.add(Calendar.MINUTE, -1);
    if (mCountDown != null) {
        mCountDown.start(start, end);
    }
    Calendar c2 = Calendar.getInstance();
    c2.add(Calendar.HOUR, 2);
    c2.set(Calendar.MINUTE, 0);
    c2.set(Calendar.SECOND, 0);
    c2.set(Calendar.MILLISECOND, 0);
    if (mCountUp != null) {
        mCountUp.start(c2);
    }
}

37. Duration#add()

Project: community-edition
Source File: Duration.java
View license
// Date duration arithmetic
/**
    * Add a duration to a date and return the date plus the specified increment.
    * 
    * @param date - the initial date
    * @param duration - the duration to add on to the date (the duration may be negative)
    * @return the adjusted date.
    */
public static Date add(Date date, Duration duration) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.YEAR, (duration.m_positive ? 1 : -1) * duration.m_years);
    c.add(Calendar.MONTH, (duration.m_positive ? 1 : -1) * duration.m_months);
    c.add(Calendar.DATE, (duration.m_positive ? 1 : -1) * duration.m_days);
    c.add(Calendar.HOUR_OF_DAY, (duration.m_positive ? 1 : -1) * duration.m_hours);
    c.add(Calendar.MINUTE, (duration.m_positive ? 1 : -1) * duration.m_mins);
    c.add(Calendar.SECOND, (duration.m_positive ? 1 : -1) * duration.m_seconds);
    c.add(Calendar.MILLISECOND, (duration.m_positive ? 1 : -1) * duration.m_nanos / 1000000);
    return c.getTime();
}

38. TestPropertyListParser#testParseDate()

View license
@Test
public void testParseDate() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2002);
    calendar.set(Calendar.MONTH, Calendar.MARCH);
    calendar.set(Calendar.DAY_OF_MONTH, 22);
    calendar.set(Calendar.HOUR_OF_DAY, 11);
    calendar.set(Calendar.MINUTE, 30);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.setTimeZone(new SimpleTimeZone(60 * 60 * 1000, "Apache/Jakarta"));
    assertEquals("parsed date", calendar.getTime(), parser.parseDate("<*D2002-03-22 11:30:00 +0100>"));
}

39. ZonelessTime#getJdbcTimestamp()

Project: calcite
Source File: ZonelessTime.java
View license
/**
   * Override ZonelessDatetime.
   *
   * <p>NOTE: the returned timestamp is based on the current date of the
   * specified time zone, rather than the context variable for current_date,
   * as specified by the SQL standard.
   */
public long getJdbcTimestamp(TimeZone zone) {
    Calendar cal = getCalendar(DateTimeUtils.GMT_ZONE);
    cal.setTimeInMillis(getTime());
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int second = cal.get(Calendar.SECOND);
    int millis = cal.get(Calendar.MILLISECOND);
    cal.setTimeZone(zone);
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millis);
    return cal.getTimeInMillis();
}

40. CalendarUtils#daysSince()

Project: cgeo
Source File: CalendarUtils.java
View license
public static int daysSince(final long date) {
    final Calendar logDate = Calendar.getInstance();
    logDate.setTimeInMillis(date);
    logDate.set(Calendar.SECOND, 0);
    logDate.set(Calendar.MINUTE, 0);
    logDate.set(Calendar.HOUR_OF_DAY, 0);
    final Calendar today = Calendar.getInstance();
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d);
}

41. AbstractExpiresHeaderFilterTest#testGetHeaderValue()

View license
@Test
public void testGetHeaderValue() throws Exception {
    when(componentContext.getProperties()).thenReturn(properties);
    Calendar expected = Calendar.getInstance();
    expected.set(Calendar.HOUR_OF_DAY, 2);
    expected.set(Calendar.MINUTE, 30);
    expected.set(Calendar.SECOND, 0);
    expected.set(Calendar.MILLISECOND, 0);
    filter.doActivate(componentContext);
    String header = filter.getHeaderValue();
    Date date = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z").parse(header);
    Calendar actual = Calendar.getInstance();
    actual.setTime(date);
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    assertTrue(DateUtils.isSameInstant(expected, actual));
}

42. ExcelSheetRuleProviderTest#value_now()

View license
/**
     * {@link ValueConditionKind} - now.
     * @throws Exception if occur
     */
@Test
public void value_now() throws Exception {
    // 2011/03/31 23:00:00 -> 23:30:00
    VerifyContext context = context(30);
    VerifyRule rule = rule("verify/value_now.xls", context);
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(2011, 2, 31, 0, 0, 0);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), not(nullValue()));
    calendar.set(2011, 2, 31, 22, 59, 59);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), not(nullValue()));
    calendar.set(2011, 2, 31, 23, 0, 0);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), is(nullValue()));
    calendar.set(2011, 2, 31, 23, 15, 0);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), is(nullValue()));
    calendar.set(2011, 2, 31, 23, 30, 00);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), is(nullValue()));
    calendar.set(2011, 2, 31, 23, 30, 01);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), not(nullValue()));
    calendar.set(2011, 2, 31, 23, 45, 00);
    assertThat(rule.verify(obj(0, ""), datetime(calendar)), not(nullValue()));
}

43. ExcelSheetOrdinalRuleTest#datetime()

View license
private Calendar datetime(int offset) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, NOW.get(Calendar.YEAR));
    calendar.set(Calendar.MONTH, NOW.get(Calendar.MONTH));
    calendar.set(Calendar.DATE, NOW.get(Calendar.DATE));
    calendar.set(Calendar.HOUR_OF_DAY, NOW.get(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, NOW.get(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, NOW.get(Calendar.SECOND));
    calendar.add(Calendar.SECOND, offset);
    return calendar;
}

44. TestDeser2001#deserializeCalendar()

Project: axis1-java
Source File: TestDeser2001.java
View license
private void deserializeCalendar(int year, int month, int day, TimeZone tz) throws Exception {
    Calendar date = Calendar.getInstance();
    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    date.set(Calendar.HOUR_OF_DAY, 12);
    date.set(Calendar.MINUTE, 01);
    date.set(Calendar.SECOND, 30);
    date.set(Calendar.MILLISECOND, 150);
    date.setTimeZone(tz);
    Time time = new Time(date);
    String offset = calcGMTOffset(date);
    //diagnostics string
    String comment = " [time=" + time.toString() + "; tz=" + tz.getDisplayName() + "; offset=" + offset + "]";
    deserialize("<result xsi:type=\"xsd:time\">" + "12:01:30.150" + offset + "</result>", time, false, comment);
}

45. DateHelper#nowBeforeTrimToMidnight()

Project: communote-server
Source File: DateHelper.java
View license
/**
     * Subtract the time from now and reset the time of the given day
     * 
     * @param time
     *            the time to subtract from now
     * @return the date in milliseconds from today minus the date given but set to midnight of the
     *         same day
     */
public static long nowBeforeTrimToMidnight(long time) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(new Date(nowBefore(time)));
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.AM_PM, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

46. DateTimeUtil#convertToShortYear()

Project: YiBo
Source File: DateTimeUtil.java
View license
public static Date convertToShortYear(Date date) {
    if (date == null) {
        return null;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}

47. TestCompositeDateFormat#beforeClass()

Project: jesque
Source File: TestCompositeDateFormat.java
View license
@BeforeClass
public static void beforeClass() {
    final Calendar cal = Calendar.getInstance(Locale.US);
    cal.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    cal.set(Calendar.YEAR, 2013);
    cal.set(Calendar.MONTH, Calendar.MARCH);
    cal.set(Calendar.DATE, 7);
    cal.set(Calendar.HOUR_OF_DAY, 21);
    cal.set(Calendar.MINUTE, 26);
    cal.set(Calendar.SECOND, 05);
    cal.set(Calendar.MILLISECOND, 234);
    date = cal.getTime();
}

48. Week#getLastMillisecond()

Project: jfreechart-fse
Source File: Week.java
View license
/**
     * Returns the last millisecond of the week, evaluated using the supplied
     * calendar (which determines the time zone).
     *
     * @param calendar  the calendar (<code>null</code> not permitted).
     *
     * @return The last millisecond of the week.
     *
     * @throws NullPointerException if {@code calendar} is {@code null}.
     */
@Override
public long getLastMillisecond(Calendar calendar) {
    Calendar c = (Calendar) calendar.clone();
    c.clear();
    c.set(Calendar.YEAR, this.year);
    c.set(Calendar.WEEK_OF_YEAR, this.week + 1);
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis() - 1;
}

49. TestClock#time()

Project: isis
Source File: TestClock.java
View license
/**
     * Always return the time as 2003/8/17 21:30:25
     */
@Override
protected long time() {
    final Calendar c = Calendar.getInstance();
    c.setTimeZone(timeZone);
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.YEAR, 2003);
    c.set(Calendar.MONTH, 7);
    c.set(Calendar.DAY_OF_MONTH, 17);
    c.set(Calendar.HOUR_OF_DAY, 21);
    c.set(Calendar.MINUTE, 30);
    c.set(Calendar.SECOND, 25);
    return c.getTime().getTime();
}

50. JavaUtilDateValueSemanticsProvider#add()

View license
@Override
protected Date add(final Date original, final int years, final int months, final int days, final int hours, final int minutes) {
    final Date date = original;
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.add(Calendar.YEAR, years);
    cal.add(Calendar.MONTH, months);
    cal.add(Calendar.DAY_OF_MONTH, days);
    cal.add(Calendar.HOUR, hours);
    cal.add(Calendar.MINUTE, minutes);
    return setDate(cal.getTime());
}

51. TestClock#time()

Project: isis
Source File: TestClock.java
View license
/**
     * Always return the time as 2003/8/17 21:30:25
     */
@Override
protected long time() {
    final Calendar c = Calendar.getInstance();
    c.setTimeZone(timeZone);
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.YEAR, 2003);
    c.set(Calendar.MONTH, 7);
    c.set(Calendar.DAY_OF_MONTH, 17);
    c.set(Calendar.HOUR_OF_DAY, 21);
    c.set(Calendar.MINUTE, 30);
    c.set(Calendar.SECOND, 25);
    return c.getTime().getTime();
}

52. CalendarTest#test_getTimeInMillis()

Project: j2objc
Source File: CalendarTest.java
View license
/**
     * java.util.Calendar#getTimeInMillis()
     */
public void test_getTimeInMillis() {
    Calendar cal = Calendar.getInstance();
    int year = Integer.MIN_VALUE + 71;
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    cal.set(Calendar.YEAR, year + 1900);
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DATE, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    assertEquals(6017546357372606464L, cal.getTimeInMillis());
}

53. OrderByDateTest#testDateOrderMillis()

Project: jackrabbit
Source File: OrderByDateTest.java
View license
/**
     * Tests order by queries with calendar properties where the calendar
     * values only have a millisecond difference.
     */
public void testDateOrderMillis() throws Exception {
    Calendar c1 = Calendar.getInstance();
    c1.set(2000, 6, 12, 14, 35, 19);
    c1.set(Calendar.MILLISECOND, 10);
    Calendar c2 = Calendar.getInstance();
    c2.set(2000, 6, 12, 14, 35, 19);
    c2.set(Calendar.MILLISECOND, 9);
    Calendar c3 = Calendar.getInstance();
    c3.set(2000, 6, 12, 14, 35, 19);
    c3.set(Calendar.MILLISECOND, 11);
    populate(new Calendar[] { c1, c2, c3 });
    checkOrder(new String[] { nodeName2, nodeName1, nodeName3 });
}

54. OrderByDateTest#testDateOrderPositiveTimeZone()

Project: jackrabbit
Source File: OrderByDateTest.java
View license
/**
     * Tests order by queries with calendar properties where the calendar
     * values have different time zones.
     */
public void testDateOrderPositiveTimeZone() throws Exception {
    Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
    c1.set(2000, 6, 12, 15, 35, 19);
    c1.set(Calendar.MILLISECOND, 10);
    Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    c2.set(2000, 6, 12, 14, 35, 19);
    c2.set(Calendar.MILLISECOND, 9);
    Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    c3.set(2000, 6, 12, 14, 35, 19);
    c3.set(Calendar.MILLISECOND, 11);
    populate(new Calendar[] { c1, c2, c3 });
    checkOrder(new String[] { nodeName2, nodeName1, nodeName3 });
}

55. OrderByDateTest#testDateOrderNegativeTimeZone()

Project: jackrabbit
Source File: OrderByDateTest.java
View license
/**
     * Tests order by queries with calendar properties where the calendar
     * values have different time zones.
     */
public void testDateOrderNegativeTimeZone() throws Exception {
    Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone("GMT-1:00"));
    c1.set(2000, 6, 12, 13, 35, 19);
    c1.set(Calendar.MILLISECOND, 10);
    Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    c2.set(2000, 6, 12, 14, 35, 19);
    c2.set(Calendar.MILLISECOND, 9);
    Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    c3.set(2000, 6, 12, 14, 35, 19);
    c3.set(Calendar.MILLISECOND, 11);
    populate(new Calendar[] { c1, c2, c3 });
    checkOrder(new String[] { nodeName2, nodeName1, nodeName3 });
}

56. MXFMetadata#readDate()

Project: jcodec
Source File: MXFMetadata.java
View license
protected static Date readDate(ByteBuffer _bb) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, _bb.getShort());
    calendar.set(Calendar.MONTH, _bb.get());
    calendar.set(Calendar.DAY_OF_MONTH, _bb.get());
    calendar.set(Calendar.HOUR, _bb.get());
    calendar.set(Calendar.MINUTE, _bb.get());
    calendar.set(Calendar.SECOND, _bb.get());
    calendar.set(Calendar.MILLISECOND, (_bb.get() & 0xff) << 2);
    return calendar.getTime();
}

57. Dates#internalDate()

Project: groovy-core
Source File: Dates.java
View license
private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.setTimeZone(tz);
    return calendar.getTime();
}

58. GeneralizedTimeTest#testCalendar()

View license
/**
     * Tests constructor with calendar object.
     */
@Test
public void testCalendar() throws ParseException {
    Calendar calendar = new GregorianCalendar(GMT, Locale.ROOT);
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 2);
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 13);
    calendar.set(Calendar.SECOND, 14);
    calendar.set(Calendar.MILLISECOND, 222);
    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
    GeneralizedTime generalizedTime = new GeneralizedTime(calendar);
    String result = generalizedTime.toGeneralizedTime();
    assertEquals("20080102121314.222Z", result);
}

59. CalendarTest#test_getTimeInMillis()

Project: teavm
Source File: CalendarTest.java
View license
/**
     * @tests java.util.Calendar#clone()
     */
//@Test
//public void test_clone() {
//    // Regression for HARMONY-475
//    Calendar cal = Calendar.getInstance();
//    cal.set(2006, 5, 6, 11, 35);
//    Calendar anotherCal = (Calendar) cal.clone();
//    // should be deep clone
//    assertNotSame("getTimeZone", cal.getTimeZone(), anotherCal
//            .getTimeZone());
//}
/**
     * @tests java.util.Calendar#getTimeInMillis()
     */
@Test
public void test_getTimeInMillis() {
    Calendar cal = Calendar.getInstance();
    int year = Integer.MIN_VALUE + 71;
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    cal.set(Calendar.YEAR, year + 1900);
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DATE, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    assertEquals(6017546357372606464L, cal.getTimeInMillis());
}

60. ZonelessTime#getJdbcTimestamp()

Project: optiq
Source File: ZonelessTime.java
View license
/**
   * Override ZonelessDatetime.
   *
   * <p>NOTE: the returned timestamp is based on the current date of the
   * specified time zone, rather than the context variable for current_date,
   * as specified by the SQL standard.
   */
public long getJdbcTimestamp(TimeZone zone) {
    Calendar cal = getCalendar(DateTimeUtil.GMT_ZONE);
    cal.setTimeInMillis(getTime());
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int second = cal.get(Calendar.SECOND);
    int millis = cal.get(Calendar.MILLISECOND);
    cal.setTimeZone(zone);
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millis);
    return cal.getTimeInMillis();
}

61. DimensionLookupMeta#getMinDate()

View license
public Date getMinDate() {
    Calendar mincal = Calendar.getInstance();
    mincal.set(Calendar.YEAR, minYear);
    mincal.set(Calendar.MONTH, 0);
    mincal.set(Calendar.DAY_OF_MONTH, 1);
    mincal.set(Calendar.HOUR_OF_DAY, 0);
    mincal.set(Calendar.MINUTE, 0);
    mincal.set(Calendar.SECOND, 0);
    mincal.set(Calendar.MILLISECOND, 0);
    return mincal.getTime();
}

62. DimensionLookupMeta#getMaxDate()

View license
public Date getMaxDate() {
    Calendar mincal = Calendar.getInstance();
    mincal.set(Calendar.YEAR, maxYear);
    mincal.set(Calendar.MONTH, 11);
    mincal.set(Calendar.DAY_OF_MONTH, 31);
    mincal.set(Calendar.HOUR_OF_DAY, 23);
    mincal.set(Calendar.MINUTE, 59);
    mincal.set(Calendar.SECOND, 59);
    mincal.set(Calendar.MILLISECOND, 999);
    return mincal.getTime();
}

63. DateUtils#getDate()

Project: QRParserLib
Source File: DateUtils.java
View license
public static Date getDate(int year, int month, int day, int hour, int min, int sec) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, min);
    cal.set(Calendar.SECOND, sec);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

64. DateUtils#getLongFromDateTime()

Project: Omni-Notes
Source File: DateUtils.java
View license
public static Calendar getLongFromDateTime(String date, String dateFormat, String time, String timeFormat) {
    Calendar cal = Calendar.getInstance();
    Calendar cDate = Calendar.getInstance();
    Calendar cTime = Calendar.getInstance();
    SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat);
    SimpleDateFormat sdfTime = new SimpleDateFormat(timeFormat);
    try {
        cDate.setTime(sdfDate.parse(date));
        cTime.setTime(sdfTime.parse(time));
    } catch (ParseException e) {
        Log.e(Constants.TAG, "Date or time parsing error: " + e.getMessage());
    }
    cal.set(Calendar.YEAR, cDate.get(Calendar.YEAR));
    cal.set(Calendar.MONTH, cDate.get(Calendar.MONTH));
    cal.set(Calendar.DAY_OF_MONTH, cDate.get(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, cTime.get(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cTime.get(Calendar.MINUTE));
    cal.set(Calendar.SECOND, 0);
    return cal;
}

65. AbstractModelInterpolatorTest#testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover()

View license
public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
    cal.set(Calendar.HOUR_OF_DAY, 1);
    cal.set(Calendar.MINUTE, 16);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.YEAR, 2014);
    cal.set(Calendar.MONTH, Calendar.JUNE);
    cal.set(Calendar.DATE, 16);
    Date firstTestDate = cal.getTime();
    cal.set(Calendar.MONTH, Calendar.NOVEMBER);
    Date secondTestDate = cal.getTime();
    SimpleDateFormat format = new SimpleDateFormat(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT);
    format.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE);
    assertEquals("2014-06-15T23:16:00Z", format.format(firstTestDate));
    assertEquals("2014-11-16T00:16:00Z", format.format(secondTestDate));
}

66. DateUtilsRoundingTest#roundToJanuaryFirst()

View license
/**
     * 
     * Any January 1 could be considered as the ultimate extreme.
     * Instead of comparing the results if the input has a difference of 1 millisecond we check the output to be exactly January first. 
     * 
     * @param minDate the lower bound
     * @param maxDate the upper bound
     * @param calendarField a Calendar.field value
     * @since 3.0
     */
protected void roundToJanuaryFirst(final Date minDate, final Date maxDate, final int calendarField) {
    assertEquals("Rounding " + fdf.format(januaryOneDate) + " as Date with CalendarField-value " + calendarField + " must return itself", januaryOneDate, DateUtils.round(januaryOneDate, calendarField));
    assertEquals(januaryOneDate, DateUtils.round(minDate, calendarField));
    assertEquals(januaryOneDate, DateUtils.round(maxDate, calendarField));
    final Calendar minCalendar = Calendar.getInstance();
    minCalendar.setTime(minDate);
    final Calendar maxCalendar = Calendar.getInstance();
    maxCalendar.setTime(maxDate);
    assertEquals("Rounding " + fdf.format(januaryOneCalendar) + " as Date with CalendarField-value " + calendarField + " must return itself", januaryOneCalendar, DateUtils.round(januaryOneCalendar, calendarField));
    assertEquals(januaryOneCalendar, DateUtils.round(minCalendar, calendarField));
    assertEquals(januaryOneCalendar, DateUtils.round(maxCalendar, calendarField));
    final Date toPrevRoundDate = DateUtils.addMilliseconds(minDate, -1);
    final Date toNextRoundDate = DateUtils.addMilliseconds(maxDate, 1);
    assertFalse(fdf.format(minDate) + " is not an lower-extreme when rounding as Date with CalendarField-value " + calendarField, januaryOneDate.equals(DateUtils.round(toPrevRoundDate, calendarField)));
    assertFalse(fdf.format(maxDate) + " is not an upper-extreme when rounding as Date with CalendarField-value " + calendarField, januaryOneDate.equals(DateUtils.round(toNextRoundDate, calendarField)));
    final Calendar toPrevRoundCalendar = Calendar.getInstance();
    toPrevRoundCalendar.setTime(toPrevRoundDate);
    final Calendar toNextRoundCalendar = Calendar.getInstance();
    toNextRoundCalendar.setTime(toNextRoundDate);
    assertFalse(fdf.format(minCalendar) + " is not an lower-extreme when rounding as Date with CalendarField-value " + calendarField, januaryOneDate.equals(DateUtils.round(toPrevRoundDate, calendarField)));
    assertFalse(fdf.format(maxCalendar) + " is not an upper-extreme when rounding as Date with CalendarField-value " + calendarField, januaryOneDate.equals(DateUtils.round(toNextRoundDate, calendarField)));
}

67. OVChipTransitData#convertDate()

Project: farebot
Source File: OVChipTransitData.java
View license
public static Date convertDate(int date, int time) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 1997);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, time / 60);
    calendar.set(Calendar.MINUTE, time % 60);
    calendar.add(Calendar.DATE, date);
    return calendar.getTime();
}

68. JavaSqlTimeValueSemanticsProvider#add()

View license
@Override
public Time add(final Time original, final int years, final int months, final int days, final int hours, final int minutes) {
    final java.sql.Time time = original;
    final Calendar cal = Calendar.getInstance();
    cal.setTime(time);
    cal.set(Calendar.YEAR, 0);
    cal.set(Calendar.MONTH, 0);
    cal.set(Calendar.DAY_OF_MONTH, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.add(Calendar.HOUR, hours);
    cal.add(Calendar.MINUTE, minutes);
    return setDate(cal.getTime());
}

69. TimestampDateTypeDescriptorTest#createDate()

View license
private Date createDate(int dayOfMonth) {
    Calendar instance = Calendar.getInstance();
    instance.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    instance.set(Calendar.MONTH, Calendar.AUGUST);
    instance.set(Calendar.YEAR, 2113);
    instance.set(Calendar.HOUR_OF_DAY, 21);
    instance.set(Calendar.MINUTE, 58);
    instance.set(Calendar.SECOND, 39);
    instance.set(Calendar.MILLISECOND, 777);
    Date one = instance.getTime();
    return one;
}

70. TestWithDateFormats#setUp()

View license
@Before
public void setUp() {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-04:00"));
    cal.set(Calendar.YEAR, 2012);
    cal.set(Calendar.MONTH, Calendar.APRIL);
    cal.set(Calendar.DAY_OF_MONTH, 20);
    cal.set(Calendar.HOUR_OF_DAY, 16);
    cal.set(Calendar.MINUTE, 20);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    date = cal.getTime();
}

71. TestHumanize#newTestDate()

Project: humanize
Source File: TestHumanize.java
View license
private Date newTestDate(int day, int month, int year, int h, int m, int s) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DATE, day);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.HOUR_OF_DAY, h);
    cal.set(Calendar.MINUTE, m);
    cal.set(Calendar.SECOND, s);
    return cal.getTime();
}

72. TestICUHumanize#newTestDate()

Project: humanize
Source File: TestICUHumanize.java
View license
private Date newTestDate(int day, int month, int year, int h, int m, int s) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DATE, day);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.HOUR_OF_DAY, h);
    cal.set(Calendar.MINUTE, m);
    cal.set(Calendar.SECOND, s);
    return cal.getTime();
}

73. Olympiad#setNewOlympiadEnd()

Project: L2_GameServer_T0
Source File: Olympiad.java
View license
protected void setNewOlympiadEnd() {
    SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_STARTED);
    sm.addNumber(_currentCycle);
    Announcements.getInstance().announceToAll(sm);
    Calendar currentTime = Calendar.getInstance();
    currentTime.add(Calendar.MONTH, 1);
    currentTime.set(Calendar.DAY_OF_MONTH, 1);
    currentTime.set(Calendar.AM_PM, Calendar.AM);
    currentTime.set(Calendar.HOUR, 12);
    currentTime.set(Calendar.MINUTE, 0);
    currentTime.set(Calendar.SECOND, 0);
    _olympiadEnd = currentTime.getTimeInMillis();
    Calendar nextChange = Calendar.getInstance();
    _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
    _isOlympiadEnd = false;
}

74. Olympiad#setNewOlympiadEnd()

Project: L2_GameServer_CT1.5
Source File: Olympiad.java
View license
protected void setNewOlympiadEnd() {
    SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_STARTED);
    sm.addNumber(_currentCycle);
    Announcements.getInstance().announceToAll(sm);
    Calendar currentTime = Calendar.getInstance();
    currentTime.add(Calendar.MONTH, 1);
    currentTime.set(Calendar.DAY_OF_MONTH, 1);
    currentTime.set(Calendar.AM_PM, Calendar.AM);
    currentTime.set(Calendar.HOUR, 12);
    currentTime.set(Calendar.MINUTE, 0);
    currentTime.set(Calendar.SECOND, 0);
    _olympiadEnd = currentTime.getTimeInMillis();
    Calendar nextChange = Calendar.getInstance();
    _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
    _isOlympiadEnd = false;
}

75. Olympiad#setNewOlympiadEnd()

Project: L2GS
Source File: Olympiad.java
View license
protected void setNewOlympiadEnd() {
    SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_STARTED);
    sm.addNumber(_currentCycle);
    Announcements.getInstance().announceToAll(sm);
    Calendar currentTime = Calendar.getInstance();
    currentTime.add(Calendar.MONTH, 1);
    currentTime.set(Calendar.DAY_OF_MONTH, 1);
    currentTime.set(Calendar.AM_PM, Calendar.AM);
    currentTime.set(Calendar.HOUR, 12);
    currentTime.set(Calendar.MINUTE, 0);
    currentTime.set(Calendar.SECOND, 0);
    _olympiadEnd = currentTime.getTimeInMillis();
    Calendar nextChange = Calendar.getInstance();
    _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
    _isOlympiadEnd = false;
}

76. DateTimeToCalendarHelper#createCalendarFromLocalDateTime()

View license
/**
	 * 
	 * @param localDateTime
	 * @return
	 */
public static Calendar createCalendarFromLocalDateTime(LocalDateTime localDateTime, TimeZone timeZone, Locale locale) {
    if (localDateTime == null) {
        return null;
    }
    Calendar lCalendar = Calendar.getInstance(timeZone, locale);
    lCalendar.set(Calendar.YEAR, localDateTime.getYear());
    lCalendar.set(Calendar.MONTH, localDateTime.getMonth().getValue() - 1);
    lCalendar.set(Calendar.DATE, localDateTime.getDayOfMonth());
    lCalendar.set(Calendar.HOUR_OF_DAY, localDateTime.getHour());
    lCalendar.set(Calendar.MINUTE, localDateTime.getMinute());
    lCalendar.set(Calendar.SECOND, localDateTime.getSecond());
    lCalendar.set(Calendar.MILLISECOND, localDateTime.getNano() / 1000000);
    return lCalendar;
}

77. DateTimeToCalendarHelper#createCalendarFromLocalDate()

View license
/**
	 * 
	 * @param localDate
	 * @return
	 */
public static Calendar createCalendarFromLocalDate(LocalDate localDate, TimeZone timeZone, Locale locale) {
    if (localDate == null) {
        return null;
    }
    Calendar lCalendar = Calendar.getInstance(timeZone, locale);
    lCalendar.set(Calendar.YEAR, localDate.getYear());
    lCalendar.set(Calendar.MONTH, localDate.getMonth().getValue() - 1);
    lCalendar.set(Calendar.DATE, localDate.getDayOfMonth());
    lCalendar.set(Calendar.HOUR_OF_DAY, 0);
    lCalendar.set(Calendar.MINUTE, 0);
    lCalendar.set(Calendar.SECOND, 0);
    lCalendar.set(Calendar.MILLISECOND, 0);
    return lCalendar;
}

78. CalendarPickerControlSkin#deriveDisplayedCalendar()

View license
// ==================================================================================================================
// PROPERTIES
/**
	 * This skin has the displayed date always pointing to the first of the month
	 * @param displayedCalendar
	 * @return
	 */
private Calendar deriveDisplayedCalendar(Calendar displayedCalendar) {
    // always the 1st of the month, without time
    Calendar lCalendar = Calendar.getInstance(getSkinnable().getLocale());
    lCalendar.set(Calendar.DATE, 1);
    lCalendar.set(Calendar.MONTH, displayedCalendar.get(Calendar.MONTH));
    lCalendar.set(Calendar.YEAR, displayedCalendar.get(Calendar.YEAR));
    lCalendar.set(Calendar.HOUR_OF_DAY, 0);
    lCalendar.set(Calendar.MINUTE, 0);
    lCalendar.set(Calendar.SECOND, 0);
    lCalendar.set(Calendar.MILLISECOND, 0);
    return lCalendar;
}

79. DateComparator#testLongDate()

View license
public static void testLongDate(int year, int month, int day, int hour, int min, int sec, String timeZone, Date expectedDate) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, min);
    c.set(Calendar.SECOND, sec);
    c.set(Calendar.MILLISECOND, 0);
    if (timeZone.length() > 0) {
        c.setTimeZone(TimeZone.getTimeZone(timeZone));
    }
    Date actualDate = c.getTime();
    Assert.assertEquals("Checking date", actualDate, expectedDate);
}

80. DateTimeConstantTest#test()

Project: querydsl
Source File: DateTimeConstantTest.java
View license
@Test
public void test() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.MONTH, 0);
    cal.set(Calendar.YEAR, 2000);
    cal.set(Calendar.HOUR_OF_DAY, 13);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 12);
    cal.set(Calendar.MILLISECOND, 3);
    DateTimeExpression<Date> date = DateTimeConstant.create(cal.getTime());
    assertEquals("1", date.dayOfMonth().toString());
    assertEquals("1", date.month().toString());
    assertEquals("2000", date.year().toString());
    assertEquals("7", date.dayOfWeek().toString());
    assertEquals("1", date.dayOfYear().toString());
    assertEquals("13", date.hour().toString());
    assertEquals("30", date.minute().toString());
    assertEquals("12", date.second().toString());
    assertEquals("3", date.milliSecond().toString());
}

81. IntervalTest#getStartCalendar()

Project: pgjdbc-ng
Source File: IntervalTest.java
View license
Calendar getStartCalendar() {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 2005);
    cal.set(Calendar.MONTH, 4);
    cal.set(Calendar.DAY_OF_MONTH, 29);
    cal.set(Calendar.HOUR_OF_DAY, 15);
    cal.set(Calendar.MINUTE, 35);
    cal.set(Calendar.SECOND, 42);
    cal.set(Calendar.MILLISECOND, 100);
    return cal;
}

82. TimestampToTime#simple()

Project: pgjdbc
Source File: TimestampToTime.java
View license
@Benchmark
public long simple() {
    long millis = ts.getTime() + 10;
    ts.setTime(millis);
    Calendar cal = cachedCalendar;
    cal.setTimeZone(timeZone);
    cal.setTimeInMillis(millis);
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(Calendar.YEAR, 1970);
    cal.set(Calendar.MONTH, 0);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    return cal.getTimeInMillis();
}

83. TimestampToDate#simple()

Project: pgjdbc
Source File: TimestampToDate.java
View license
@Benchmark
public long simple() {
    long millis = ts.getTime() + 10;
    ts.setTime(millis);
    Calendar cal = cachedCalendar;
    cal.setTimeZone(timeZone);
    cal.setTimeInMillis(millis);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

84. ReadEventCommand#getTimestamp()

Project: openhab
Source File: ReadEventCommand.java
View license
/**
     * Returns date and time of the event.
     *
     * @return date and time of the event
     */
public Calendar getTimestamp() {
    Calendar c = Calendar.getInstance();
    int yearBase = c.get(Calendar.YEAR) / 4;
    int yearMarker = (response.getPayload()[0] >> 6) & 0x03;
    int minutes = ((response.getPayload()[2] & 0x0f) << 8) + (response.getPayload()[3] & 0xff);
    c.set(Calendar.YEAR, 4 * yearBase + yearMarker);
    c.set(Calendar.MONTH, ((response.getPayload()[2] >> 4) & 0x0f) - 1);
    c.set(Calendar.DAY_OF_MONTH, response.getPayload()[1] & 0x1f);
    c.set(Calendar.HOUR_OF_DAY, minutes / 60);
    c.set(Calendar.MINUTE, minutes % 60);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c;
}

85. IntegraStatusCommand#getIntegraTime()

Project: openhab
Source File: IntegraStatusCommand.java
View license
/**
     * @return date and time
     */
public Calendar getIntegraTime() {
    // parse current date and time
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, bcdToInt(response.getPayload(), 0, 2));
    c.set(Calendar.MONTH, bcdToInt(response.getPayload(), 2, 1) - 1);
    c.set(Calendar.DAY_OF_MONTH, bcdToInt(response.getPayload(), 3, 1));
    c.set(Calendar.HOUR_OF_DAY, bcdToInt(response.getPayload(), 4, 1));
    c.set(Calendar.MINUTE, bcdToInt(response.getPayload(), 5, 1));
    c.set(Calendar.SECOND, bcdToInt(response.getPayload(), 6, 1));
    c.set(Calendar.MILLISECOND, 0);
    return c;
}

86. Times#getWeekEndTime()

Project: symphony
Source File: Times.java
View license
/**
     * Gets the week end time with the specified time.
     *
     * @param time the specified time
     * @return week end time
     */
public static long getWeekEndTime(final long time) {
    final Calendar end = Calendar.getInstance();
    end.setFirstDayOfWeek(Calendar.MONDAY);
    end.setTimeInMillis(time);
    end.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    end.set(Calendar.HOUR, 23);
    end.set(Calendar.MINUTE, 59);
    end.set(Calendar.SECOND, 59);
    end.set(Calendar.MILLISECOND, 999);
    return end.getTime().getTime();
}

87. Times#getWeekStartTime()

Project: symphony
Source File: Times.java
View license
/**
     * Gets the week start time with the specified time.
     *
     * @param time the specified time
     * @return week start time
     */
public static long getWeekStartTime(final long time) {
    final Calendar start = Calendar.getInstance();
    start.setFirstDayOfWeek(Calendar.MONDAY);
    start.setTimeInMillis(time);
    start.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    start.set(Calendar.HOUR, 0);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.MILLISECOND, 0);
    return start.getTime().getTime();
}

88. PodamTestUtils#getMyBirthday()

Project: mohit
Source File: PodamTestUtils.java
View license
// ------------------->> Public methods
/**
	 * Returns a Calendar with my birthday date.
	 * 
	 * @return A Calendar with my birthday date.
	 */
public static Calendar getMyBirthday() {
    Calendar myBirthday = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    myBirthday.set(Calendar.DAY_OF_MONTH, 20);
    myBirthday.set(Calendar.MONTH, 5);
    myBirthday.set(Calendar.YEAR, 1972);
    myBirthday.set(Calendar.HOUR_OF_DAY, 2);
    myBirthday.set(Calendar.MINUTE, 0);
    myBirthday.set(Calendar.SECOND, 0);
    myBirthday.set(Calendar.MILLISECOND, 0);
    return myBirthday;
}

89. IntervalTest#getStartCalendar()

Project: pgjdbc
Source File: IntervalTest.java
View license
Calendar getStartCalendar() {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 2005);
    cal.set(Calendar.MONTH, 4);
    cal.set(Calendar.DAY_OF_MONTH, 29);
    cal.set(Calendar.HOUR_OF_DAY, 15);
    cal.set(Calendar.MINUTE, 35);
    cal.set(Calendar.SECOND, 42);
    cal.set(Calendar.MILLISECOND, 100);
    return cal;
}

90. Const#removeTimeFromDate()

Project: pentaho-kettle
Source File: Const.java
View license
/**
   * Remove time from a date.
   *
   * @return a date without hour.
   */
public static Date removeTimeFromDate(Date input) {
    if (input == null) {
        return null;
    }
    // Get an instance of the Calendar.
    Calendar calendar = Calendar.getInstance();
    // Make sure the calendar will not perform automatic correction.
    calendar.setLenient(false);
    // Set the time of the calendar to the given date.
    calendar.setTime(input);
    // Remove the hours, minutes, seconds and milliseconds.
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    // Return the date again.
    return calendar.getTime();
}

91. PodamTestUtils#getMyBirthday()

View license
// ------------------->> Public methods
/**
	 * Returns a Calendar with my birthday date.
	 * 
	 * @return A Calendar with my birthday date.
	 */
public static Calendar getMyBirthday() {
    Calendar myBirthday = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    myBirthday.set(Calendar.DAY_OF_MONTH, 20);
    myBirthday.set(Calendar.MONTH, 5);
    myBirthday.set(Calendar.YEAR, 1972);
    myBirthday.set(Calendar.HOUR_OF_DAY, 2);
    myBirthday.set(Calendar.MINUTE, 0);
    myBirthday.set(Calendar.SECOND, 0);
    myBirthday.set(Calendar.MILLISECOND, 0);
    return myBirthday;
}

92. PredicatesTest#t()

Project: asakusafw
Source File: PredicatesTest.java
View license
private Calendar t(int y, int mo, int d, int h, int mi, int s) {
    Calendar c = Calendar.getInstance();
    c.clear();
    c.set(Calendar.YEAR, y);
    c.set(Calendar.MONTH, mo - 1);
    c.set(Calendar.DATE, d);
    c.set(Calendar.HOUR_OF_DAY, h);
    c.set(Calendar.MINUTE, mi);
    c.set(Calendar.SECOND, s);
    return c;
}

93. JsonObjectDriver#datetimeProperty()

Project: asakusafw
Source File: JsonObjectDriver.java
View license
@Override
public void datetimeProperty(PropertyName name, JsonObject context) throws IOException {
    JsonElement prop = property(context, name);
    if (prop == null) {
        return;
    }
    String string = prop.getAsString();
    Matcher matcher = DATETIME.matcher(string);
    if (matcher.matches() == false) {
        throw new IOException(MessageFormat.format(//$NON-NLS-1$
        Messages.getString("JsonObjectDriver.errorInvalidDateTimeFormat"), name, string, //$NON-NLS-1$
        "yyyy-mm-dd hh:mm:ss"));
    }
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, Integer.parseInt(matcher.group(1)));
    calendar.set(Calendar.MONTH, Integer.parseInt(matcher.group(2)) - 1);
    calendar.set(Calendar.DATE, Integer.parseInt(matcher.group(3)));
    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(4)));
    calendar.set(Calendar.MINUTE, Integer.parseInt(matcher.group(5)));
    calendar.set(Calendar.SECOND, Integer.parseInt(matcher.group(6)));
    builder.add(name, calendar);
}

94. TimeValidatorTest#createTime()

View license
/**
     * Create a calendar instance for a specified time zone, date and time.
     * 
     * @param zone The time zone
     * @param time the time in HH:mm:ss format
     * @param millisecond the milliseconds
     * @return the new Calendar instance.
     */
protected static Calendar createTime(TimeZone zone, int time, int millisecond) {
    Calendar calendar = zone == null ? Calendar.getInstance() : Calendar.getInstance(zone);
    int hour = ((time / 10000) * 10000);
    int min = ((time / 100) * 100) - hour;
    int sec = time - (hour + min);
    calendar.set(Calendar.YEAR, 1970);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DATE, 1);
    calendar.set(Calendar.HOUR_OF_DAY, (hour / 10000));
    calendar.set(Calendar.MINUTE, (min / 100));
    calendar.set(Calendar.SECOND, sec);
    calendar.set(Calendar.MILLISECOND, millisecond);
    return calendar;
}

95. AbstractCalendarValidatorTest#createCalendar()

View license
/**
     * Create a calendar instance for a specified time zone, date and time.
     * 
     * @param zone The time zone
     * @param date The date in yyyyMMdd format
     * @param time the time in HH:mm:ss format
     * @return the new Calendar instance.
     */
protected static Calendar createCalendar(TimeZone zone, int date, int time) {
    Calendar calendar = zone == null ? Calendar.getInstance() : Calendar.getInstance(zone);
    int year = ((date / 10000) * 10000);
    int mth = ((date / 100) * 100) - year;
    int day = date - (year + mth);
    int hour = ((time / 10000) * 10000);
    int min = ((time / 100) * 100) - hour;
    int sec = time - (hour + min);
    calendar.set(Calendar.YEAR, (year / 10000));
    calendar.set(Calendar.MONTH, ((mth / 100) - 1));
    calendar.set(Calendar.DATE, day);
    calendar.set(Calendar.HOUR_OF_DAY, (hour / 10000));
    calendar.set(Calendar.MINUTE, (min / 100));
    calendar.set(Calendar.SECOND, sec);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}

96. NetwareFTPEntryParserTest#testParseFieldsOnDirectory()

View license
@Override
public void testParseFieldsOnDirectory() throws Exception {
    String reply = "d [-W---F--] testUser                        512 Apr 13 23:12 testFile";
    FTPFile f = getParser().parseFTPEntry(reply);
    assertNotNull("Could not parse file", f);
    assertEquals("testFile", f.getName());
    assertEquals(512L, f.getSize());
    assertEquals("testUser", f.getUser());
    assertTrue("Directory flag is not set!", f.isDirectory());
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, 3);
    cal.set(Calendar.DAY_OF_MONTH, 13);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 12);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.YEAR, f.getTimestamp().get(Calendar.YEAR));
    assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
}

97. Timestamp#dateStrToCalendar()

Project: openwayback
Source File: Timestamp.java
View license
/**
	 * @param dateStr up to 14 digit String representing date
	 * @return a GMT Calendar object, set to the date represented
	 */
public static Calendar dateStrToCalendar(final String dateStr) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    String paddedDateStr = padStartDateStr(dateStr);
    int iYear = Integer.parseInt(paddedDateStr.substring(0, 4));
    int iMonth = Integer.parseInt(paddedDateStr.substring(4, 6));
    int iDay = Integer.parseInt(paddedDateStr.substring(6, 8));
    int iHour = Integer.parseInt(paddedDateStr.substring(8, 10));
    int iMinute = Integer.parseInt(paddedDateStr.substring(10, 12));
    int iSecond = Integer.parseInt(paddedDateStr.substring(12, 14));
    cal.set(Calendar.YEAR, iYear);
    cal.set(Calendar.MONTH, iMonth - 1);
    cal.set(Calendar.DAY_OF_MONTH, iDay);
    cal.set(Calendar.HOUR_OF_DAY, iHour);
    cal.set(Calendar.MINUTE, iMinute);
    cal.set(Calendar.SECOND, iSecond);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
}

98. DateTimeUtil#convertToShortMonth()

Project: YiBo
Source File: DateTimeUtil.java
View license
public static Date convertToShortMonth(Date date) {
    if (date == null) {
        return null;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}

99. HuobiAdapters#adaptTime()

Project: XChange
Source File: HuobiAdapters.java
View license
private static Date adaptTime(String time) {
    String[] hms = time.split(":");
    TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai");
    Calendar now = Calendar.getInstance();
    Calendar timestamp = Calendar.getInstance(timeZone);
    timestamp.setTime(now.getTime());
    timestamp.set(Calendar.HOUR, Integer.parseInt(hms[0]));
    timestamp.set(Calendar.MINUTE, Integer.parseInt(hms[1]));
    timestamp.set(Calendar.SECOND, Integer.parseInt(hms[2]));
    timestamp.set(Calendar.MILLISECOND, 0);
    if (timestamp.getTimeInMillis() > now.getTimeInMillis() + FIVE_MINUTES) {
        timestamp.add(Calendar.DAY_OF_MONTH, -1);
    }
    return timestamp.getTime();
}

100. DateTimeUtil#convertToShortWeek()

Project: YiBo
Source File: DateTimeUtil.java
View license
public static Date convertToShortWeek(Date date) {
    if (date == null) {
        return null;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}