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.semispace.semimeter.dao.mongo.SemiMeterDaoMongo.java

@Override
public void performInsertion(final Collection<Item> items) {
    DBCollection meterCollection = mongoTemplate.getCollection("meter");
    DBCollection sumsCollection = mongoTemplate.getCollection("sums");
    for (Item item : items) {
        //some time calculations
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(item.getWhen());
        cal.set(Calendar.MILLISECOND, 0);
        long second = cal.getTimeInMillis();
        cal.set(Calendar.SECOND, 0);
        long minute = cal.getTimeInMillis();
        cal.set(Calendar.MINUTE, 0);
        long hour = cal.getTimeInMillis();
        cal.setTimeInMillis(item.getWhen());

        BasicDBObject query = new BasicDBObject();
        PathElements pathElements = MeterHit.calcPath(item.getPath(), "/");
        query.append("id", integerForCompatibilityReasonOrString(pathElements.getE4()));
        query.append("sectionId", integerForCompatibilityReasonOrString(pathElements.getE3()));
        query.append("publicationId", integerForCompatibilityReasonOrString(pathElements.getE2()));
        query.append("type", pathElements.getE1());

        StringBuilder sb = new StringBuilder();
        sb.append("{ '$inc': ");
        sb.append(" { 'day.count' : " + item.getAccessNumber() + ", ");
        sb.append("   'day.last15minutes' : " + item.getAccessNumber() + ", ");
        sb.append("   'day.last180minutes' : " + item.getAccessNumber() + ", ");
        sb.append("   'day.hours." + hour + ".count' : " + item.getAccessNumber() + ",  ");
        sb.append(/*from   www .  j av  a 2 s. c o m*/
                "   'day.hours." + hour + ".minutes." + minute + ".count' : " + item.getAccessNumber() + "  ");
        sb.append("}}");

        DBObject update = (DBObject) JSON.parse(sb.toString());

        meterCollection.update(query, update, true, false, WriteConcern.UNACKNOWLEDGED);

        query = new BasicDBObject();
        BasicDBObject time = new BasicDBObject();
        query.append("time", time);
        time.append("ts", minute);
        time.append("year", cal.get(Calendar.YEAR));
        time.append("month", cal.get(Calendar.MONTH));
        time.append("day", cal.get(Calendar.DAY_OF_MONTH));
        time.append("hour", cal.get(Calendar.HOUR_OF_DAY));
        time.append("minute", cal.get(Calendar.MINUTE));

        sb = new StringBuilder();
        sb.append(" { '$inc': ");
        sb.append("{ 'total' : ").append(item.getAccessNumber());
        if (pathElements.getE1().equals("article")) {
            sb.append(", 'article' : ").append(item.getAccessNumber());
        } else if (pathElements.getE1().equals("album")) {
            sb.append(", 'album' : ").append(item.getAccessNumber());
        } else if (pathElements.getE1().equals("video")) {
            sb.append(", 'video' : ").append(item.getAccessNumber());
        } else {
            sb.append(", 'other' : ").append(item.getAccessNumber());
        }
        sb.append(" } }");

        update = (DBObject) JSON.parse(sb.toString());

        sumsCollection.update(query, update, true, false, WriteConcern.UNACKNOWLEDGED);

    }
}

From source file:com.greenline.guahao.biz.util.DateUtils.java

/**
 * // w w w  . j av  a2  s.c  o  m
 * 
 * @param date
 * @return Date
 */
public static Date getYmdTime(Date date) {
    if (date == null) {
        return (new Date());
    }
    Calendar day = Calendar.getInstance();
    day.setTime(date);
    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);
    Date convertTime = day.getTime();
    return convertTime;
}

From source file:net.sf.housekeeper.domain.Food.java

/**
 * Sets the expiry date of this item to one second before midnight of the
 * given date. A value of null specifies that the expiry for this item
 * should not be set to a value./*from ww w .  j a  v  a  2 s. c o m*/
 * 
 * @param expiry The new expiry date or null to unset the date.
 */
public void setExpiry(final Date expiry) {
    if (expiry != null) {
        final Date truncatedExpiry = DateUtils.truncate(expiry, Calendar.DAY_OF_MONTH);
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(truncatedExpiry);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.SECOND, -1);
        this.expiry = calendar.getTime();
    } else {
        this.expiry = null;
    }
}

From source file:br.gov.frameworkdemoiselle.component.audit.dashboard.view.FeaturesDashboardMB.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 dataFinal = Calendar.getInstance();
    dataFinal.set(Calendar.HOUR_OF_DAY, 23);
    dataFinal.set(Calendar.MINUTE, 59);
    dataFinal.set(Calendar.SECOND, 59);

    trails = trailBC.findByNamedQueryWithBetween("Trail.findByWhat", "what", feature.getWhat(),
            dateBegin.getTime(), dataFinal.getTime());
}

From source file:com.lfv.yada.net.server.ServerLogger.java

public synchronized void print(String s) {
    if (printer != null && s != null && suspendTime == 0) {
        long t = System.currentTimeMillis();

        // UTC time
        calendar.setTimeInMillis(t);/*from  w ww  .  j ava2 s . c  o  m*/
        String st = "UTC " + s2(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + s2(calendar.get(Calendar.MINUTE))
                + ":" + s2(calendar.get(Calendar.SECOND)) + "." + s3(calendar.get(Calendar.MILLISECOND));

        // Simulation time
        calendar.setTimeInMillis(resumeTime + t - startTime);
        st += " SIM " + s2(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + s2(calendar.get(Calendar.MINUTE)) + ":"
                + s2(calendar.get(Calendar.SECOND)) + "." + s3(calendar.get(Calendar.MILLISECOND));

        // Print it to the output logfile
        printer.println(st + " | " + s);
    }
}

From source file:com.adobe.acs.commons.http.headers.impl.AbstractExpiresHeaderFilterTest.java

@Test
public void testGetHeaderValue() throws Exception {

    when(componentContext.getProperties()).thenReturn(properties);

    Calendar expected = Calendar.getInstance();
    expected.set(Calendar.HOUR_OF_DAY, 2);
    expected.set(Calendar.MINUTE, 30);
    expected.set(Calendar.SECOND, 0);
    expected.set(Calendar.MILLISECOND, 0);

    filter.doActivate(componentContext);
    String header = filter.getHeaderValue();
    Date date = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z").parse(header);
    Calendar actual = Calendar.getInstance();
    actual.setTime(date);/* ww w. jav a2 s  .c o  m*/
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);

    assertTrue(DateUtils.isSameInstant(expected, actual));
}

From source file:Time.java

public void setSeconds(int seconds) {
    calendar_.set(Calendar.SECOND, seconds);
}

From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java

/**
 * Generate the histogram buckets based on the time frame requested and the interval.  This will
 * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0.
 * @param rval//from  w w w.j  a va  2 s . c o m
 * @param from
 * @param to
 * @param interval
 */
public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval,
        DateTime from, DateTime to, HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) {
    Map<K, T> index = new HashMap<>();

    Calendar fromCal = from.toGregorianCalendar();
    Calendar toCal = to.toGregorianCalendar();

    switch (interval) {
    case day:
        fromCal.set(Calendar.HOUR_OF_DAY, 0);
        fromCal.set(Calendar.MINUTE, 0);
        fromCal.set(Calendar.SECOND, 0);
        fromCal.set(Calendar.MILLISECOND, 0);
        break;
    case hour:
        fromCal.set(Calendar.MINUTE, 0);
        fromCal.set(Calendar.SECOND, 0);
        fromCal.set(Calendar.MILLISECOND, 0);
        break;
    case minute:
        fromCal.set(Calendar.SECOND, 0);
        fromCal.set(Calendar.MILLISECOND, 0);
        break;
    case month:
        fromCal.set(Calendar.DAY_OF_MONTH, 1);
        fromCal.set(Calendar.HOUR_OF_DAY, 0);
        fromCal.set(Calendar.MINUTE, 0);
        fromCal.set(Calendar.SECOND, 0);
        fromCal.set(Calendar.MILLISECOND, 0);
        break;
    case week:
        fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        fromCal.set(Calendar.HOUR_OF_DAY, 0);
        fromCal.set(Calendar.MINUTE, 0);
        fromCal.set(Calendar.SECOND, 0);
        fromCal.set(Calendar.MILLISECOND, 0);
        break;
    default:
        break;
    }

    while (fromCal.before(toCal)) {
        String label = formatDateWithMillis(fromCal);
        T point;
        try {
            point = dataType.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        point.setLabel(label);
        rval.addDataPoint(point);
        if (keyType == String.class) {
            index.put((K) label, point);
        } else {
            index.put((K) new Long(fromCal.getTimeInMillis()), point);
        }
        switch (interval) {
        case day:
            fromCal.add(Calendar.DAY_OF_YEAR, 1);
            break;
        case hour:
            fromCal.add(Calendar.HOUR_OF_DAY, 1);
            break;
        case minute:
            fromCal.add(Calendar.MINUTE, 1);
            break;
        case month:
            fromCal.add(Calendar.MONTH, 1);
            break;
        case week:
            fromCal.add(Calendar.WEEK_OF_YEAR, 1);
            break;
        default:
            break;
        }
    }

    return index;

}

From source file:com.sshdemo.common.schedule.generate.validator.JobInfoValidator.java

protected void validateJobTrigger(ValidationErrorsable errors, JobInfo job) throws BaseException {
    JobTrigger trigger = job.getTrigger();
    if (trigger == null) {
        errors.add(new ValidationError("error.alqc.job.no.trigger", null, "??.",
                "trigger"));
        return;//w w w  .  j  ava  2s . c  om
    }

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date now = calendar.getTime();
    String tzId = trigger.getTimeZone();
    if (tzId != null && tzId.length() > 0) {
        TimeZone tz = TimeZone.getTimeZone(tzId);
        now = DateBuilder.translateTime(now, tz, TimeZone.getDefault());
    }

    if (trigger.getStartType() == JobTrigger.START_TYPE_SCHEDULE) {
        Date startDate = trigger.getStartDate();
        if (startDate == null) {
            errors.add(new ValidationError("error.not.empty", null, "?.",
                    "trigger.startDate"));
            //            } else if (startDate.before(now)) {
            //                errors.add(new ValidationError("error.before.current.date", null, "?.", "trigger.startDate"));
        }
    }

    if (trigger.getEndDate() != null) {
        if (trigger.getStartType() == JobTrigger.START_TYPE_NOW) {
            if (trigger.getEndDate().before(now)) {
                errors.add(new ValidationError("error.before.current.date", null,
                        "??.", "trigger.endDate"));
            }
        } else if (trigger.getStartType() == JobTrigger.START_TYPE_SCHEDULE) {
            if (trigger.getEndDate().before(now)) {
                errors.add(new ValidationError("error.before.current.date", null,
                        "??.", "trigger.endDate"));
            }
            if (trigger.getStartDate() != null && trigger.getEndDate().before(trigger.getStartDate())) {
                errors.add(new ValidationError("error.before.start.date", null,
                        "??.", "trigger.endDate"));
            }
        }
    }

    if (trigger instanceof JobSimpleTrigger) {
        validateJobSimpleTrigger(errors, (JobSimpleTrigger) trigger);
    } else if (trigger instanceof JobCalendarTrigger) {
        validateJobCalendarTrigger(errors, (JobCalendarTrigger) trigger);
    } else {
        //            String quotedTriggerType = "\"" + trigger.getClass().getName() + "\"";
        //            throw new JSException("jsexception.job.unknown.trigger.type", new Object[] {quotedTriggerType});
        throw new BaseException("??",
                "??");
    }
}

From source file:com.streamsets.pipeline.stage.origin.jdbc.table.AllTypesIT.java

private static void populateRecords() {
    Record record = RecordCreator.create();
    LinkedHashMap<String, Field> fields;
    AtomicInteger id_field = new AtomicInteger(0);

    //CHAR_AND_BINARY
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);/*from   w  w w .  j  ava2 s  .  co  m*/
    fields.put("char1", Field.create("abcdefghij"));
    fields.put("varchar1", Field.create(UUID.randomUUID().toString()));
    fields.put("clob1", Field.create(UUID.randomUUID().toString()));
    fields.put("varbinary1", Field.create(UUID.randomUUID().toString().getBytes()));
    fields.put("blob1", Field.create(UUID.randomUUID().toString().getBytes()));
    record.set(Field.createListMap(fields));

    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("CHAR_AND_BINARY").getRight().add(record);

    //Date and time
    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    fields.put("date1", Field.create(Field.Type.DATE, calendar.getTime()));
    calendar.setTimeInMillis(System.currentTimeMillis());

    calendar.set(Calendar.MILLISECOND, 0);
    fields.put("timestamp1", Field.create(Field.Type.DATETIME, calendar.getTime()));
    fields.put("datetime1", Field.create(Field.Type.DATETIME, calendar.getTime()));
    calendar.setTimeInMillis(System.currentTimeMillis());

    calendar.set(Calendar.YEAR, 1970);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.MILLISECOND, 0);
    fields.put("time1", Field.create(Field.Type.TIME, calendar.getTime()));
    calendar.setTimeInMillis(System.currentTimeMillis());

    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DATE_AND_TIME").getRight().add(record);

    //DIFFERENT_INTS
    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    fields.put("int1", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE));
    fields.put("int2", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE));
    fields.put("mediumint1", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE));
    fields.put("tinyint1", Field.create(Field.Type.SHORT, -128));
    fields.put("smallint1", Field.create(Field.Type.SHORT, Short.MIN_VALUE));
    fields.put("bigint1", Field.create(Field.Type.LONG, Long.MIN_VALUE));
    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DIFFERENT_INTS").getRight().add(record);

    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    fields.put("int1", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE));
    fields.put("int2", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE));
    fields.put("mediumint1", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE));
    fields.put("tinyint1", Field.create(Field.Type.SHORT, 127));
    fields.put("smallint1", Field.create(Field.Type.SHORT, Short.MAX_VALUE));
    fields.put("bigint1", Field.create(Field.Type.LONG, Long.MAX_VALUE));
    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DIFFERENT_INTS").getRight().add(record);

    //FLOATING_PT_INTS
    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    fields.put("decimal1", Field.create(Field.Type.DECIMAL, new BigDecimal("12.345")));
    fields.put("number1", Field.create(Field.Type.DECIMAL, new BigDecimal("0.12345")));
    fields.put("double1", Field.create(Field.Type.DOUBLE, 123.456));
    fields.put("real1", Field.create(Field.Type.FLOAT, 12.34));
    fields.put("floatdouble1", Field.create(Field.Type.DOUBLE, Double.MAX_VALUE));
    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("FLOATING_PT_INTS").getRight().add(record);

    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    fields.put("decimal1", Field.create(Field.Type.DECIMAL, new BigDecimal("-12.345")));
    fields.put("number1", Field.create(Field.Type.DECIMAL, new BigDecimal("-0.12345")));
    fields.put("double1", Field.create(Field.Type.DOUBLE, -123.456));
    fields.put("real1", Field.create(Field.Type.FLOAT, -12.34));
    fields.put("floatdouble1", Field.create(Field.Type.DOUBLE, Double.MIN_VALUE));
    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("FLOATING_PT_INTS").getRight().add(record);

    //OTHER_TYPES
    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    fields.put("boolean1", Field.create(Field.Type.BOOLEAN, true));
    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("OTHER_TYPES").getRight().add(record);

    record = RecordCreator.create();
    fields = new LinkedHashMap<>();
    createIdField(fields, id_field);
    fields.put("boolean1", Field.create(Field.Type.BOOLEAN, false));
    record.set(Field.createListMap(fields));
    TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("OTHER_TYPES").getRight().add(record);
}