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:com.swiftcorp.portal.common.util.CalendarUtils.java

public static Calendar getDayEndCalendar(Calendar cal) {
    Date date = cal.getTime();/* w  w w. ja va2s.  co  m*/
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(date);

    // set the hour min sec
    endCalendar.set(Calendar.HOUR, 11);
    endCalendar.set(Calendar.HOUR_OF_DAY, 23);
    endCalendar.set(Calendar.MINUTE, 59);
    endCalendar.set(Calendar.SECOND, 59);

    // return cal
    return endCalendar;
}

From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java

private long getNextWeeklyExecutionTime() {
    Calendar calendar = Calendar.getInstance();

    long nowMillis = calendar.getTimeInMillis();
    int amHour = hour;
    if (amHour > 12) {
        amHour = amHour - 12;//from  w  w w .j av  a2 s  . c  om
        calendar.set(Calendar.AM_PM, Calendar.PM);
    } else {
        calendar.set(Calendar.AM_PM, Calendar.AM);
    }
    calendar.set(Calendar.HOUR, amHour);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.DAY_OF_WEEK, weekDay + 1);
    if (calendar.getTimeInMillis() <= nowMillis) {
        calendar.add(Calendar.WEEK_OF_YEAR, 1);
    }
    return calendar.getTimeInMillis() - nowMillis;
}

From source file:net.solarnetwork.node.dao.jdbc.reactor.JdbcInstructionDao.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public int deleteHandledInstructionsOlderThan(final int hours) {
    return getJdbcTemplate().update(new PreparedStatementCreator() {

        @Override/*from w w w  . j a  v  a  2s. c  o m*/
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            final String sql = getSqlResource(RESOURCE_SQL_DELETE_OLD);
            log.debug("Preparing SQL to delete old instructions [{}] with hours [{}]", sql, hours);
            PreparedStatement ps = con.prepareStatement(sql);
            Calendar c = Calendar.getInstance();
            c.add(Calendar.HOUR, -hours);
            ps.setTimestamp(1, new Timestamp(c.getTimeInMillis()), c);
            return ps;
        }
    });
}

From source file:com.expressui.sample.dao.init.TestDataInitializer.java

public static Date randomDate(int startYear, int endYear) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.DAY_OF_MONTH, ReferenceDataInitializer.random(1, 28));
    calendar.set(Calendar.MONTH, ReferenceDataInitializer.random(1, 12));
    calendar.set(Calendar.YEAR, ReferenceDataInitializer.random(startYear, endYear));

    return calendar.getTime();
}

From source file:net.seratch.taskun.util.CalendarUtil.java

public void test_getCurrentTruncDate_A$() throws Exception {
        Calendar actual = CalendarUtil.getCurrentTruncDate();
        assertEquals(0, actual.get(Calendar.HOUR));
        assertEquals(0, actual.get(Calendar.MINUTE));
        assertEquals(0, actual.get(Calendar.SECOND));
        assertEquals(0, actual.get(Calendar.MILLISECOND));
    }//from  ww  w . java 2s . com

From source file:org.teiid.resource.adapter.google.dataprotocol.GoogleDataProtocolAPI.java

static Object convertValue(Calendar cal, Object object, SpreadsheetColumnType type) {
    switch (type) {
    case DATE://from w ww  .ja v a2s .  c  om
    case DATETIME:
        if (object instanceof String) {
            String stringVal = (String) object;
            if (stringVal.startsWith("Date(") && stringVal.endsWith(")")) { //$NON-NLS-1$ //$NON-NLS-2$
                String[] parts = stringVal.substring(5, stringVal.length() - 1).split(","); //$NON-NLS-1$
                if (cal == null) {
                    cal = Calendar.getInstance();
                }
                cal.clear();
                if (type == SpreadsheetColumnType.DATETIME) {
                    cal.set(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]), Integer.valueOf(parts[2]),
                            Integer.valueOf(parts[3]), Integer.valueOf(parts[4]), Integer.valueOf(parts[5]));
                    object = new Timestamp(cal.getTimeInMillis());
                } else {
                    cal.set(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]), Integer.valueOf(parts[2]));
                    object = new Date(cal.getTimeInMillis());
                }
            }
        }
        break;
    case TIMEOFDAY:
        if (object instanceof List<?>) {
            List<Double> doubleVals = (List<Double>) object;
            if (cal == null) {
                cal = Calendar.getInstance();
            }
            cal.clear();
            cal.set(Calendar.YEAR, 1970);
            cal.set(Calendar.MONTH, Calendar.JANUARY);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.set(Calendar.MILLISECOND, 0);
            cal.set(Calendar.HOUR, doubleVals.get(0).intValue());
            cal.set(Calendar.MINUTE, doubleVals.get(1).intValue());
            cal.set(Calendar.SECOND, doubleVals.get(2).intValue());
            //TODO: it's not proper to convey the millis on a time value
            cal.set(Calendar.MILLISECOND, doubleVals.get(3).intValue());
            object = new Time(cal.getTimeInMillis());
        }
        break;
    }
    return object;
}

From source file:org.codice.pubsub.stomp.SubscriptionQueryMessageListener.java

private boolean createSubscription(SearchQueryMessage queryMsg) {

    boolean success = false;

    String subscriptionId = queryMsg.getSubscriptionId();

    //Build Query
    String cqlText = queryMsg.getQueryString();

    if (StringUtils.isNotEmpty(cqlText)) {
        Filter filter = null;/*from   ww w.  j a  v a  2s . c om*/
        try {
            filter = CQL.toFilter(cqlText);
        } catch (CQLException e) {
            LOGGER.error("Fatal error while trying to build CQL-based Filter from cqlText : " + cqlText);
            return success;
        }

        //Add CSW Record Mapper Filter Visitor for more CQL filtering options
        try {
            FilterVisitor f = new CswRecordMapperFilterVisitor();
            filter = (Filter) filter.accept(f, null);
        } catch (UnsupportedOperationException ose) {
            try {
                throw new CswException(ose.getMessage(), CswConstants.INVALID_PARAMETER_VALUE, null);
            } catch (CswException e) {
                LOGGER.error(e.getMessage());
                return success;
            }
        }

        if (catalogFramework != null && filter != null) {
            LOGGER.trace("Catalog Frameowork: " + catalogFramework.getVersion());
            //Set creation and last modified date times
            Calendar now = Calendar.getInstance();
            queryMsg.setCreationDate(now.getTimeInMillis());
            queryMsg.setLastModifiedDate(now.getTimeInMillis());

            //Starts this class in a thread
            ExecutorService executor = Executors.newFixedThreadPool(NUM_QUERY_SEND_THREADS);
            QueryAndSend qasInst = queryAndSend.newInstance();
            qasInst.setEnterprise(DEFAULT_IS_ENTERPRISE);
            qasInst.setFilter(filter);
            qasInst.setSubscriptionId(subscriptionId);
            Callable worker = qasInst;
            executor.submit(worker);

            //Add to Subscription Map
            ObjectMapper mapper = new ObjectMapper();
            String jsonMsg = null;
            try {
                jsonMsg = mapper.writeValueAsString(queryMsg);
            } catch (JsonProcessingException e) {
                LOGGER.error(e.getMessage());
                return success;
            }

            LOGGER.debug("Store Subscription: " + jsonMsg);
            Dictionary subMap = getSubscriptionMap();
            subMap.put(subscriptionId, jsonMsg);
            setSubscriptionMap(subMap);

            //Set TTL (time to live) for subscription
            int ttlType = Calendar.MILLISECOND;

            String queryTtlType = queryMsg.getSubscriptionTtlType();

            //If Query TTL Type is null, assume Milliseconds
            if (StringUtils.isBlank(queryTtlType)) {
                LOGGER.debug("Query TTL Type is null");
                queryTtlType = TTL_TYPE_MILLISECONDS;
            }

            if (queryTtlType.equals(TTL_TYPE_MILLISECONDS)) {
                ttlType = Calendar.MILLISECOND;
            } else if (queryTtlType.equals(TTL_TYPE_SECONDS)) {
                ttlType = Calendar.SECOND;
            } else if (queryTtlType.equals(TTL_TYPE_MINUTES)) {
                ttlType = Calendar.MINUTE;
            } else if (queryTtlType.equals(TTL_TYPE_HOURS)) {
                ttlType = Calendar.HOUR;
            } else if (queryTtlType.equals(TTL_TYPE_MONTHS)) {
                ttlType = Calendar.MONTH;
            } else if (queryTtlType.equals(TTL_TYPE_YEARS)) {
                ttlType = Calendar.YEAR;
            }

            int queryTtl = queryMsg.getSubscriptionTtl();
            LOGGER.debug("Query TTL: {}", queryTtl);

            if (queryTtl == -9 || queryTtl == 0) {
                //No TTL chosen; make it close to forever
                queryTtl = 9999;
                ttlType = Calendar.YEAR;
            }

            //Set TTL from creation time to TTL specified
            long creationTime = queryMsg.getCreationDate();
            Calendar ttl = Calendar.getInstance();
            ttl.setTimeInMillis(creationTime);
            ttl.add(ttlType, queryTtl);
            subscriptionTtlMap.put(subscriptionId, ttl);

            success = true;

        } else {
            LOGGER.trace("Catalog Framework or filter is NULL");
        }
    } else {
        LOGGER.debug("Subscription ID is null: Subscription ID= {}", subscriptionId);
    }
    return success;
}

From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java

private long getNextDailyExecutionTime() {
    Calendar calendar = Calendar.getInstance();

    long nowMillis = calendar.getTimeInMillis();
    int amHour = hour;
    if (amHour > 12) {
        amHour = amHour - 12;// ww w  .  ja va2s  . co  m
        calendar.set(Calendar.AM_PM, Calendar.PM);
    } else {
        calendar.set(Calendar.AM_PM, Calendar.AM);
    }
    calendar.set(Calendar.HOUR, amHour);
    calendar.set(Calendar.MINUTE, minutes);
    if (calendar.getTimeInMillis() <= nowMillis) {
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
    return calendar.getTimeInMillis() - nowMillis;
}

From source file:es.ficonlan.web.backend.test.eventservice.EventServiceTest.java

@Test
public void testChangeActivityData() throws ServiceException {
    Session anonymousSession = userService.newAnonymousSession();
    Session s = userService.login(anonymousSession.getSessionId(), ADMIN_LOGIN, ADMIN_PASS);
    Calendar dateStart = Calendar.getInstance();
    Calendar dateEnd = Calendar.getInstance();
    dateEnd.add(Calendar.DAY_OF_YEAR, 1);
    Event event = new Event(0, "FicOnLan 2014", "FicOnLan 2014", 150, dateStart, dateEnd, dateStart, dateEnd,
            null, null, null, null, null);
    eventDao.save(event);//from   w w  w  . j  a v a 2  s .  c o m
    Activity activity = eventService.addActivity(s.getSessionId(), event.getEventId(),
            new Activity(event, "Torneo de Lol", "Torneo de Lol", 10, ActivityType.Tournament, true, dateStart,
                    dateEnd, dateStart, dateEnd));
    dateStart.add(Calendar.HOUR, 1);
    dateEnd.add(Calendar.HOUR, 2);
    eventService.changeActivityData(s.getSessionId(), activity.getActivityId(),
            new Activity(activity.getActivityId(), "Concurso de hacking", "Concurso de hacking", 20,
                    ActivityType.Production, false, dateStart, dateEnd, dateStart, dateEnd));
    assertTrue(activity.getName().contentEquals("Concurso de hacking"));
    assertTrue(activity.getDescription().contentEquals("Concurso de hacking"));
    assertTrue(activity.getNumParticipants() == 20);
    assertTrue(activity.getType() == ActivityType.Production);
    assertTrue(!activity.isOficial());
    assertTrue(activity.getStartDate().compareTo(dateStart) == 0);
    assertTrue(activity.getEndDate().compareTo(dateEnd) == 0);
    assertTrue(activity.getRegDateOpen().compareTo(dateStart) == 0);
    assertTrue(activity.getRegDateClose().compareTo(dateEnd) == 0);
}

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

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