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. 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);
}

5. 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());
}

6. 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());
}

7. 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);
}

8. 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);
}

9. 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);
}

10. ZonelessDatetime#getJdbcTimestamp()

Project: calcite
Source File: ZonelessDatetime.java
View license
/**
   * Gets the value of this datetime as a milliseconds value for
   * [email protected] 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();
}

11. 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());
}

12. 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;
}

13. 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());
}

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. 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);
    }
}

16. 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();
}

17. 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();
}

18. 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();
}

19. 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();
}

20. 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));
}

21. 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();
}

22. 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());
}

23. 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();
}

24. 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();
}

25. 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();
}

26. 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());
}

27. 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();
}

28. 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();
}

29. 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;
}

30. 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));
}

31. 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 [email protected] calendar} is [email protected] 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();
}

32. 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());
}

33. 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();
}

34. 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));
}

35. 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));
}

36. 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;
}

37. 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));
}

38. 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));
}

39. ExcelSheetRuleProviderTest#value_now()

View license
/**
     * [email protected] 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()));
}

40. 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;
}

41. 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);
}

42. 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();
}

43. 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);
}

44. 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>"));
}

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. 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);
}

47. 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();
}

48. 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();
}

49. 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());
}

50. 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();
}

51. 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());
}

52. 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 });
}

53. 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 });
}

54. 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 });
}

55. 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();
}

56. 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();
}

57. 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 [email protected] calendar} is [email protected] 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;
}

58. 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));
}

59. 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;
}

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. CalendarTest#test_getTimeInMillis()

Project: teavm
Source File: CalendarTest.java
View license
/**
     * @tests java.util.Calendar#clone()
     */
[email protected]
//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());
}

65. 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();
}

66. MonthlyExpiresHeaderFilterTest#testAdjustExpiresPastDay()

View license
@Test
public void testAdjustExpiresPastDay() throws Exception {
    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());
    expected.add(Calendar.DAY_OF_MONTH, -3);
    expected.add(Calendar.MONTH, 1);
    actual.set(Calendar.DAY_OF_MONTH, 15);
    int month = expected.get(Calendar.MONTH);
    properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, expected.get(Calendar.DAY_OF_MONTH));
    filter.doActivate(componentContext);
    filter.adjustExpires(actual);
    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(month, actual.get(Calendar.MONTH));
}

67. MonthlyExpiresHeaderFilterTest#testAdjustExpiresLastDayPast()

View license
@Test
public void testAdjustExpiresLastDayPast() throws Exception {
    Calendar actual = Calendar.getInstance();
    actual.add(Calendar.MONTH, -1);
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    actual.set(Calendar.DAY_OF_MONTH, actual.getActualMaximum(Calendar.DAY_OF_MONTH));
    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());
    expected.add(Calendar.MONTH, 1);
    int month = expected.get(Calendar.MONTH);
    properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, "LAST");
    filter.doActivate(componentContext);
    filter.adjustExpires(actual);
    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(month, actual.get(Calendar.MONTH));
}

68. DateUtils#createDate()

View license
public static Date createDate(int year, int monthOfYear, int dayOfMonth) {
    Calendar c = Calendar.getInstance();
    // set the calendar to start of today
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    // setup the date
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, monthOfYear);
    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    // and get that as a Date
    Date resultDate = c.getTime();
    return resultDate;
}

69. 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);
}

70. 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;
}

71. Duration#getAsCalendar()

Project: axis1-java
Source File: Duration.java
View license
/**
     * Returns duration as a calendar.  Due to the way a Calendar class works,
     * the values for particular fields may not be the same as obtained through
     * getter methods.  For example, if a Duration's object getMonths
     * returns 20, a similar call on a Calendar object will return 1 year and
     * 8 months.
     *
     * @param startTime Calendar
     * @return Calendar
     */
public Calendar getAsCalendar(Calendar startTime) {
    Calendar ret = (Calendar) startTime.clone();
    ret.set(Calendar.YEAR, years);
    ret.set(Calendar.MONTH, months);
    ret.set(Calendar.DATE, days);
    ret.set(Calendar.HOUR, hours);
    ret.set(Calendar.MINUTE, minutes);
    ret.set(Calendar.SECOND, (int) seconds);
    ret.set(Calendar.MILLISECOND, (int) (seconds * 100 - Math.round(seconds) * 100));
    return ret;
}

72. Duration#getAsCalendar()

Project: axis2-java
Source File: Duration.java
View license
/**
     * Returns duration as a calendar.  Due to the way a Calendar class works, the values for
     * particular fields may not be the same as obtained through getter methods.  For example, if a
     * Duration's object getMonths returns 20, a similar call on a Calendar object will return 1
     * year and 8 months.
     *
     * @param startTime Calendar
     * @return Calendar
     */
public Calendar getAsCalendar(Calendar startTime) {
    Calendar ret = (Calendar) startTime.clone();
    ret.set(Calendar.YEAR, years);
    ret.set(Calendar.MONTH, months);
    ret.set(Calendar.DATE, days);
    ret.set(Calendar.HOUR, hours);
    ret.set(Calendar.MINUTE, minutes);
    ret.set(Calendar.SECOND, (int) seconds);
    ret.set(Calendar.MILLISECOND, (int) (seconds * 100 - Math.round(seconds) * 100));
    return ret;
}

73. DateTest#main()

Project: bboss
Source File: DateTest.java
View license
public static void main(String[] args) {
    Calendar gmtlocal = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
    gmtlocal.set(Calendar.YEAR, 2007);
    gmtlocal.set(Calendar.MONTH, 0);
    gmtlocal.set(Calendar.DAY_OF_MONTH, 1);
    gmtlocal.set(Calendar.HOUR_OF_DAY, 0);
    gmtlocal.set(Calendar.MINUTE, 0);
    Calendar gmt0 = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));
    gmt0.setTimeInMillis(gmtlocal.getTimeInMillis());
    System.out.println(gmt0.get(Calendar.YEAR));
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    sf.setTimeZone(TimeZone.getTimeZone("GMT+12"));
    System.out.println(sf.format(gmtlocal.getTime()));
    sf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    System.out.println(sf.format(gmtlocal.getTime()));
    sf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    System.out.println(sf.format(gmtlocal.getTime()));
}

74. HistoricIdentityLinkLogQueryTest#newYearMorning()

View license
public Date newYearMorning(int minutes) {
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.YEAR, 2016);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date morning = calendar.getTime();
    return morning;
}

75. HistoricIdentityLinkLogQueryTest#newYearNoon()

View license
public Date newYearNoon(int minutes) {
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.YEAR, 2016);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date morning = calendar.getTime();
    return morning;
}

76. HistoricIdentityLinkLogQueryTest#newYearEvening()

View license
public Date newYearEvening() {
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.YEAR, 2016);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 21);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date morning = calendar.getTime();
    return morning;
}

77. ZipUtil#dosToJavaTime()

Project: commons-compress
Source File: ZipUtil.java
View license
/**
     * Converts DOS time to Java time (number of milliseconds since
     * epoch).
     * @param dosTime time to convert
     * @return converted time
     */
public static long dosToJavaTime(final long dosTime) {
    final Calendar cal = Calendar.getInstance();
    // CheckStyle:MagicNumberCheck OFF - no point
    cal.set(Calendar.YEAR, (int) ((dosTime >> 25) & 0x7f) + 1980);
    cal.set(Calendar.MONTH, (int) ((dosTime >> 21) & 0x0f) - 1);
    cal.set(Calendar.DATE, (int) (dosTime >> 16) & 0x1f);
    cal.set(Calendar.HOUR_OF_DAY, (int) (dosTime >> 11) & 0x1f);
    cal.set(Calendar.MINUTE, (int) (dosTime >> 5) & 0x3f);
    cal.set(Calendar.SECOND, (int) (dosTime << 1) & 0x3e);
    cal.set(Calendar.MILLISECOND, 0);
    // CheckStyle:MagicNumberCheck ON
    return cal.getTime().getTime();
}

78. 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)));
}

79. 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()));
}

80. 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;
}

81. 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;
}

82. 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;
}

83. 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();
}

84. 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();
}

85. 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;
}

86. 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();
}

87. 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();
}

88. 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());
}

89. 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;
}

90. 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;
}

91. 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;
}

92. 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;
}

93. 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;
}

94. 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;
}

95. CachedDateFormatTest#test9()

Project: log4j
Source File: CachedDateFormatTest.java
View license
/**
   * Test of caching when less than three millisecond digits are specified.
   */
public void test9() {
    // (Note: 'Z' is JDK 1.4, using 'z' instead.)
    DateFormat baseFormat = new SimpleDateFormat("yyyy-MMMM-dd HH:mm:ss,SS z", Locale.US);
    DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
    TimeZone cet = TimeZone.getTimeZone("GMT+1");
    cachedFormat.setTimeZone(cet);
    Calendar c = Calendar.getInstance();
    c.set(2004, Calendar.DECEMBER, 12, 20, 0);
    c.set(Calendar.SECOND, 37);
    c.set(Calendar.MILLISECOND, 23);
    c.setTimeZone(cet);
    String s = cachedFormat.format(c.getTime());
    assertEquals("2004-December-12 20:00:37,23 GMT+01:00", s);
    c.set(2005, Calendar.JANUARY, 1, 0, 0);
    c.set(Calendar.SECOND, 13);
    c.set(Calendar.MILLISECOND, 905);
    s = cachedFormat.format(c.getTime());
    assertEquals("2005-January-01 00:00:13,905 GMT+01:00", s);
}

96. CachedDateFormatTest#test10()

Project: log4j
Source File: CachedDateFormatTest.java
View license
/**
   * Test when millisecond position moves but length remains constant.
   */
public void test10() {
    DateFormat baseFormat = new SimpleDateFormat("MMMM SSS EEEEEE", Locale.US);
    DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
    TimeZone cet = TimeZone.getTimeZone("GMT+1");
    cachedFormat.setTimeZone(cet);
    Calendar c = Calendar.getInstance();
    c.set(2004, Calendar.OCTOBER, 5, 20, 0);
    c.set(Calendar.SECOND, 37);
    c.set(Calendar.MILLISECOND, 23);
    c.setTimeZone(cet);
    String s = cachedFormat.format(c.getTime());
    assertEquals("October 023 Tuesday", s);
    c.set(2004, Calendar.NOVEMBER, 1, 0, 0);
    c.set(Calendar.MILLISECOND, 23);
    s = cachedFormat.format(c.getTime());
    assertEquals("November 023 Monday", s);
    c.set(Calendar.MILLISECOND, 984);
    s = cachedFormat.format(c.getTime());
    assertEquals("November 984 Monday", s);
}

97. 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;
}

98. 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;
}

99. 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;
}

100. MonthStatistics#newAggregate()

View license
@Override
public Aggregate newAggregate(long startTime) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(startTime);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    startTime = cal.getTimeInMillis();
    cal.add(Calendar.MONTH, 1);
    return new Aggregate(startTime, cal.getTimeInMillis());
}