Example usage for java.sql Time Time

List of usage examples for java.sql Time Time

Introduction

In this page you can find the example usage for java.sql Time Time.

Prototype

public Time(long time) 

Source Link

Document

Constructs a Time object using a milliseconds time value.

Usage

From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java

/**
 * Methods to read and write length coded times in the Binary Protocol
 * //from   w ww. j ava2 s . c o m
 * if days, hours, minutes, seconds and micro_seconds are all 0, length is 0
 * and no other field is sent
 * 
 * if micro_seconds is 0, length is 8 and micro_seconds is not sent
 * otherwise length is 12
 * 
 * Fields 
 *       length (1) -- number of bytes following (valid values: 0, 8, 12)
 *       is_negative (1) -- (1 if minus, 0 for plus) 
 *       days (4) -- days 
 *       hours (1) -- hours
 *       minutes (1) -- minutes
 *       seconds (1) -- seconds
 *       micro_seconds (4) -- micro-seconds
 */
public static Time getLengthCodedTime(ByteBuf cb) throws PEException {
    Calendar cal = Calendar.getInstance();
    cal.clear();
    short length = cb.readUnsignedByte();

    if (length == 0)
        return null;

    Time ret = null;

    if (length >= 8) {
        cb.skipBytes(1); // this is the sign - we are ignoring this for now
        cb.skipBytes(4); // this is "days" - we are ignoring this for now
        cal.set(Calendar.HOUR_OF_DAY, cb.readByte());
        cal.set(Calendar.MINUTE, cb.readByte());
        cal.set(Calendar.SECOND, cb.readByte());
        if (length == 12) {
            long microSeconds = cb.readUnsignedInt();
            cal.set(Calendar.MILLISECOND, (int) (microSeconds / 1000));
        }
        if (length > 12) {
            throw new PEException("Invalid length specified to date type (" + length + ")");
        }

        ret = new Time(cal.getTimeInMillis());
    }
    return ret;
}

From source file:org.kuali.kpme.core.calendar.entry.CalendarEntryBo.java

public Time getBatchEmployeeApprovalTime() {
    return batchEmployeeApprovalDateTime != null ? new Time(batchEmployeeApprovalDateTime.getTime()) : null;
}

From source file:org.sakaiproject.component.section.sakai.CourseSectionImpl.java

public static final Time convertStringToTime(String str) {
    if (StringUtils.trimToNull(str) == null) {
        return null;
    }/*from   w ww .j  a v  a  2 s . c  o  m*/
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_LONG);
        return new Time(sdf.parse(str).getTime());
    } catch (Exception e) {

        // Stored in other format, with date and time zone. 
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_DATE_TZ);

            Calendar src = new GregorianCalendar();
            src.setTime(sdf.parse(str));
            src.setTimeInMillis(src.getTimeInMillis());

            TimeZone srcTz = sdf.getTimeZone();
            TimeZone userTz = timeService.getLocalTimeZone();
            TimeZone serverTz = TimeZone.getDefault();

            Calendar now = new GregorianCalendar(userTz);

            // STORED IN DAYLIGHT SAVING TIME and NOW IS STANDARD
            if (srcTz.inDaylightTime(src.getTime()) && !srcTz.inDaylightTime(now.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() + srcTz.getDSTSavings());
            }

            // STORED IN STANDAR TIME and NOW IS DAYLIGHT SAVING TIME
            if (srcTz.inDaylightTime(now.getTime()) && !srcTz.inDaylightTime(src.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() - srcTz.getDSTSavings());
            }

            // DO THE SAME IN SERVER TIMEZONE
            if (serverTz.inDaylightTime(src.getTime()) && !serverTz.inDaylightTime(now.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() - serverTz.getDSTSavings());
            }

            if (serverTz.inDaylightTime(now.getTime()) && !serverTz.inDaylightTime(src.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() + serverTz.getDSTSavings());
            }

            src.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
            src.set(Calendar.YEAR, now.get(Calendar.YEAR));
            src.set(Calendar.MONTH, now.get(Calendar.MONTH));

            return new Time(src.getTimeInMillis() + userTz.getOffset(now.getTimeInMillis())
                    - serverTz.getOffset(now.getTimeInMillis()));

        } catch (Exception ex) {
            if (log.isDebugEnabled())
                log.debug("Unable to parse " + str);
            return null;
        }
    }
}

From source file:org.azkfw.datasource.xml.XmlDatasourceBuilder.java

private XmlRecord readData(final int aRowNum, final XmlRecordEntity aRecord, final List<XmlField> aFields)
        throws ParseException {
    Map<String, Object> data = new HashMap<String, Object>();
    for (int i = 0; i < aFields.size(); i++) {
        XmlField field = aFields.get(i);
        XmlRecordDataEntity d = aRecord.data.get(i);

        String value = d.value;/*from w w  w. j a va  2 s  . com*/

        if (nullString.equals(value)) {
            data.put(field.name, null);
        } else {
            if (FieldType.String == field.type) {
                String obj = value;
                data.put(field.name, obj);
            } else if (FieldType.Boolean == field.type) {
                Boolean obj = Boolean.parseBoolean(value);
                data.put(field.name, obj);
            } else if (FieldType.Integer == field.type) {
                Double obj = Double.parseDouble(value);
                data.put(field.name, Integer.valueOf(obj.intValue()));
            } else if (FieldType.Long == field.type) {
                Double obj = Double.parseDouble(value);
                data.put(field.name, Long.valueOf(obj.longValue()));
            } else if (FieldType.Float == field.type) {
                Float obj = Float.parseFloat(value);
                data.put(field.name, obj);
            } else if (FieldType.Double == field.type) {
                Double obj = Double.parseDouble(value);
                data.put(field.name, obj);
            } else if (FieldType.Timestamp == field.type) {
                Timestamp obj = new Timestamp(
                        new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value).getTime());
                data.put(field.name, obj);
            } else if (FieldType.Date == field.type) {
                Timestamp ts = new Timestamp(new SimpleDateFormat("yyyy/MM/dd").parse(value).getTime());
                Date obj = new Date(ts.getTime());
                data.put(field.name, obj);
            } else if (FieldType.Time == field.type) {
                Timestamp ts = new Timestamp(new SimpleDateFormat("HH:mm:ss").parse(value).getTime());
                Time obj = new Time(ts.getTime());
                data.put(field.name, obj);
            } else {
                throw new ParseException("Undefined type.[" + field.getType() + "]", aRowNum);
            }
        }
    }

    XmlRecord record = new XmlRecord();
    record.data = data;
    return record;
}

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

static Object convertValue(Calendar cal, Object object, SpreadsheetColumnType type) {
    switch (type) {
    case DATE:/*w ww . ja v a 2 s  . c o m*/
    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:gobblin.converter.jdbc.AvroToJdbcEntryConverter.java

@Override
public Iterable<JdbcEntryData> convertRecord(JdbcEntrySchema outputSchema, GenericRecord record,
        WorkUnitState workUnit) throws DataConversionException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Converting " + record);
    }//from   www. ja  v a 2  s . co m
    List<JdbcEntryDatum> jdbcEntryData = Lists.newArrayList();
    for (JdbcEntryMetaDatum entry : outputSchema) {
        final String colName = entry.getColumnName();
        final JdbcType jdbcType = entry.getJdbcType();
        final Object val = record.get(tryConvertColumn(colName, this.jdbcToAvroColPairs));

        if (val == null) {
            jdbcEntryData.add(new JdbcEntryDatum(colName, null));
            continue;
        }

        if (!JDBC_SUPPORTED_TYPES.contains(jdbcType)) {
            throw new DataConversionException("Unsupported JDBC type detected " + jdbcType);
        }

        switch (jdbcType) {
        case VARCHAR:
            jdbcEntryData.add(new JdbcEntryDatum(colName, val.toString()));
            continue;
        case INTEGER:
        case BOOLEAN:
        case BIGINT:
        case FLOAT:
        case DOUBLE:
            jdbcEntryData.add(new JdbcEntryDatum(colName, val));
            continue;
        //        case BOOLEAN:
        //          jdbcEntryData.add(new JdbcEntryDatum(colName, Boolean.valueOf((boolean) val)));
        //          continue;
        //        case BIGINT:
        //          jdbcEntryData.add(new JdbcEntryDatum(colName, Long.valueOf((long) val)));
        //          continue;
        //        case FLOAT:
        //          jdbcEntryData.add(new JdbcEntryDatum(colName, Float.valueOf((float) val)));
        //          continue;
        //        case DOUBLE:
        //          jdbcEntryData.add(new JdbcEntryDatum(colName, Double.valueOf((double) val)));
        //          continue;
        case DATE:
            jdbcEntryData.add(new JdbcEntryDatum(colName, new Date((long) val)));
            continue;
        case TIME:
            jdbcEntryData.add(new JdbcEntryDatum(colName, new Time((long) val)));
            continue;
        case TIMESTAMP:
            jdbcEntryData.add(new JdbcEntryDatum(colName, new Timestamp((long) val)));
            continue;
        default:
            throw new DataConversionException(jdbcType + " is not supported");
        }
    }
    JdbcEntryData converted = new JdbcEntryData(jdbcEntryData);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Converted data into " + converted);
    }
    return new SingleRecordIterable<>(converted);
}

From source file:org.kuali.kpme.core.calendar.entry.CalendarEntryBo.java

public Time getBatchSupervisorApprovalTime() {
    return batchSupervisorApprovalDateTime != null ? new Time(batchSupervisorApprovalDateTime.getTime()) : null;
}

From source file:org.diffkit.diff.sns.DKPoiSheet.java

private static Time readTime(Cell cell_) {
    Date dateValue = cell_.getDateCellValue();
    if (dateValue == null)
        return null;
    return new Time(dateValue.getTime());
}

From source file:org.apache.gobblin.converter.jdbc.AvroToJdbcEntryConverter.java

@Override
public Iterable<JdbcEntryData> convertRecord(JdbcEntrySchema outputSchema, GenericRecord record,
        WorkUnitState workUnit) throws DataConversionException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Converting " + record);
    }/*w  w w  . j  a  v a 2  s.  c o m*/
    List<JdbcEntryDatum> jdbcEntryData = Lists.newArrayList();
    for (JdbcEntryMetaDatum entry : outputSchema) {
        final String jdbcColName = entry.getColumnName();
        final JdbcType jdbcType = entry.getJdbcType();

        String avroColName = convertJdbcColNameToAvroColName(jdbcColName);
        final Object val = avroRecordValueGet(record, AVRO_RECORD_LEVEL_SPLITTER.split(avroColName).iterator());

        if (val == null) {
            jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, null));
            continue;
        }

        if (!JDBC_SUPPORTED_TYPES.contains(jdbcType)) {
            throw new DataConversionException("Unsupported JDBC type detected " + jdbcType);
        }

        switch (jdbcType) {
        case VARCHAR:
            jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, val.toString()));
            continue;
        case INTEGER:
        case BOOLEAN:
        case BIGINT:
        case FLOAT:
        case DOUBLE:
            jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, val));
            continue;
        case DATE:
            jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, new Date((long) val)));
            continue;
        case TIME:
            jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, new Time((long) val)));
            continue;
        case TIMESTAMP:
            jdbcEntryData.add(new JdbcEntryDatum(jdbcColName, new Timestamp((long) val)));
            continue;
        default:
            throw new DataConversionException(jdbcType + " is not supported");
        }
    }
    JdbcEntryData converted = new JdbcEntryData(jdbcEntryData);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Converted data into " + converted);
    }
    return new SingleRecordIterable<>(converted);
}

From source file:fr.certu.chouette.dao.hibernate.AbstractDaoTemplateTests.java

protected ConnectionLink createConnectionLink() {
    ConnectionLink connectionLink = new ConnectionLink();
    connectionLink.setObjectId("ConnectionLink:" + getNextObjectId());
    connectionLink.setStairsAvailable(true);
    connectionLink.setStartOfLink(createStopArea());
    connectionLink.setEndOfLink(createStopArea());
    connectionLink.setDefaultDuration(new Time(new Date().getTime()));
    return connectionLink;
}