Example usage for org.apache.poi.ss.usermodel DateUtil getJavaCalendarUTC

List of usage examples for org.apache.poi.ss.usermodel DateUtil getJavaCalendarUTC

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel DateUtil getJavaCalendarUTC.

Prototype

public static Calendar getJavaCalendarUTC(double date, boolean use1904windowing) 

Source Link

Document

Get EXCEL date as Java Calendar with UTC time zone.

Usage

From source file:org.eclipse.emfforms.internal.spreadsheet.core.converter.EMFFormsSpreadsheetSingleAttributeConverter.java

License:Open Source License

private Object readCellValue(Cell cell, final EDataType attributeType) {
    if (isByte(attributeType.getInstanceClass())) {
        return Double.valueOf(cell.getNumericCellValue()).byteValue();
    } else if (isShort(attributeType.getInstanceClass())) {
        return Double.valueOf(cell.getNumericCellValue()).shortValue();
    } else if (isInteger(attributeType.getInstanceClass())) {
        return Double.valueOf(cell.getNumericCellValue()).intValue();
    } else if (isLong(attributeType.getInstanceClass())) {
        return Double.valueOf(cell.getNumericCellValue()).longValue();
    } else if (isFloat(attributeType.getInstanceClass())) {
        return Double.valueOf(cell.getNumericCellValue()).floatValue();
    } else if (isDouble(attributeType.getInstanceClass())) {
        return cell.getNumericCellValue();
    } else if (isBigInteger(attributeType.getInstanceClass())) {
        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            return BigInteger.valueOf((long) cell.getNumericCellValue());
        }//from   www. j  a  v  a  2  s .  c  om
        return new BigInteger(cell.getStringCellValue());
    } else if (isBigDecimal(attributeType.getInstanceClass())) {
        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            return BigDecimal.valueOf(cell.getNumericCellValue()).stripTrailingZeros();
        }
        final String value = cell.getStringCellValue();
        return new BigDecimal(value).stripTrailingZeros();
    } else if (isBoolean(attributeType.getInstanceClass())) {
        return cell.getBooleanCellValue();
    } else if (isDate(attributeType.getInstanceClass())) {
        return DateUtil.getJavaDate(cell.getNumericCellValue());
    } else if (isXMLDate(attributeType.getInstanceClass())) {
        final Calendar targetCal = DateUtil.getJavaCalendarUTC(cell.getNumericCellValue(), false);
        if (targetCal == null) {
            return null;
        }
        final XMLGregorianCalendar cal = new XMLCalendar(targetCal.getTime(), XMLCalendar.DATE);
        cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
        cal.setHour(DatatypeConstants.FIELD_UNDEFINED);
        cal.setMinute(DatatypeConstants.FIELD_UNDEFINED);
        cal.setSecond(DatatypeConstants.FIELD_UNDEFINED);
        cal.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return cal;
    } else {
        return EcoreUtil.createFromString(attributeType, cell.getStringCellValue());
    }
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.converter.EMFFormsSpreadsheetSingleAttributeConverter_Test.java

License:Open Source License

@Test
public void testSetCellValueXmlDate() throws EMFFormsConverterException {
    final XMLGregorianCalendar cellValue = new XMLCalendar(Calendar.getInstance(UTC_TIMEZONE).getTime(),
            XMLCalendar.DATE);/* w ww  .ja  va  2s. c o m*/

    final EDataType dataType = EcoreFactory.eINSTANCE.createEDataType();
    dataType.setInstanceClass(XMLGregorianCalendar.class);
    final EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
    eAttribute.setEType(dataType);

    converter.setCellValue(cell, cellValue, eAttribute, viewModelContext);
    assertEquals(cellValue.toGregorianCalendar(UTC_TIMEZONE, null, cellValue).getTime(),
            DateUtil.getJavaCalendarUTC(cell.getNumericCellValue(), false).getTime());
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.EMFFormsSpreadsheetExporterImpl_ITest.java

License:Open Source License

@Test
public void testRender() throws DatatypeConfigurationException {
    final EMFFormsSpreadsheetExporter viewRenderer = new EMFFormsSpreadsheetExporterImpl(new ViewProvider() {
        @Override/* w  ww  . j a  va  2  s  .  c o  m*/
        public VView getViewModel(EObject viewEobject, VViewModelProperties properties) {
            return getView();
        }
    });
    final User user = getDomainModel();
    final Workbook wb = viewRenderer.render(Collections.singleton(user), null, null);
    final Sheet sheet = wb.getSheetAt(0);
    final Row row = sheet.getRow(3);
    assertEquals(11, row.getLastCellNum());
    for (int i = 0; i < 10; i++) {
        final Cell cell = row.getCell(i + 1);
        switch (i) {
        case 0:
            assertEquals(user.getFirstName(), cell.getStringCellValue());
            break;
        case 1:
            assertEquals(user.getLastName(), cell.getStringCellValue());
            break;
        case 2:
            assertEquals(user.getGender().toString(), cell.getStringCellValue());
            break;
        case 3:
            assertEquals(user.isActive(), cell.getBooleanCellValue());
            break;
        case 4:
            assertEquals(user.getTimeOfRegistration(), cell.getDateCellValue());
            break;
        case 5:
            assertEquals(user.getWeight(), cell.getNumericCellValue(), 0);
            break;
        case 6:
            assertEquals(user.getHeigth(), Double.valueOf(cell.getNumericCellValue()).intValue());
            break;
        case 7:
            assertEquals(user.getNationality().toString(), cell.getStringCellValue());
            break;
        case 8:
            assertEquals(user.getDateOfBirth().toGregorianCalendar().getTime(),
                    DateUtil.getJavaCalendarUTC(cell.getNumericCellValue(), false).getTime());
            break;
        case 9:
            assertEquals(user.getEmail(), cell.getStringCellValue());
            break;
        default:
            fail();
        }
    }
}