Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

In this page you can find the example usage for java.util Calendar HOUR.

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:org.oscarehr.fax.admin.ManageFaxes.java

public ActionForward fetchFaxStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/*  w  w w  . j  a  va2s.  c om*/

    String statusStr = request.getParameter("status");
    String teamStr = request.getParameter("team");
    String dateBeginStr = request.getParameter("dateBegin");
    String dateEndStr = request.getParameter("dateEnd");
    String provider_no = request.getParameter("oscarUser");
    String demographic_no = request.getParameter("demographic_no");

    if (provider_no.equalsIgnoreCase("-1")) {
        provider_no = null;
    }

    if (statusStr.equalsIgnoreCase("-1")) {
        statusStr = null;
    }

    if (teamStr.equalsIgnoreCase("-1")) {
        teamStr = null;
    }

    if ("null".equalsIgnoreCase(demographic_no) || "".equals(demographic_no)) {
        demographic_no = null;
    }

    Calendar calendar = GregorianCalendar.getInstance();
    Date dateBegin = null, dateEnd = null;
    String datePattern[] = new String[] { "yyyy-MM-dd" };
    try {
        dateBegin = DateUtils.parseDate(dateBeginStr, datePattern);
        calendar.setTime(dateBegin);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        dateBegin = calendar.getTime();
    } catch (ParseException e) {
        dateBegin = null;
        MiscUtils.getLogger().error("UNPARSEABLE DATE " + dateBeginStr);
    }

    try {
        dateEnd = DateUtils.parseDate(dateEndStr, datePattern);
        calendar.setTime(dateEnd);
        calendar.set(Calendar.HOUR, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.MILLISECOND, 59);
        dateEnd = calendar.getTime();

    } catch (ParseException e) {
        dateEnd = null;
        MiscUtils.getLogger().error("UNPARSEABLE DATE " + dateEndStr);
    }

    FaxJobDao faxJobDao = SpringUtils.getBean(FaxJobDao.class);

    List<FaxJob> faxJobList = faxJobDao.getFaxStatusByDateDemographicProviderStatusTeam(demographic_no,
            provider_no, statusStr, teamStr, dateBegin, dateEnd);

    request.setAttribute("faxes", faxJobList);

    return mapping.findForward("faxstatus");
}

From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java

private void redrawPercentageBandwidthStats() {

    Cursor c = CursorUtils.setWaitCursor(uiComponent);
    try {/*from  www. j  ava 2s.c om*/

        int percentDataType = percentDataTypeComboBox.getSelectedIndex();

        percentageBandwidthSeries.clear();

        Set<CoalescedBandwidthStat> stats = getController().getTransferManager().getBandwidthStats();
        Calendar cal = Calendar.getInstance();
        boolean first = true;
        Date last = null;
        for (CoalescedBandwidthStat stat : stats) {
            Hour hour = new Hour(stat.getDate());
            if (first) {
                first = false;
                cal.setTime(stat.getDate());
            }
            if (stat.getInfo() == BandwidthLimiterInfo.WAN_INPUT && percentDataType == 0
                    || stat.getInfo() == BandwidthLimiterInfo.WAN_OUTPUT && percentDataType == 1
                    || stat.getInfo() == BandwidthLimiterInfo.LAN_INPUT && percentDataType == 2
                    || stat.getInfo() == BandwidthLimiterInfo.LAN_OUTPUT && percentDataType == 3) {
                percentageBandwidthSeries.add(hour, stat.getPercentageUsedBandwidth());
            }
            last = stat.getDate();
        }
        if (last != null) {
            while (cal.getTime().before(last)) {
                Hour hour = new Hour(cal.getTime());
                if (percentageBandwidthSeries.getDataItem(hour) == null) {
                    percentageBandwidthSeries.add(hour, 0.0);
                }
                cal.add(Calendar.HOUR, 1);
            }
        }
    } finally {
        CursorUtils.returnToOriginal(uiComponent, c);
    }
}

From source file:org.jfree.data.time.Week.java

/**
 * Returns the last millisecond of the week, evaluated using the supplied
 * calendar (which determines the time zone).
 *
 * @param calendar  the calendar (<code>null</code> not permitted).
 *
 * @return The last millisecond of the week.
 *
 * @throws NullPointerException if <code>calendar</code> is
 *     <code>null</code>.// w  w w . j  a  v  a2  s.  c o  m
 */
@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;
}

From source file:com.chortitzer.web.admin.controller.TiemposBean.java

/**
 * @return the periodoPasado/*w w  w . j  ava  2 s  .co m*/
 */
public String getPeriodoPasado() {
    try {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.MONTH, -1);
        cal.set(Calendar.DAY_OF_MONTH, 16);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        Date desde = DateUtils.truncate(cal.getTime(), Calendar.HOUR_OF_DAY);
        cal.add(Calendar.MONTH, 1);
        cal.add(Calendar.MINUTE, -1);
        Date hasta = DateUtils.truncate(cal.getTime(), Calendar.HOUR_OF_DAY);
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM");
        periodoPasado = sdf.format(desde) + " - " + sdf.format(hasta);
        return periodoPasado;
    } catch (Exception ex) {
        LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex);
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", ex.getMessage()));
        return null;
    }
}

From source file:com.fiveamsolutions.nci.commons.data.security.AbstractUser.java

/**
 * @param nonce the nonce string to check
 * @return whether this is a valid nonce at this time for this user
 */// ww w  . ja va  2 s  .  c o m
@Transient
public boolean checkNonce(String nonce) {
    if (nonce != null) {
        Calendar expiryDate = Calendar.getInstance();
        expiryDate.add(Calendar.HOUR, -REQUEST_TIMEOUT_HOURS);
        for (PasswordReset pr : getPasswordResets()) {
            if (pr.getNonce().equals(nonce) && pr.getCreateDate().after(expiryDate.getTime())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java

public Calendar prepareDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from  w  ww.j a  v  a  2  s .  com
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}

From source file:com.wxxr.nirvana.json.JSONInterceptorTest.java

@SuppressWarnings({ "unchecked", "unchecked" })
public void test() throws Exception {
    // request// w w  w  . j  av a  2  s.  c  om
    setRequestContent("json-1.txt");
    this.request.addHeader("content-type", "application/json");

    // interceptor
    JSONInterceptor interceptor = new JSONInterceptor();
    TestAction action = new TestAction();

    this.invocation.setAction(action);
    this.invocation.getStack().push(action);

    interceptor.intercept(this.invocation);

    // serialize and compare
    List list = action.getList();

    assertNotNull(list);
    assertEquals(list.size(), 10);

    list = action.getCollection();
    assertNotNull(list);
    assertEquals(list.size(), 3);
    assertEquals(list.get(0), "b");
    assertEquals(list.get(1), 1L);
    list = (List) list.get(2);
    assertNotNull(list);
    assertEquals(list.size(), 2);
    assertEquals(list.get(0), 10L);
    assertEquals(list.get(1), 12L);

    list = action.getCollection2();
    assertNotNull(list);
    assertEquals(list.size(), 1);

    // inside a map any primitive is either: String, Long, Boolean or Double
    Map bean = (Map) list.get(0);

    assertNotNull(bean);
    assertTrue((Boolean) bean.get("booleanField"));
    assertEquals(bean.get("charField"), "s");
    assertEquals(bean.get("doubleField"), 10.1);
    assertEquals(bean.get("floatField"), 1.5);
    assertEquals(bean.get("intField"), 10L);
    assertEquals(bean.get("longField"), 100L);
    assertEquals(bean.get("stringField"), "str");

    bean = (Map) bean.get("objectField");
    assertNotNull(bean);
    assertFalse((Boolean) bean.get("booleanField"));
    assertEquals(bean.get("charField"), "\u0000");
    assertEquals(bean.get("doubleField"), 2.2);
    assertEquals(bean.get("floatField"), 1.1);
    assertEquals(bean.get("intField"), 0L);
    assertEquals(bean.get("longField"), 0L);
    assertEquals(bean.get("stringField"), "  ");

    assertEquals(action.getFoo(), "foo");

    Map map = action.getMap();

    assertNotNull(map);
    assertEquals(map.size(), 2);
    assertEquals(map.get("a"), 1L);
    list = (List) map.get("c");
    assertNotNull(list);
    assertEquals(list.size(), 2);
    assertEquals(list.get(0), 1.0);
    assertEquals(list.get(1), 2.0);

    assertEquals(action.getResult(), null);

    Bean bean2 = action.getBean();

    assertNotNull(bean2);
    assertTrue(bean2.isBooleanField());
    assertEquals(bean2.getStringField(), "test");
    assertEquals(bean2.getIntField(), 10);
    assertEquals(bean2.getCharField(), 's');
    assertEquals(bean2.getDoubleField(), 10.1);
    assertEquals(bean2.getByteField(), 3);

    String[] strArray = action.getArray();

    assertNotNull(strArray);
    assertEquals(strArray.length, 2);
    assertEquals(strArray[0], "str0");
    assertEquals(strArray[1], "str1");

    int[] intArray = action.getIntArray();

    assertNotNull(intArray);
    assertEquals(intArray.length, 2);
    assertEquals(intArray[0], 1);
    assertEquals(intArray[1], 2);

    Bean[] beanArray = action.getBeanArray();

    assertNotNull(beanArray);
    assertNotNull(beanArray[0]);
    assertEquals(beanArray[0].getStringField(), "bean1");
    assertNotNull(beanArray[1]);
    assertEquals(beanArray[1].getStringField(), "bean2");

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(action.getDate());

    assertEquals(calendar.get(Calendar.YEAR), 1999);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.DECEMBER);
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 31);
    assertEquals(calendar.get(Calendar.HOUR), 11);
    assertEquals(calendar.get(Calendar.MINUTE), 59);
    assertEquals(calendar.get(Calendar.SECOND), 59);

    calendar.setTime(action.getDate2());
    assertEquals(calendar.get(Calendar.YEAR), 1999);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.DECEMBER);
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 31);

    // test desrialize=false
    assertNull(action.getFoo2());
}

From source file:com.projity.server.data.MPXConverter.java

public static void toMpxCalendar(WorkingCalendar workCalendar, ProjectCalendar mpx) {
    mpx.setName(workCalendar.getName());
    //      mpx.setUniqueID((int) workCalendar.getId()); // TODO watch out for int overrun

    WorkingCalendar wc = workCalendar;//from  w  w w. java 2  s  .  co m
    if (workCalendar.isBaseCalendar())
        wc = (WorkingCalendar) workCalendar.getBaseCalendar();
    for (int i = 0; i < 7; i++) {// MPX days go from SUNDAY=1 to SATURDAY=7
        WorkDay day = workCalendar.isBaseCalendar() ? workCalendar.getDerivedWeekDay(i)
                : workCalendar.getWeekDay(i);
        ProjectCalendarHours mpxDay = null;
        Day d = Day.getInstance(i + 1);
        if (day == null) {
            mpx.setWorkingDay(d, ProjectCalendar.DEFAULT);
        } else {
            mpx.setWorkingDay(d, day.isWorking());
            if (day.isWorking()) {
                mpxDay = mpx.addCalendarHours(Day.getInstance(i + 1));
                toMpxCalendarDay(day, mpxDay);
            }
        }
    }

    WorkDay[] workDays = workCalendar.getExceptionDays();
    if (workDays != null)
        for (int i = 0; i < workDays.length; i++) {
            if (workDays[i] == null || workDays[i].getStart() == 0L || workDays[i].getStart() == Long.MAX_VALUE)
                continue;
            ProjectCalendarException exception = mpx.addCalendarException();
            Date start = new Date(workDays[i].getStart());
            exception.setFromDate(start);
            GregorianCalendar cal = DateTime.calendarInstance();
            // days go from 00:00 to 23:59
            cal.setTime(start);
            cal.set(Calendar.HOUR, 23);
            cal.set(Calendar.MINUTE, 59);
            exception.setToDate(DateTime.fromGmt(cal.getTime()));
            toMpxExceptionDay(workDays[i], exception);
            exception.setWorking(workDays[i].isWorking());
        }
    WorkCalendar baseCalendar = workCalendar.getBaseCalendar();
    if (baseCalendar != null) {
        mpx.setBaseCalendar(ImportedCalendarService.getInstance().findExportedCalendar(baseCalendar));
    }

    //mpx.setUniqueID((int)workCalendar.getUniqueId());
}

From source file:org.onebusaway.nyc.vehicle_tracking.webapp.controllers.VehicleLocationSimulationController.java

private Date getTime(HttpSession session, Date time) {

    if (time == null)
        time = new Date();

    String calendarOffset = (String) session.getAttribute(CALENDAR_OFFSET_KEY);

    if (calendarOffset != null) {

        Matcher m = CALENDAR_OFFSET_PATTERN.matcher(calendarOffset);
        if (m.matches()) {

            int amount = Integer.parseInt(m.group(1));
            String type = m.group(2);

            Calendar c = Calendar.getInstance();
            c.setTime(time);/*from w w  w  .ja  va  2  s  . c  o  m*/

            if (type.equals("M"))
                c.add(Calendar.MONTH, amount);
            else if (type.equals("w"))
                c.add(Calendar.WEEK_OF_YEAR, amount);
            else if (type.equals("d"))
                c.add(Calendar.DAY_OF_YEAR, amount);
            else if (type.equals("h"))
                c.add(Calendar.HOUR, amount);
            time = c.getTime();
        }
    }

    return time;
}

From source file:Dates.java

/**
 * Date Arithmetic function (date2 - date1). subtract a date from another
 * date, return the difference as the required fields. E.g. if specified
 * Calendar.Date, the smaller range of fields is ignored and this method
 * return the difference of days./*from   ww w  .  j a v  a 2 s.c om*/
 * 
 * @param date2
 *          The date2.
 * @param tz
 *          The time zone.
 * @param field
 *          The time field; e.g., Calendar.DATE, Calendar.YEAR, it's default
 *          value is Calendar.DATE
 * @param date1
 *          The date1.
 */
public static final long subtract(Date date2, TimeZone tz, int field, Date date1) {
    if (tz == null)
        tz = TimeZones.getCurrent();

    boolean negative = false;
    if (date1.after(date2)) {
        negative = true;
        final Date d = date1;
        date1 = date2;
        date2 = d;
    }

    final Calendar cal1 = Calendar.getInstance(tz);
    cal1.setTimeInMillis(date1.getTime());// don't call cal.setTime(Date) which
                                          // will reset the TimeZone.

    final Calendar cal2 = Calendar.getInstance(tz);
    cal2.setTimeInMillis(date2.getTime());// don't call cal.setTime(Date) which
                                          // will reset the TimeZone.

    int year1 = cal1.get(Calendar.YEAR);
    int year2 = cal2.get(Calendar.YEAR);

    switch (field) {
    case Calendar.YEAR: {
        return negative ? (year1 - year2) : (year2 - year1);
    }
    case Calendar.MONTH: {
        int month1 = cal1.get(Calendar.MONTH);
        int month2 = cal2.get(Calendar.MONTH);
        int months = 12 * (year2 - year1) + month2 - month1;
        return negative ? -months : months;
    }
    case Calendar.HOUR: {
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        long min1 = (time1 < 0 ? (time1 - (1000 * 60 * 60 - 1)) : time1) / (1000 * 60 * 60);
        long min2 = (time2 < 0 ? (time2 - (1000 * 60 * 60 - 1)) : time2) / (1000 * 60 * 60);
        return negative ? (min1 - min2) : (min2 - min1);
    }
    case Calendar.MINUTE: {
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        long min1 = (time1 < 0 ? (time1 - (1000 * 60 - 1)) : time1) / (1000 * 60);
        long min2 = (time2 < 0 ? (time2 - (1000 * 60 - 1)) : time2) / (1000 * 60);
        return negative ? (min1 - min2) : (min2 - min1);
    }
    case Calendar.SECOND: {
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        long sec1 = (time1 < 0 ? (time1 - (1000 - 1)) : time1) / 1000;
        long sec2 = (time2 < 0 ? (time2 - (1000 - 1)) : time2) / 1000;

        return negative ? (sec1 - sec2) : (sec2 - sec1);
    }
    case Calendar.MILLISECOND: {
        return negative ? (date1.getTime() - date2.getTime()) : (date2.getTime() - date1.getTime());
    }
    case Calendar.DATE:
    default: /* default, like -1 */
    {
        int day1 = cal1.get(Calendar.DAY_OF_YEAR);
        int day2 = cal2.get(Calendar.DAY_OF_YEAR);

        int maxDay1 = year1 == year2 ? 0 : cal1.getActualMaximum(Calendar.DAY_OF_YEAR);
        int days = maxDay1 - day1 + day2;

        final Calendar cal = Calendar.getInstance(tz);
        for (int year = year1 + 1; year < year2; year++) {
            cal.set(Calendar.YEAR, year);
            days += cal.getActualMaximum(Calendar.DAY_OF_YEAR);
        }
        return negative ? -days : days;
    }
    }
}