use of com.haulmont.chile.core.datatypes.TimeZoneAwareDatatype in project cuba by cuba-platform.
the class DatatypeFormatter method parseDateTime.
/**
* Parse Date (date and time) using {@code dateTimeFormat} string specified in the main message pack.
* <p>Takes into account time zone if it is set for the current user session.</p>
* @return Date value or null if a blank string is provided
*/
@Nullable
public Date parseDateTime(String str) throws ParseException {
TimeZone timeZone = uss.getUserSession().getTimeZone();
Datatype<Date> datatype = Datatypes.getNN(Date.class);
if (datatype instanceof TimeZoneAwareDatatype) {
return (Date) ((TimeZoneAwareDatatype) datatype).parse(str, uss.getLocale(), timeZone);
}
return datatype.parse(str, uss.getLocale());
}
use of com.haulmont.chile.core.datatypes.TimeZoneAwareDatatype in project cuba by cuba-platform.
the class ListEditorHelper method getValueCaption.
public static String getValueCaption(Object v, ListEditor.ItemType itemType, TimeZone timeZone) {
if (v == null)
return null;
switch(itemType) {
case ENTITY:
if (v instanceof Instance)
return ((Instance) v).getInstanceName();
else
return v.toString();
case STRING:
return (String) v;
case DATE:
return Datatypes.getNN(java.sql.Date.class).format(v);
case DATETIME:
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = userSessionSource.getUserSession();
if (timeZone != null) {
return ((TimeZoneAwareDatatype) Datatypes.getNN(Date.class)).format(v, userSession.getLocale(), timeZone);
} else {
return Datatypes.getNN(Date.class).format(v, userSession.getLocale());
}
case INTEGER:
return Datatypes.getNN(Integer.class).format(v);
case LONG:
return Datatypes.getNN(Long.class).format(v);
case BIGDECIMAL:
return Datatypes.getNN(BigDecimal.class).format(v);
case DOUBLE:
return Datatypes.getNN(Double.class).format(v);
case ENUM:
return AppBeans.get(Messages.class).getMessage((Enum) v);
case UUID:
return Datatypes.getNN(java.util.UUID.class).format(v);
default:
throw new IllegalStateException("Unknown item type");
}
}
use of com.haulmont.chile.core.datatypes.TimeZoneAwareDatatype in project cuba by cuba-platform.
the class DatatypeFormatter method formatDateTime.
/**
* Format Date (date and time) using {@code dateTimeFormat} string specified in the main message pack.
* <p>Takes into account time zone if it is set for the current user session.</p>
* @return string representation or empty string if the value is null
*/
public String formatDateTime(@Nullable Date value) {
TimeZone timeZone = uss.getUserSession().getTimeZone();
Datatype<Date> datatype = Datatypes.getNN(Date.class);
if (datatype instanceof TimeZoneAwareDatatype) {
return ((TimeZoneAwareDatatype) datatype).format(value, uss.getLocale(), timeZone);
}
return datatype.format(value, uss.getLocale());
}
Aggregations