List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:com.ecofactor.qa.automation.consumerapi.DRAPI_Test.java
/** * Test create Dr event for an expired event. *///from w w w .j a v a2 s . c om @Test(groups = { Groups.SANITY1 }, dataProvider = "eventExpired", dataProviderClass = DRAPIDataProvider.class, priority = 13) public void eventExpired(final String Url, final String programId, final String eventId, final String targetType, final String jSon, final String endtime) { long timeStamp = System.currentTimeMillis(); String createUrl = Url; createUrl = createUrl.replaceFirst("<program_id>", programId) .replaceFirst("<event_id>", eventId + timeStamp).replaceFirst("<target_type>", targetType) .replaceFirst("<target_all>", "true"); String json = jSon; json = json .replaceFirst("<start_time>", Long.toString(DateUtil.subtractFromUTCMilliSeconds(Calendar.MINUTE, 5))) .replaceFirst("<end_time>", Long.toString(DateUtil.addToUTCMilliSeconds(Calendar.HOUR, 2))); setLogString("URL Values of the API \n" + createUrl + "\n" + json, true); final HttpResponse response = HTTPSClient.postResponse(createUrl, json, HTTPSClient.getPKCSKeyHttpClient("ecofactorcorp.p12", "ecofactor")); Assert.assertTrue(response.getStatusLine().getStatusCode() == 400, "Error status: " + response.getStatusLine()); final String result = HTTPSClient.getResultString(response.getEntity()); setLogString("response :'" + result + " " + "Cannot create an event for the expired event " + "'", true); }
From source file:com.appeligo.alerts.KeywordAlertChecker.java
/** * @param timeZone the user's timezone// w w w. ja va 2s . co m * @param startOfDay We're using the value of earliestSmsTime (user account setting) as a starting point, * so anything before this time is credited to the previous day) * @return 12am (midnight) using system time (not user time) because "Date" objects stored in SQL * come back in system time. */ private Date calculateDay(TimeZone timeZone, Time startOfDay) { Calendar cal = Calendar.getInstance(timeZone); Calendar start = Calendar.getInstance(); start.setTimeInMillis(startOfDay.getTime()); cal.add(Calendar.HOUR_OF_DAY, 0 - start.get(Calendar.HOUR_OF_DAY)); cal.add(Calendar.MINUTE, 0 - start.get(Calendar.MINUTE)); cal.add(Calendar.SECOND, 0 - start.get(Calendar.SECOND)); cal.clear(Calendar.MILLISECOND); cal.clear(Calendar.SECOND); cal.clear(Calendar.MINUTE); cal.clear(Calendar.HOUR_OF_DAY); cal.clear(Calendar.HOUR); cal.clear(Calendar.AM_PM); TimeZone systemTimeZone = TimeZone.getDefault(); long now = System.currentTimeMillis(); long difference = systemTimeZone.getOffset(now) - timeZone.getOffset(now); return new Date(cal.getTimeInMillis() - difference); }
From source file:org.hdiv.web.servlet.tags.form.CheckboxTagTests.java
private Date getDate() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 10);//from w w w .j a va 2 s . co m cal.set(Calendar.MONTH, 10); cal.set(Calendar.DATE, 10); cal.set(Calendar.HOUR, 10); cal.set(Calendar.MINUTE, 10); cal.set(Calendar.SECOND, 10); return cal.getTime(); }
From source file:net.seratch.taskun.util.CalendarUtil.java
public void test_getCalendar_A$int$int$int$int$int$int() throws Exception { Calendar actual = CalendarUtil.getCalendar(2000, 2, 3, 4, 5, 6); assertTrue(2000 == actual.get(Calendar.YEAR)); assertTrue(1 == actual.get(Calendar.MONTH)); assertTrue(3 == actual.get(Calendar.DATE)); assertTrue(4 == actual.get(Calendar.HOUR)); assertTrue(5 == actual.get(Calendar.MINUTE)); assertTrue(6 == actual.get(Calendar.SECOND)); }//from w ww . j a v a 2 s . co m
From source file:adalid.commons.util.TimeUtils.java
public static Time addTime(java.util.Date date, int addend, char unit) { if (date == null) { return null; }/*from w ww . j a v a 2 s . c o m*/ Calendar c = newTimeCalendar(date); if (addend != 0) { switch (unit) { case 'h': c.add(Calendar.HOUR, addend); break; case 'm': c.add(Calendar.MINUTE, addend); break; case 's': c.add(Calendar.SECOND, addend); break; default: break; } } return new Time(c.getTimeInMillis()); }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
public static long[] parseTimePeriod(String timeperiod) { if (null == timeperiod) timeperiod = "last60minutes"; Date fromDate = null;/*from w w w . j a va2 s . c o m*/ Date toDate = null; long dataPoints = 60; Calendar cal = Calendar.getInstance(); Date now = cal.getTime(); // Reset the day fields so we're at the beginning of the day. cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // Compute "this week" by resetting the day of the week to the first day of the week cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); Date thisWeekStart = cal.getTime(); Date thisWeekEnd = now; // Compute last week - start with the end boundary which is 1 millisecond before the start of this week cal.add(Calendar.MILLISECOND, -1); Date lastWeekEnd = cal.getTime(); // Add that millisecond back, subtract 7 days for the start boundary of "last week" cal.add(Calendar.MILLISECOND, 1); cal.add(Calendar.DAY_OF_YEAR, -7); Date lastWeekStart = cal.getTime(); // Reset the time cal.setTime(now); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // Reset to the 1st day of the month, make the the start boundary for "this month" cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DAY_OF_MONTH)); Date thisMonthStart = cal.getTime(); Date thisMonthEnd = now; // Compute last month cal.add(Calendar.MILLISECOND, -1); Date lastMonthEnd = cal.getTime(); cal.add(Calendar.MILLISECOND, 1); cal.add(Calendar.MONTH, -1); Date lastMonthStart = cal.getTime(); // Compute last 3 months cal.setTime(now); cal.add(Calendar.MONTH, -2); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date last3MonthsStart = cal.getTime(); Date last3MonthsEnd = now; // Compute last 7 days: cal.setTime(now); cal.add(Calendar.DAY_OF_YEAR, -6); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date last7DaysStart = cal.getTime(); Date last7DaysEnd = now; // Compute last 60 minutes; cal.setTime(now); cal.add(Calendar.MINUTE, -60); Date last60MinutesStart = cal.getTime(); Date last60MinutesEnd = now; // Compute last 24 hours; cal.setTime(now); cal.add(Calendar.HOUR, -23); Date last24HoursStart = cal.getTime(); Date last24HoursEnd = now; // Done, reset the cal internal date to now cal.setTime(now); if ("thisweek".equals(timeperiod)) { fromDate = thisWeekStart; toDate = thisWeekEnd; dataPoints = 7; } else if ("last7days".equals(timeperiod)) { fromDate = last7DaysStart; toDate = last7DaysEnd; dataPoints = 7; } else if ("lastweek".equals(timeperiod)) { fromDate = lastWeekStart; toDate = lastWeekEnd; dataPoints = 7; } else if ("thismonth".equals(timeperiod)) { fromDate = thisMonthStart; toDate = thisMonthEnd; dataPoints = 30; } else if ("lastmonth".equals(timeperiod)) { fromDate = lastMonthStart; toDate = lastMonthEnd; dataPoints = 30; } else if ("last3months".equals(timeperiod)) { fromDate = last3MonthsStart; toDate = last3MonthsEnd; dataPoints = (long) Math.ceil((toDate.getTime() - fromDate.getTime()) / WEEK); } else if ("last60minutes".equals(timeperiod)) { fromDate = last60MinutesStart; toDate = last60MinutesEnd; dataPoints = 60; } else if ("last24hours".equals(timeperiod)) { fromDate = last24HoursStart; toDate = last24HoursEnd; dataPoints = 48; } else { String[] dates = timeperiod.split("to"); if (dates.length > 0) { DateFormat formDateFormatter = new SimpleDateFormat("MM/dd/yy"); String fromDateParam = dates[0]; String toDateParam = dates[1]; if (fromDateParam != null) { try { fromDate = formDateFormatter.parse(fromDateParam); } catch (Exception e) { // ignore formatting exception } } if (toDateParam != null) { try { toDate = formDateFormatter.parse(toDateParam); // Make this date be the end of the day (so it's the day *inclusive*, not *exclusive*) Calendar adjusted = Calendar.getInstance(); adjusted.setTime(toDate); adjusted.set(Calendar.HOUR_OF_DAY, 23); adjusted.set(Calendar.MINUTE, 59); adjusted.set(Calendar.SECOND, 59); adjusted.set(Calendar.MILLISECOND, 999); toDate = adjusted.getTime(); } catch (Exception e) { // ignore formatting exception } } dataPoints = discoverDataPoints(fromDate, toDate); } } // default to last 60 minutes if (null == fromDate && null == toDate) { return new long[] { last60MinutesStart.getTime(), last60MinutesEnd.getTime(), dataPoints }; } else if (null == fromDate) { return new long[] { 0, toDate.getTime(), dataPoints }; } else if (null == toDate) { return new long[] { fromDate.getTime(), now.getTime(), dataPoints }; } else { return new long[] { fromDate.getTime(), toDate.getTime(), dataPoints }; } }
From source file:com.concursive.connect.web.modules.calendar.utils.CalendarView.java
/** * Returns the cell representing the first day of the month in the 42 cell * grid Creation date: (5/2/2000 2:51:35 AM) * * @param tmp Description of Parameter//w w w . j av a 2 s. com * @return int */ public int getStartCell(Calendar tmp) { Calendar beginOfMonth = Calendar.getInstance(locale); beginOfMonth.set(tmp.get(Calendar.YEAR), tmp.get(Calendar.MONTH), 0); beginOfMonth.set(Calendar.HOUR, 0); beginOfMonth.set(Calendar.MINUTE, 0); beginOfMonth.set(Calendar.SECOND, 0); beginOfMonth.set(Calendar.MILLISECOND, 0); int baseDay = beginOfMonth.get(Calendar.DAY_OF_WEEK) - tmp.getFirstDayOfWeek() + 1; if (baseDay < 1) { baseDay = 7 + baseDay; } return baseDay; }
From source file:org.apache.gobblin.service.modules.orchestration.AzkabanAjaxAPIClient.java
/*** * Generate a random scheduled time between specified execution time window in the Azkaban compatible format * which is: hh,mm,a,z Eg. ScheduleTime=12,00,PM,PDT * * @param windowStartHour Window start hour in 24 hr (HH) format (inclusive) * @param windowEndHour Window end hour in 24 hr (HH) format (exclusive) * @param delayMinutes If current time is within window, then additional delay for bootstrapping if desired * @return Scheduled time string of the format hh,mm,a,z */// w ww . j ava2s .c om @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DMI_RANDOM_USED_ONLY_ONCE", justification = "As expected for randomization") public static String getScheduledTimeInAzkabanFormat(int windowStartHour, int windowEndHour, int delayMinutes) { // Validate if (windowStartHour < 0 || windowEndHour > 23 || windowStartHour >= windowEndHour) { throw new IllegalArgumentException( "Window start should be less than window end, and both should be between " + "0 and 23"); } if (delayMinutes < 0 || delayMinutes > 59) { throw new IllegalArgumentException("Delay in minutes should be between 0 and 59 (inclusive)"); } // Setup window Calendar windowStartTime = Calendar.getInstance(); windowStartTime.set(Calendar.HOUR_OF_DAY, windowStartHour); windowStartTime.set(Calendar.MINUTE, 0); windowStartTime.set(Calendar.SECOND, 0); Calendar windowEndTime = Calendar.getInstance(); windowEndTime.set(Calendar.HOUR_OF_DAY, windowEndHour); windowEndTime.set(Calendar.MINUTE, 0); windowEndTime.set(Calendar.SECOND, 0); // Check if current time is between windowStartTime and windowEndTime, then let the execution happen // after delayMinutes minutes Calendar now = Calendar.getInstance(); if (now.after(windowStartTime) && now.before(windowEndTime)) { // Azkaban takes a few seconds / a minute to bootstrap, // so extra few minutes get the first execution to run instantly now.add(Calendar.MINUTE, delayMinutes); return new SimpleDateFormat("hh,mm,a,z").format(now.getTime()); } // Current time is not between windowStartTime and windowEndTime, so get random execution time for next day int allowedSchedulingWindow = (int) ((windowEndTime.getTimeInMillis() - windowStartTime.getTimeInMillis()) / MILLISECONDS_IN_HOUR); int randomHourInWindow = new Random(System.currentTimeMillis()).nextInt(allowedSchedulingWindow); int randomMinute = new Random(System.currentTimeMillis()).nextInt(60); windowStartTime.add(Calendar.HOUR, randomHourInWindow); windowStartTime.set(Calendar.MINUTE, randomMinute); return new SimpleDateFormat("hh,mm,a,z").format(windowStartTime.getTime()); }
From source file:adalid.commons.util.TimeUtils.java
public static Timestamp addTimestamp(java.util.Date date, int addend, char unit) { if (date == null) { return null; }//from www . j av a2 s. c om Calendar c = newCalendar(date); if (addend != 0) { switch (unit) { case 'Y': c.add(Calendar.YEAR, addend); break; case 'M': c.add(Calendar.MONTH, addend); break; case 'D': c.add(Calendar.DAY_OF_MONTH, addend); break; case 'h': c.add(Calendar.HOUR, addend); break; case 'm': c.add(Calendar.MINUTE, addend); break; case 's': c.add(Calendar.SECOND, addend); break; default: break; } } return new Timestamp(c.getTimeInMillis()); }
From source file:com.concursive.connect.web.modules.calendar.utils.CalendarView.java
/** * Gets the calendarStartDate attribute of the CalendarView object * * @param source Description of the Parameter * @return The calendarStartDate value//from w w w .jav a 2 s . c o m */ public String getCalendarStartDate(String source) { int displayMonth = 0; int displayDay = 0; int displayYear = 0; if (source != null) { if (calendarInfo.isAgendaView() && source.equalsIgnoreCase("calendarDetails")) { Calendar today = Calendar.getInstance(timeZone, locale); today.set(Calendar.HOUR, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); displayMonth = today.get(Calendar.MONTH) + 1; displayDay = today.get(Calendar.DAY_OF_MONTH); displayYear = today.get(Calendar.YEAR); } else if (!source.equalsIgnoreCase("Calendar")) { if (calendarInfo.getCalendarView().equalsIgnoreCase("day")) { displayMonth = calendarInfo.getMonthSelected(); displayDay = calendarInfo.getDaySelected(); displayYear = calendarInfo.getYearSelected(); } else if (calendarInfo.getCalendarView().equalsIgnoreCase("week")) { displayMonth = calendarInfo.getStartMonthOfWeek(); displayDay = calendarInfo.getStartDayOfWeek(); displayYear = calendarInfo.getYearSelected(); } else { displayMonth = calPrev.get(Calendar.MONTH) + 1; displayDay = (this.getEndCell(calPrev) - this.getStartCell(cal) + 2 - this.getStartCell(calPrev)); displayYear = calPrev.get(Calendar.YEAR); } } else { displayMonth = calPrev.get(Calendar.MONTH) + 1; displayDay = (this.getEndCell(calPrev) - this.getStartCell(cal) + 2 - this.getStartCell(calPrev)); displayYear = calPrev.get(Calendar.YEAR); } } else { LOG.warn("getCalendarStartDate() source is NULL"); } LOG.debug("Start Day: " + displayMonth + "/" + displayDay + "/" + displayYear); return (displayMonth + "/" + displayDay + "/" + displayYear); }