Example usage for org.joda.time DateTime toLocalTime

List of usage examples for org.joda.time DateTime toLocalTime

Introduction

In this page you can find the example usage for org.joda.time DateTime toLocalTime.

Prototype

public LocalTime toLocalTime() 

Source Link

Document

Converts this object to a LocalTime with the same time and chronology.

Usage

From source file:org.netxilia.api.utils.DateUtils.java

License:Open Source License

/**
 * /*from   w ww . j  a  v a  2s  .  c  o m*/
 * @param formatter
 * @param text
 * @return the ReadablePartial corresponding to the given formatter and text
 */
public static ReadablePartial parsePartial(DateTimeFormatter formatter, String text) {
    PartialDateTimeParserBucket bucket = new PartialDateTimeParserBucket();
    int newPos = formatter.getParser().parseInto(bucket, text, 0);

    if (newPos >= 0 && newPos >= text.length()) {
        long millis = bucket.computeMillis(true, text);
        DateTime dt = new DateTime(millis, (Chronology) null);
        if (bucket.isHasDate() && bucket.isHasTime()) {
            return dt.toLocalDateTime();
        }
        if (bucket.isHasDate()) {
            return dt.toLocalDate();
        }
        return dt.toLocalTime();
    }
    throw new IllegalArgumentException("Cannot parse date:" + text);
}

From source file:org.netxilia.impexp.impl.ExcelImportService.java

License:Open Source License

private ICellCommand copyCell(Cell poiCell, CellReference cellReference, HSSFPalette palette,
        NetxiliaStyleResolver styleResolver) throws FormulaParsingException {

    CellStyle poiStyle = poiCell.getCellStyle();
    Styles styles = PoiUtils.poiStyle2Netxilia(poiStyle,
            poiCell.getSheet().getWorkbook().getFontAt(poiStyle.getFontIndex()), palette, styleResolver);

    IGenericValue value = null;/*from w ww . java2s  .  c o m*/
    Formula formula = null;

    // log.info("CELL TYPE:" + cellReference + " type:" + poiCell.getCellType() + " "
    // + (poiCell.getCellType() == Cell.CELL_TYPE_FORMULA ? poiCell.getCellFormula() : "no"));
    switch (poiCell.getCellType()) {
    // TODO translate errors

    case Cell.CELL_TYPE_STRING:
        value = new StringValue(poiCell.getStringCellValue());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(poiCell)) {
            DateTime dt = new DateTime(poiCell.getDateCellValue());
            // TODO decide whether is date or time
            if (dt.isBefore(EXCEL_START)) {
                value = new DateValue(dt.toLocalTime());
            } else if (dt.getMillisOfDay() == 0) {
                value = new DateValue(dt.toLocalDate());
            } else {
                value = new DateValue(dt.toLocalDateTime());
            }
        } else {
            value = new NumberValue(poiCell.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        value = new BooleanValue(poiCell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        if (poiCell.getCellFormula() != null) {
            formula = formulaParser.parseFormula(new Formula("=" + poiCell.getCellFormula()));
        }
        break;
    }

    if ((styles == null || styles.getItems().isEmpty()) && formula == null
            && (value == null || value.equals(GenericValueUtils.EMTPY_STRING))) {
        return null;
    }
    return CellCommands.cell(new AreaReference(cellReference), value, formula, styles);
}

From source file:org.specrunner.converters.core.ConverterLocalTimePatternArgs.java

License:Open Source License

@Override
public Object convert(Object value, Object[] args) throws ConverterException {
    if (value instanceof LocalTime) {
        return value;
    }/*from  w w w . j av a 2  s . c o  m*/
    DateTime date = (DateTime) super.convert(value, args);
    return date != null ? date.toLocalTime() : null;
}