Search in sources :

Example 26 with JDateTime

use of jodd.datetime.JDateTime in project my_curd by qinyou.

the class ExcelHelper method excelFileConvertToList.

/**
 * @param filename
 * @param inputStream
 * @return
 * @throws Exception
 */
public List<List> excelFileConvertToList(String filename, FileInputStream inputStream) throws Exception {
    Workbook wb = null;
    // 此处为兼容2003 与2oo7
    String ext = getExtensionName(filename);
    if (ext.toLowerCase().equals("xlsx")) {
        wb = new XSSFWorkbook(inputStream);
    } else {
        wb = WorkbookFactory.create(inputStream);
    }
    Sheet sheet = wb.getSheetAt(0);
    List<List> rows = new ArrayList<List>();
    for (Row row : sheet) {
        List<Object> cells = new ArrayList<Object>();
        for (Cell cell : row) {
            Object obj = null;
            CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
            switch(cell.getCellType()) {
                case Cell.CELL_TYPE_STRING:
                    obj = cell.getRichStringCellValue().getString();
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    if (DateUtil.isCellDateFormatted(cell)) {
                        obj = new JDateTime(cell.getDateCellValue());
                    } else {
                        obj = cell.getNumericCellValue();
                    }
                    break;
                case Cell.CELL_TYPE_BOOLEAN:
                    obj = cell.getBooleanCellValue();
                    break;
                case Cell.CELL_TYPE_FORMULA:
                    obj = cell.getNumericCellValue();
                    break;
                default:
                    obj = null;
            }
            cells.add(obj);
        }
        rows.add(cells);
    }
    return rows;
}
Also used : CellReference(org.apache.poi.hssf.util.CellReference) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) JDateTime(jodd.datetime.JDateTime) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook)

Example 27 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class ConvertTest method testDefaultConversion.

@Test
public void testDefaultConversion() {
    assertEquals(true, Convert.toBooleanValue(null, true));
    assertEquals((byte) 23, Convert.toByteValue(null, (byte) 23));
    assertEquals('A', Convert.toCharValue(null, 'A'));
    assertEquals(1.4d, Convert.toDoubleValue(null, 1.4d), 0.005);
    assertEquals(1.4f, Convert.toFloatValue(null, 1.4f), 0.005);
    assertEquals(23L, Convert.toLongValue(null, 23L));
    assertEquals(7, Convert.toIntValue(null, 7));
    assertEquals(7, Convert.toShortValue(null, (short) 7));
    BigDecimal defaultBigDecimal = new BigDecimal("1.1");
    assertEquals(defaultBigDecimal, Convert.toBigDecimal(null, defaultBigDecimal));
    BigInteger defaultBigInteger = new BigInteger("173");
    assertEquals(defaultBigInteger, Convert.toBigInteger(null, defaultBigInteger));
    String defaultString = "123qweasdzxc";
    assertEquals(defaultString, Convert.toString(null, defaultString));
    JDateTime defaultJDateTime = new JDateTime(2010, 4, 20);
    assertEquals(defaultJDateTime, Convert.toJDateTime(null, defaultJDateTime));
    Date defaultDate = defaultJDateTime.convertToDate();
    assertEquals(defaultDate, Convert.toDate(null, defaultDate));
    Calendar defaultCalendar = defaultJDateTime.convertToCalendar();
    assertEquals(defaultCalendar, Convert.toCalendar(null, defaultCalendar));
    assertEquals(Boolean.TRUE, Convert.toBoolean(null, Boolean.TRUE));
    assertEquals(Byte.valueOf((byte) 123), Convert.toByte(null, Byte.valueOf((byte) 123)));
    assertEquals(Character.valueOf('A'), Convert.toCharacter(null, Character.valueOf('A')));
    assertEquals(Double.valueOf(5), Convert.toDouble(null, Double.valueOf(5)));
    assertEquals(Float.valueOf(5), Convert.toFloat(null, Float.valueOf(5)));
    assertEquals(Long.valueOf(7), Convert.toLong(null, Long.valueOf(7)));
    assertEquals(Integer.valueOf(8), Convert.toInteger(null, Integer.valueOf(8)));
    assertEquals(Short.valueOf((short) 3), Convert.toShort(null, Short.valueOf((short) 3)));
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JDateTime(jodd.datetime.JDateTime) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 28 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class JDateTimeConverterTest method testTimestamp2JDateTime.

@Test
public void testTimestamp2JDateTime() {
    Timestamp timestamp = new Timestamp(time);
    JDateTime jdt = jDateTimeConverter.convert(timestamp);
    assertEquals(time, jdt.getTimeInMillis());
}
Also used : JDateTime(jodd.datetime.JDateTime) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 29 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class JDateTimeConverterTest method testSqlDate2JDateTime.

@Test
public void testSqlDate2JDateTime() {
    java.sql.Date date = new java.sql.Date(time);
    JDateTime jdt = jDateTimeConverter.convert(date);
    assertEquals(time, jdt.getTimeInMillis());
}
Also used : JDateTime(jodd.datetime.JDateTime) Date(java.util.Date) Test(org.junit.Test)

Example 30 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class JDateTimeConverterTest method testJDateTime2JDateTime.

@Test
public void testJDateTime2JDateTime() {
    JDateTime jdt2 = new JDateTime(time);
    JDateTime jdt = jDateTimeConverter.convert(jdt2);
    assertEquals(time, jdt.getTimeInMillis());
}
Also used : JDateTime(jodd.datetime.JDateTime) Test(org.junit.Test)

Aggregations

JDateTime (jodd.datetime.JDateTime)38 Test (org.junit.Test)28 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)8 Date (java.util.Date)6 Timestamp (java.sql.Timestamp)5 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)2 Time (java.sql.Time)2 DbSession (jodd.db.DbSession)2 CellReference (org.apache.poi.hssf.util.CellReference)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 File (java.io.File)1 Date (java.sql.Date)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 DateTimeStamp (jodd.datetime.DateTimeStamp)1 DbThreadSession (jodd.db.DbThreadSession)1 Area (jodd.json.model.cat.Area)1 Event (jodd.json.model.cat.Event)1