Example usage for java.util Calendar clone

List of usage examples for java.util Calendar clone

Introduction

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

Prototype

@Override
public Object clone() 

Source Link

Document

Creates and returns a copy of this object.

Usage

From source file:org.betaconceptframework.astroboa.portal.utility.CalendarUtils.java

public Calendar[] getPredefinedCalendarPeriod(String predefinedPeriodName, TimeZone zone, Locale locale) {
    if ("today".equals(predefinedPeriodName)) {
        Calendar todayStart = GregorianCalendar.getInstance(zone, locale);
        Calendar todayEnd = GregorianCalendar.getInstance(zone, locale);

        setCalendarToStartOfDay(todayStart);
        setCalendarToEndOfDay(todayEnd);

        Calendar[] period = { todayStart, todayEnd };
        return period;
    }//w  ww  .  j av a  2s.  c o  m

    if ("tomorrow".equals(predefinedPeriodName)) {
        Calendar tomorrowStart = GregorianCalendar.getInstance(zone, locale);
        tomorrowStart.add(Calendar.DAY_OF_MONTH, 1);

        Calendar tomorrowEnd = (GregorianCalendar) tomorrowStart.clone();
        setCalendarToStartOfDay(tomorrowStart);
        setCalendarToEndOfDay(tomorrowEnd);

        Calendar[] period = { tomorrowStart, tomorrowEnd };
        return period;
    }

    if ("weekend".equals(predefinedPeriodName))
        return getCurrentWeekendPeriod(zone, locale);

    if ("thisWeek".equals(predefinedPeriodName))
        return getCurrentWeekPeriod(zone, locale);

    if ("thisMonth".equals(predefinedPeriodName))
        return getCurrentMonthPeriod(zone, locale);

    if ("nextSevenDays".equals(predefinedPeriodName))
        return getNextSevenDaysPeriod(zone, locale);

    if ("nextThirtyDays".equals(predefinedPeriodName))
        return getNextThirtyDaysPeriod(zone, locale);

    return null;
}

From source file:org.ambraproject.admin.service.impl.SyndicationServiceImpl.java

@Transactional
@SuppressWarnings("unchecked")
@Override/*www  . jav a2s.c  o  m*/
public List<Syndication> getFailedAndInProgressSyndications(final String journalKey) {
    Integer numDaysInPast = configuration
            .getInteger("ambra.virtualJournals." + journalKey + ".syndications.display.numDaysInPast", 30);

    // The most recent midnight.  No need to futz about with exact dates.
    final Calendar start = Calendar.getInstance();
    start.set(Calendar.HOUR, 0);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.MILLISECOND, 0);

    final Calendar end = (Calendar) start.clone(); // The most recent midnight (last night)

    start.add(Calendar.DATE, -(numDaysInPast));
    end.add(Calendar.DATE, 1); // Include everything that happened today.

    final Journal journal = journalService.getJournal(journalKey);

    if (journal == null) {
        throw new SyndicationException("Could not find journal for journal key: " + journalKey);
    }

    return (List<Syndication>) hibernateTemplate.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            StringBuilder sql = new StringBuilder();
            sql.append("select {s.*} from syndication s ").append("join article a on s.doi = a.doi ")
                    .append("where s.status in ('" + Syndication.STATUS_IN_PROGRESS + "','"
                            + Syndication.STATUS_FAILURE + "')")
                    .append("and s.lastModified between '" + mysqlDateFormat.format(start.getTime()) + "'")
                    .append(" and '" + mysqlDateFormat.format(end.getTime()) + "' and ")
                    .append("a.eIssn = '" + journal.geteIssn() + "'");

            return session.createSQLQuery(sql.toString()).addEntity("s", Syndication.class).list();
        }
    });
}

From source file:com.linuxbox.enkive.imap.mongo.MongoImapAccountCreator.java

@Override
public void addImapMessages(String username, Date fromDate, Date toDate) throws MessageSearchException {

    Calendar startTime = Calendar.getInstance();
    startTime.setTime(fromDate);/*from   ww w  . j  ava2s  .c  om*/
    Calendar endTime = Calendar.getInstance();
    endTime.setTime(toDate);

    while (startTime.before(endTime)) {
        Calendar endOfMonth = (Calendar) startTime.clone();
        endOfMonth.set(Calendar.DAY_OF_MONTH, endOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH));

        if (endOfMonth.after(endTime))
            endOfMonth = (Calendar) endTime.clone();

        // Need to get all messages to add
        Set<String> messageIdsToAdd = getMailboxMessageIds(username, startTime.getTime(), endOfMonth.getTime());
        // Need to add messages
        // Get top UID, add from there
        if (!messageIdsToAdd.isEmpty()) {
            // Need to check if folder exists, if not create it and add to
            // user
            // mailbox list
            DBObject mailboxObject = getMessagesFolder(username, startTime.getTime());

            @SuppressWarnings("unchecked")
            HashMap<String, String> mailboxMsgIds = (HashMap<String, String>) mailboxObject
                    .get(MongoEnkiveImapConstants.MESSAGEIDS);

            TreeMap<String, String> sortedMsgIds = new TreeMap<String, String>();
            sortedMsgIds.putAll(mailboxMsgIds);
            long i = 0;
            if (!sortedMsgIds.isEmpty())
                i = Long.valueOf(sortedMsgIds.lastKey());

            for (String msgId : messageIdsToAdd) {
                i++;
                mailboxMsgIds.put(((Long.toString(i))), msgId);
            }
            mailboxObject.put(MongoEnkiveImapConstants.MESSAGEIDS, mailboxMsgIds);

            imapCollection.findAndModify(new BasicDBObject("_id", mailboxObject.get("_id")), mailboxObject);
        }
        startTime.set(Calendar.DAY_OF_MONTH, 1);
        startTime.add(Calendar.MONTH, 1);
    }
}

From source file:eu.planets_project.tb.impl.model.exec.ExecutionRecordImpl.java

/**
 * @param date the date to set/*  ww  w .ja  v a 2  s  .  c  om*/
 */
public void setEndDate(Calendar date) {
    this.endDate = (Calendar) date.clone();
    this.endMillis = new Long(this.endDate.get(Calendar.MILLISECOND));
    this.endDate.clear(Calendar.MILLISECOND);
}

From source file:eu.planets_project.tb.impl.model.exec.ExecutionRecordImpl.java

/**
 * @param date the date to set//from w ww  . j  a v  a2  s. co  m
 */
public void setStartDate(Calendar date) {
    this.startDate = (Calendar) date.clone();
    this.startMillis = new Long(this.startDate.get(Calendar.MILLISECOND));
    this.startDate.clear(Calendar.MILLISECOND);
}

From source file:org.apache.flume.sink.customhdfs.add.ImpalaTableFill.java

private void setPartitionStr() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(this.partitionFormat);
    this.nowPartition = simpleDateFormat.format(calendar.getTime());
    Calendar calendarLast = (Calendar) calendar.clone();
    setLastTime(calendarLast);//  w w  w .j  a va 2s.c  om
    this.lastPartition = simpleDateFormat.format(calendarLast.getTime());
    LOG.info("now partition:" + this.nowPartition + ",last partition:" + this.lastPartition);
}

From source file:org.openhab.binding.unifi.internal.handler.UniFiClientThingHandler.java

private synchronized boolean isClientHome(UniFiClient client) {
    boolean online = false;
    if (client != null) {
        Calendar lastSeen = client.getLastSeen();
        if (lastSeen == null) {
            logger.warn("Could not determine if client is online: cid = {}, lastSeen = null",
                    config.getClientID());
        } else {//from ww w  .j  a va  2 s  . com
            Calendar considerHome = (Calendar) lastSeen.clone();
            considerHome.add(Calendar.SECOND, config.getConsiderHome());
            Calendar now = Calendar.getInstance();
            online = (now.compareTo(considerHome) < 0);
        }
    }
    return online;
}

From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java

/**
 * @param connection/*  w  w w .  j  ava 2  s  . c o  m*/
 * @param series
 * @param metrica
 * @param timeBegin
 * @param timeEnd
 * @param dataset
 * @throws SQLException
 */
private void getMetrics(Connection connection, String series, String metrica, Calendar calendarBegin,
        Calendar calendarEnd, DefaultCategoryDataset dataset) throws SQLException {

    PreparedStatement stmt = null;
    try {

        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");

        Calendar calendar1 = (Calendar) calendarBegin.clone();
        String dateStr = format.format(calendar1.getTime());
        dataset.addValue(0, series, dateStr);
        for (int i = 0; i < 6; i++) {
            calendar1.add(Calendar.DAY_OF_MONTH, 1);
            dateStr = format.format(calendar1.getTime());
            dataset.addValue(0, series, dateStr);
        }

        stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE"
                + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? ");

        stmt.setString(1, metrica);
        stmt.setDate(2, new java.sql.Date(calendarBegin.getTimeInMillis()));
        stmt.setDate(3, new java.sql.Date(calendarEnd.getTimeInMillis()));
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            long value = rs.getLong("METRIC_VALUE_LONG");
            Date date = rs.getDate("METRIC_DATE");
            dateStr = format.format(date.getTime());
            String category = dateStr;
            dataset.addValue(value, series, category);
            //            System.out.println(value + " = " + series + " = "+ category);
        }
        rs.close();

    } finally {
        if (stmt != null)
            stmt.close();
    }
}

From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java

/**
 * @param connection//from  w w w .j  a v a 2  s.  co m
 * @param series
 * @param metrica
 * @param timeBegin
 * @param timeEnd
 * @param dataset
 * @throws SQLException
 */
private void getMetrics(Connection connection, String series, String metrica, Calendar calendarBegin,
        Calendar calendarEnd, DefaultCategoryDataset dataset) throws SQLException {

    PreparedStatement stmt = null;
    try {

        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");

        Calendar calendar1 = (Calendar) calendarBegin.clone();
        String dateStr = format.format(calendar1.getTime());
        dataset.addValue(0, series, dateStr);
        for (int i = 0; i < 6; i++) {
            calendar1.add(Calendar.DAY_OF_MONTH, 1);
            dateStr = format.format(calendar1.getTime());
            dataset.addValue(0, series, dateStr);
        }

        stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE"
                + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? ");

        stmt.setString(1, metrica);
        stmt.setDate(2, new java.sql.Date(calendarBegin.getTimeInMillis()));
        stmt.setDate(3, new java.sql.Date(calendarEnd.getTimeInMillis()));
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            long value = rs.getLong("METRIC_VALUE_LONG") / 1000;
            Date date = rs.getDate("METRIC_DATE");
            dateStr = format.format(date.getTime());
            String category = dateStr;
            dataset.addValue(value, series, category);
            //            System.out.println(value + " = " + series + " = "+ category);
        }
        rs.close();

    } finally {
        if (stmt != null)
            stmt.close();
    }
}

From source file:org.kuali.kfs.gl.batch.service.impl.RunDateServiceImpl.java

/**
 * Determines if the given calendar time is before the given cutoff time
 * //ww w . j a  v a2  s  .co m
 * @param currentCal the current time
 * @param cutoffTime the "start of the day" cut off time
 * @return true if the current time is before the cutoff, false otherwise
 */
protected boolean isCurrentDateBeforeCutoff(Calendar currentCal, CutoffTime cutoffTime) {
    if (cutoffTime != null) {
        // if cutoff date is not properly defined
        // 24 hour clock (i.e. hour is 0 - 23)

        // clone the calendar so we get the same month, day, year
        // then change the hour, minute, second fields
        // then see if the cutoff is before or after
        Calendar cutoffCal = (Calendar) currentCal.clone();
        cutoffCal.setLenient(false);
        cutoffCal.set(Calendar.HOUR_OF_DAY, cutoffTime.hour);
        cutoffCal.set(Calendar.MINUTE, cutoffTime.minute);
        cutoffCal.set(Calendar.SECOND, cutoffTime.second);
        cutoffCal.set(Calendar.MILLISECOND, 0);

        return currentCal.before(cutoffCal);
    }
    // if cutoff date is not properly defined, then it is considered to be after the cutoff
    return false;
}