use of jodd.datetime.JDateTime in project jodd by oblac.
the class CalendarConverter method convert.
public Calendar convert(Object value) {
if (value == null) {
return null;
}
if (value instanceof Calendar) {
return (Calendar) value;
}
if (value instanceof Date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) value);
return calendar;
}
if (value instanceof JDateTime) {
return ((JDateTime) value).convertToCalendar();
}
if (value instanceof Number) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(((Number) value).longValue());
return calendar;
}
String stringValue = value.toString().trim();
if (!StringUtil.containsOnlyDigits(stringValue)) {
// try to parse default string format
JDateTime jdt = new JDateTime(stringValue, JDateTime.DEFAULT_FORMAT);
return jdt.convertToCalendar();
}
try {
long milliseconds = Long.parseLong(stringValue);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliseconds);
return calendar;
} catch (NumberFormatException nfex) {
throw new TypeConversionException(value, nfex);
}
}
use of jodd.datetime.JDateTime in project jodd by oblac.
the class CatalogTest method assertCatalog.
private void assertCatalog(Catalog catalog) {
assertNotNull(catalog);
Map<Long, String> map;
// areaNames
map = catalog.getAreaNames();
assertNotNull(map);
assertEquals(17, map.size());
assertEquals("1er balcon jardin", map.get(Long.valueOf(205706005)));
// audienceSubCategoryNames
map = catalog.getAudienceSubCategoryNames();
assertEquals(1, map.size());
assertEquals("Abonné", map.get(Long.valueOf(337100890)));
// events
Map<Long, Event> events = catalog.getEvents();
assertNotNull(events);
assertEquals(184, events.size());
Event event = events.get(Long.valueOf(138586341));
assertNotNull(event);
assertNull(event.getDescription());
assertEquals(138586341, event.getId().longValue());
assertNull(event.getLogo());
assertEquals("30th Anniversary Tour", event.getName());
Long[] subTopicIds = event.getSubTopicIds();
assertEquals(2, subTopicIds.length);
assertEquals(337184269, subTopicIds[0].longValue());
assertEquals(337184283, subTopicIds[1].longValue());
assertNull(event.getSubjectCode());
assertNull(event.getSubtitle());
Long[] topicIds = event.getTopicIds();
assertEquals(2, topicIds.length);
assertEquals(324846099, topicIds[0].longValue());
assertEquals(107888604, topicIds[1].longValue());
// performances
List<Performance> performances = catalog.getPerformances();
assertNotNull(performances);
assertEquals(243, performances.size());
Performance performance = performances.get(0);
assertEquals(138586341, performance.getEventId().longValue());
assertEquals(339887544, performance.getId().longValue());
assertNull(performance.getLogo());
assertNull(performance.getName());
List<Price> prices = performance.getPrices();
assertEquals(2, prices.size());
Price price = prices.get(0);
assertEquals(90250, price.getAmount());
assertEquals(337100890, price.getAudienceSubCategoryId().longValue());
assertEquals(338937295, price.getSeatCategoryId().longValue());
List<SeatCategory> seatCategories = performance.getSeatCategories();
assertEquals(2, seatCategories.size());
SeatCategory seatCategory = seatCategories.get(0);
assertEquals(338937295, seatCategory.getSeatCategoryId().longValue());
List<Area> areas = seatCategory.getAreas();
assertEquals(11, areas.size());
Area area = areas.get(0);
assertEquals(205705999, area.getAreaId().longValue());
assertEquals(0, area.getBlockIds().length);
JDateTime start = performance.getStart();
assertEquals(1372701600000L, start.getTimeInMillis());
assertEquals("PLEYEL_PLEYEL", performance.getVenueCode());
// seatCategoryNames
map = catalog.getSeatCategoryNames();
assertEquals(64, map.size());
assertEquals("catétgorie unique", map.get(Long.valueOf(342752792)));
// subTopicNames
map = catalog.getSubTopicNames();
assertEquals(19, map.size());
assertEquals("Jazz", map.get(Long.valueOf(337184269)));
// topicNames
map = catalog.getTopicNames();
assertEquals(4, map.size());
assertEquals("Genre", map.get(Long.valueOf(324846099)));
// topicSubTopics
Map<Long, Long[]> map2 = catalog.getTopicSubTopics();
assertEquals(4, map2.size());
Long[] longs = map2.get(Long.valueOf(107888604));
assertEquals(2, longs.length);
assertEquals(337184283L, longs[0].longValue());
// venueNames
Map<String, String> map3 = catalog.getVenueNames();
assertEquals(1, map3.size());
assertEquals("Salle Pleyel", map3.get("PLEYEL_PLEYEL"));
}
use of jodd.datetime.JDateTime in project my_curd by qinyou.
the class ExcelHelper method excelFileConvertToList.
/**
* @param filename
* @return
* @throws Exception
*/
public List<List> excelFileConvertToList(String filename) throws Exception {
Workbook wb = null;
// 此处为兼容2003 与2oo7
String ext = getExtensionName(filename);
if (ext.toLowerCase().equals("xlsx")) {
wb = new XSSFWorkbook(filename);
} else {
wb = WorkbookFactory.create(new FileInputStream(filename));
}
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;
}
Aggregations