Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

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

Prototype

int SECOND

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

Click Source Link

Document

Field number for get and set indicating the second within the minute.

Usage

From source file:org.vietspider.server.handler.cms.metas.IndexSearchHandler.java

public String handle(final HttpRequest request, final HttpResponse response, final HttpContext context,
        String... params) throws Exception {
    String pattern = params[1];// ww w .  j  a v a  2 s .c om
    int idx = pattern.indexOf('=');
    if (idx < 0 || idx >= pattern.length() - 1) {
        throw new IndexOutOfBoundsException("Incorrect parammeter");
    }

    String search = URLDecoder.decode(pattern.substring(idx + 1), "UTF-8");

    pattern = search;

    MetaList metas = new MetaList();
    metas.setAction("SEARCH");
    metas.setCurrentPage(Integer.parseInt(params[0]));

    String[][] parameters = ParameterParser.getParameters(params[1]);

    /*SearchQuery query = null;
    if(parameters.length > 0) {
      query = new SearchQuery(parameters[0][1]);
    //      for(int i = 1; i < parameters.length; i++) {
    //        if("region".equalsIgnoreCase(parameters[i][0])) {
    //          query.setRegion(parameters[i][1]);
    //        }
    //      }
    } else {
      throw new IndexOutOfBoundsException("Incorrect parammeter");
    }*/

    ArticleSearchQuery query = new ArticleSearchQuery();
    for (int i = 0; i < parameters.length; i++) {
        if (parameters[i][0].charAt(0) == '?') {
            parameters[i][0] = parameters[i][0].substring(1);
        }
        //      System.out.println(parameters[i][0] + " : "+ parameters[i][1]);
        if (parameters[i][0].equals("text")) {
            query.setPattern(parameters[i][1]);
        } else if (parameters[i][0].equals("source")) {
            query.setSource(parameters[i][1]);
        } else if (parameters[i][0].equals("dtstart")) {
            parameters[i][1] = parameters[i][1].replace('.', '/');
            try {
                SimpleDateFormat dateFormat = CalendarUtils.getDateFormat();
                Date date = dateFormat.parse(parameters[i][1]);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                calendar.set(Calendar.HOUR, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                query.setIndexFrom(calendar.getTimeInMillis());
            } catch (Exception e) {
                LogService.getInstance().setMessage(e, e.toString());
            }
        } else if (parameters[i][0].equals("dtend")) {
            parameters[i][1] = parameters[i][1].replace('.', '/');
            try {
                SimpleDateFormat dateFormat = CalendarUtils.getDateFormat();
                Date date = dateFormat.parse(parameters[i][1]);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                calendar.set(Calendar.HOUR, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
                query.setIndexTo(calendar.getTimeInMillis());
            } catch (Exception e) {
                LogService.getInstance().setMessage(e, e.toString());
            }
        }
    }

    if (Application.LICENSE != Install.PERSONAL) {
        //      ArticleSearchQuery query = new ArticleSearchQuery(parameters[0][1]);
        query.setHighlightStart("<b style=\"color: black; background-color: rgb(255, 255, 102);\">");
        query.setHighlightEnd("</b>");
        ArticleIndexStorage.getInstance().search(metas, query);
    }

    //    System.out.println("thay co " + metas.getData().size());

    //    System.out.println(parameters[0][1]);

    //    File tempFolder = UtilFile.getFolder("content/temp/search/");
    //    ContentSearcher2 searcher = new ContentSearcher2(ContentSearcher2.SIMPLE, tempFolder);
    //    HighlightBuilder highlighter = new HighlightBuilder(query.getPattern().toLowerCase());
    //    highlighter.setHighlightTag("<b style=\"color: black; background-color: rgb(255, 255, 102);\">", "</b>");
    //      query.setParser(new QueryParser());
    //    DefaultArticleHandler articleHandler2 = new DefaultArticleHandler(highlighter);
    //    searcher.search(metas, query, articleHandler2);
    //    ContentSearcher searcher = new ContentSearcher();
    //    searcher.search(metas, pattern);

    WebRM resources = new WebRM();
    StringBuilder builder = new StringBuilder(resources.getLabel("search"));
    metas.setTitle(builder.toString());
    metas.setUrl(params[1]);

    return write(request, response, context, metas, params);
}

From source file:helper.lang.DateHelperTest.java

@Test
public void testGetRangeDaysBeforeTodayUtc() {
    int days = 1;
    Calendar nowUtc = DateHelper.nowUtc();

    CalendarRange range = DateHelper.getRangeFullDaysBefore(nowUtc, days);
    Calendar start = range.getStart();
    Calendar end = range.getEnd();
    System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(start));
    System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(end));

    // end date is midnight of date passed in
    assertEquals(nowUtc.get(Calendar.YEAR), end.get(Calendar.YEAR));
    assertEquals(nowUtc.get(Calendar.MONTH), end.get(Calendar.MONTH));
    assertEquals(nowUtc.get(Calendar.DATE), end.get(Calendar.DATE));
    assertEquals(0, end.get(Calendar.HOUR));
    assertEquals(0, end.get(Calendar.MINUTE));
    assertEquals(0, end.get(Calendar.SECOND));
    assertEquals(0, end.get(Calendar.MILLISECOND));
    assertEquals(0, end.get(Calendar.HOUR_OF_DAY));
    assertEquals(DateHelper.UTC_TIME_ZONE, end.getTimeZone());

    // start date is 11:59:59 or 'days' time
    nowUtc.add(Calendar.DATE, -(days + 2));
    assertEquals(nowUtc.get(Calendar.YEAR), start.get(Calendar.YEAR));
    assertEquals(nowUtc.get(Calendar.MONTH), start.get(Calendar.MONTH));
    assertEquals(nowUtc.get(Calendar.DATE), start.get(Calendar.DATE));
    assertEquals(11, start.get(Calendar.HOUR));
    assertEquals(23, start.get(Calendar.HOUR_OF_DAY));
    assertEquals(59, start.get(Calendar.MINUTE));
    assertEquals(59, start.get(Calendar.SECOND));
    assertEquals(999, start.get(Calendar.MILLISECOND));
    assertEquals(DateHelper.UTC_TIME_ZONE, start.getTimeZone());

}

From source file:br.gov.frameworkdemoiselle.component.audit.dashboard.view.UsersDashboardMB.java

private void search() {
    Calendar dateBegin = Calendar.getInstance();
    dateBegin.set(Calendar.DAY_OF_MONTH, dateBegin.get(Calendar.DAY_OF_MONTH) - 5);
    dateBegin.set(Calendar.HOUR_OF_DAY, 0);
    dateBegin.set(Calendar.MINUTE, 0);
    dateBegin.set(Calendar.SECOND, 0);

    Calendar dateFinal = Calendar.getInstance();
    dateFinal.set(Calendar.HOUR_OF_DAY, 23);
    dateFinal.set(Calendar.MINUTE, 59);
    dateFinal.set(Calendar.SECOND, 59);

    trails = trailBC.findByNamedQueryWithBetween("Trail.findByUserName", "userName", user.getUserName(),
            dateBegin.getTime(), dateFinal.getTime());
}

From source file:br.com.autonomiccs.autonomic.administration.plugin.services.AutonomicClusterManagementService.java

/**
 * Checks if the cluster has been processed recently (according to the
 * administration algorithm management interval). If the host has no last administration value
 * ('last_administration' column is null), then we consider that the cluster
 * has never been processed; therefore, we will put it into the management queue.
 * @return true if the cluster can be processed
 *//*from w  w  w .java2 s. c o  m*/
public boolean canProcessCluster(long clusterId, ClusterAdministrationHeuristicAlgorithm algorithm) {
    Date lastAdministration = clusterDaoJdbc.getClusterLastAdminstration(clusterId);
    if (lastAdministration == null) {
        return true;
    }
    Calendar lastAdministrationCalendar = Calendar.getInstance();
    lastAdministrationCalendar.setTime(lastAdministration);
    lastAdministrationCalendar.add(Calendar.SECOND, algorithm.getClusterIntervalBetweenConsolidation());
    Calendar calendarNow = Calendar.getInstance();
    return lastAdministrationCalendar.before(calendarNow);
}

From source file:com.sdm.core.resource.DefaultResource.java

protected Map<String, Object> buildCache(int cacheAge) {
    // Build CacheControl
    CacheControl cc = new CacheControl();
    cc.setMaxAge(cacheAge);/*from   ww w  . j a va2s. c o  m*/
    cc.setNoStore(false);
    cc.setPrivate(true);
    cc.setNoTransform(false);

    // Build Expire
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.SECOND, cacheAge);

    Map<String, Object> cacheHeader = new HashMap<>();
    cacheHeader.put(HttpHeaders.CACHE_CONTROL, cc);
    cacheHeader.put(HttpHeaders.EXPIRES, cal.getTime());
    cacheHeader.put(HttpHeaders.ETAG, new EntityTag(eTag));
    cacheHeader.put(HttpHeaders.LAST_MODIFIED, lastModified);
    return cacheHeader;
}

From source file:com.bt.sdk.callcontrol.demo.standup.ConferenceRowCallbackHandler.java

public void processRow(ResultSet arg0) throws SQLException {
    String conferenceName = arg0.getString("name");
    log.debug(conferenceName);//  www.  j a v  a  2s . c o m

    Calendar conferenceTime = Calendar.getInstance();
    conferenceTime.set(Calendar.HOUR_OF_DAY, arg0.getTime("time").getHours());
    conferenceTime.set(Calendar.MINUTE, arg0.getTime("time").getMinutes());
    conferenceTime.set(Calendar.SECOND, 0);
    conferenceTime.set(Calendar.MILLISECOND, 0);
    String date = DATE_FORMAT.format(Calendar.getInstance().getTime());
    final String key = String.format("%s:%02d%02d:%s", conferenceName, conferenceTime.get(Calendar.HOUR_OF_DAY),
            conferenceTime.get(Calendar.MINUTE), date);
    log.debug(key);
    if (conferenceFutures.containsKey(key)) {
        log.warn(String.format("conference already scheduled: %s", key));
        return;
    }
    final List<String> participants = getParticipants(conferenceName);
    log.debug(participants);
    log.info(String.format("Starting conference \"%s\" in %d seconds", conferenceName,
            secondsBeforeStartTime(conferenceTime)));
    conferenceFutures.put(key, scheduledExecutorService.schedule(new Runnable() {
        public void run() {
            String conferenceId = conferenceBean.createConference(participants.size(),
                    maxConferenceDurationInMinutes);
            conferences.put(conferenceId, key);
            log.debug(conferences);
            for (String participantTelno : participants) {
                String callLegId = conferenceBean.createParticipantCallLeg(conferenceId,
                        URI.create(String.format("sip:%s@%s", participantTelno, pstnGatewayIpAddress)));
                conferenceBean.inviteParticipant(conferenceId, callLegId);
            }
        }
    }, secondsBeforeStartTime(conferenceTime), TimeUnit.SECONDS));
}

From source file:info.raack.appliancedetection.common.util.DateUtils.java

public Calendar getPreviousFiveMinuteIncrement(Calendar calOrig) {
    Calendar cal = (Calendar) calOrig.clone();

    // round start time to 5 minute marker to greatly simplify evaluation
    cal.add(Calendar.MILLISECOND, -1 * cal.get(Calendar.MILLISECOND));
    cal.add(Calendar.SECOND, -1 * cal.get(Calendar.SECOND));
    cal.add(Calendar.MINUTE, -1 * cal.get(Calendar.MINUTE) % 5);

    return cal;//w w w  . j  av a  2  s.c  om
}

From source file:py.una.pol.karaku.test.test.FormatProviderTest.java

/**
 *
 *///from   w w  w  .j a  v  a 2 s.com
@Before
public void setUp() {

    calendar = GregorianCalendar.getInstance();
    calendar.set(Calendar.YEAR, 2013);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DATE, 1);

    calendar.set(Calendar.HOUR_OF_DAY, 6);
    calendar.set(Calendar.MINUTE, 30);
    calendar.set(Calendar.SECOND, 10);

    date = calendar.getTime();

    veryLarge = this.getByString("1000000000000");
    large = this.getByString("100000");
    small = this.getByString("100");
    verySmall = this.getByString("1");
    decimal = this.getByString("0.111");
    decimalUP = this.getByString("0.119");
    smallDecimal = this.getByString("0.0111");
    smallDecimalUP = this.getByString("0.0159");
}

From source file:org.yamj.core.service.tasks.ExecutionTaskService.java

public void executeTask(ExecutionTask executionTask) {
    ITask task = registeredTasks.get(executionTask.getTaskName().toLowerCase());

    if (task == null) {
        LOG.warn("Task " + executionTask.getTaskName() + " not registered");
    } else {//from  w  w w  .  j a v a 2s .  c  om
        try {
            task.execute(executionTask.getOptions());
        } catch (Exception ex) {
            LOG.error("Failed to execute task '" + task.getTaskName() + "'", ex);
        }
    }

    if (IntervalType.ONCE == executionTask.getIntervalType()) {
        // just delete the task after executed once
        try {
            this.executionTaskStorageService.deleteEntity(executionTask);
        } catch (Exception ex) {
            LOG.error("Failed to delete execution task: " + executionTask.getName(), ex);
        }
        // nothing to do for this task anymore
        return;
    }

    try {
        Calendar nextCal = Calendar.getInstance();
        nextCal.setTime(executionTask.getNextExecution());

        Calendar cal = Calendar.getInstance();
        if (IntervalType.MONTHLY == executionTask.getIntervalType()) {
            cal.add(Calendar.MONTH, 1);
            cal.set(Calendar.DAY_OF_MONTH, nextCal.get(Calendar.DAY_OF_MONTH));
            cal.set(Calendar.HOUR_OF_DAY, nextCal.get(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE, nextCal.get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, nextCal.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, 0);
        } else if (IntervalType.DAILY == executionTask.getIntervalType()) {
            cal.add(Calendar.DAY_OF_MONTH, 1);
            cal.set(Calendar.HOUR_OF_DAY, nextCal.get(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE, nextCal.get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, nextCal.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, 0);
        } else if (IntervalType.DAYS == executionTask.getIntervalType()) {
            cal.add(Calendar.DAY_OF_MONTH, executionTask.getDelay());
            cal.set(Calendar.HOUR_OF_DAY, nextCal.get(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE, nextCal.get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, nextCal.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, 0);
        } else if (IntervalType.HOURS == executionTask.getIntervalType()) {
            cal.add(Calendar.HOUR_OF_DAY, executionTask.getDelay());
            cal.set(Calendar.MINUTE, nextCal.get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, nextCal.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, 0);
        } else if (IntervalType.MINUTES == executionTask.getIntervalType()) {
            cal.add(Calendar.MINUTE, executionTask.getDelay());
            cal.set(Calendar.SECOND, nextCal.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, 0);
        }

        executionTask.setLastExecution(new Date());
        executionTask.setNextExecution(cal.getTime());
        this.executionTaskStorageService.updateEntity(executionTask);
    } catch (Exception ex) {
        LOG.error("Failed to update: {}", executionTask);
        LOG.warn("Storage error", ex);
    }
}

From source file:com.ar.dev.tierra.api.service.FacturaService.java

public BigDecimal getFacturaSumByDay(int idSucursal) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    BigDecimal total = facturaRepository.sumFacturasEnded(fromDate, toDate, idSucursal);
    return total;
}