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;
}
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)));
}
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());
}
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());
}
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());
}
Aggregations