use of com.manydesigns.elements.fields.DateField in project Portofino by ManyDesigns.
the class XlsUtil method addFieldToCell.
public void addFieldToCell(WritableSheet sheet, int i, int j, Field field) throws WriteException {
if (field instanceof NumericField) {
NumericField numField = (NumericField) field;
if (numField.getValue() != null) {
jxl.write.Number number;
BigDecimal decimalValue = numField.getValue();
if (numField.getDecimalFormat() == null) {
number = new Number(j, i, decimalValue.doubleValue());
} else {
number = new Number(j, i, decimalValue.doubleValue(), getNumberFormat(numField.getDecimalFormat().toPattern()));
}
sheet.addCell(number);
}
} else if (field instanceof PasswordField) {
Label label = new Label(j, i, PasswordField.PASSWORD_PLACEHOLDER);
sheet.addCell(label);
} else if (field instanceof DateField) {
DateField dateField = (DateField) field;
DateTime dateCell;
Date date = dateField.getValue();
if (date != null) {
dateCell = new DateTime(j, i, date, getDateFormat(dateField.getDatePattern()));
sheet.addCell(dateCell);
}
} else {
Label label = new Label(j, i, field.getStringValue());
sheet.addCell(label);
}
}
use of com.manydesigns.elements.fields.DateField in project Portofino by ManyDesigns.
the class PersistenceTest method testDateWithDTSSwitch.
// Disable because it fails on the CI server where the timezone is different
@Test(enabled = false)
public void testDateWithDTSSwitch() {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
// 1973-06-03 DTS switch at midnight in tz Europe/Rome
Date problematicDate = new Date(73, 5, 3);
Map<String, Object> order = new HashMap<>();
order.put("orderid", new BigInteger("1"));
order.put("userid", "x");
order.put("orderdate", problematicDate);
order.put("shipaddr1", "x");
order.put("shipaddr2", "x");
order.put("shipcity", "x");
order.put("shipstate", "x");
order.put("shipzip", "x");
order.put("shipcountry", "x");
order.put("billaddr1", "x");
order.put("billaddr2", "x");
order.put("billcity", "x");
order.put("billstate", "x");
order.put("billzip", "x");
order.put("billcountry", "x");
order.put("courier", "x");
order.put("totalprice", new BigDecimal(1.0));
order.put("billtofirstname", "x");
order.put("billtolastname", "x");
order.put("shiptofirstname", "x");
order.put("shiptolastname", "x");
order.put("creditcard", "x");
order.put("exprdate", "x");
order.put("cardtype", "x");
order.put("locale", "x");
Session session = persistence.getSession("jpetstore");
session.save("orders", order);
FormBuilder fb = new FormBuilder(persistence.getTableAccessor("jpetstore", "orders"));
Form form = fb.configFields("orderdate").build();
DateField dateField = (DateField) form.findFieldByPropertyName("orderdate");
dateField.readFromObject(order);
assertEquals("dd-MM-yyyy", ElementsProperties.getConfiguration().getString("fields.date.format"));
String strDate = "03-06-1973";
assertEquals(strDate, dateField.getStringValue());
MutableHttpServletRequest request = new MutableHttpServletRequest();
request.setParameter("date", strDate);
dateField.readFromRequest(request);
assertTrue(dateField.validate());
dateField.writeToObject(order);
session.update("orders", order);
session.flush();
// Forget about order
session.clear();
order = (Map) session.get("orders", new BigInteger("1"));
// Convert to java.util.Date from java.sql.Date
Date date = new Date(((Date) order.get("orderdate")).getTime());
assertEquals(73, date.getYear());
assertEquals(5, date.getMonth());
assertEquals(3, date.getDate());
assertEquals(1, date.getHours());
assertEquals(0, date.getMinutes());
assertEquals(0, date.getSeconds());
dateField.readFromObject(order);
assertEquals(strDate, dateField.getStringValue());
}
Aggregations