@Override protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getDateFormat(), locale); }
public Properties getFreeMarkerSettings() { GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); Map<String, Locale> availableLocales = globalConfig.getAvailableLocales(); if (availableLocales.isEmpty()) { throw new IllegalStateException("Property cuba.availableLocales is not configured"); } Locale locale = availableLocales.values().iterator().next(); FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(locale); final Properties freemarkerSettings = new Properties(); freemarkerSettings.setProperty("number_format", "#"); freemarkerSettings.setProperty("datetime_format", formatStrings.getDateTimeFormat()); freemarkerSettings.setProperty("date_format", formatStrings.getDateFormat()); freemarkerSettings.setProperty("template_exception_handler", "rethrow"); return freemarkerSettings; } }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat()); return format.format(value); }
@Override public Date parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat()); format.setLenient(false); return normalize(format.parse(value.trim())); }
private Object tryDate(String value) { UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME); FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale()); SimpleDateFormat sdf = new SimpleDateFormat(formatStrings.getDateFormat()); try { Date date = sdf.parse(value); return date; } catch (ParseException e) { return null; } }
switch (type) { case "DATE": format = formatStrings.getDateFormat(); break; case "DATETIME":
private void initDefaultFormats() { FormatStrings formatStrings = getFormatStrings(); setDateFormat(formatStrings.getDateFormat()); setBooleanTrueValue(formatStrings.getTrueString()); setBooleanFalseValue(formatStrings.getFalseString()); }
@Override public void afterPropertiesSet() { UserSessionSource userSessionSource = beanLocator.get(UserSessionSource.class); Locale locale = userSessionSource.getLocale(); FormatStringsRegistry formatStringsRegistry = beanLocator.get(FormatStringsRegistry.NAME); dateField.setDateFormat(formatStringsRegistry.getFormatStringsNN(locale).getDateFormat()); dateField.setResolution(DateResolution.DAY); timeField.setTimeFormat(formatStringsRegistry.getFormatStringsNN(locale).getTimeFormat()); setResolution(Resolution.MIN); AppUI ui = AppUI.getCurrent(); if (ui != null && ui.isTestMode()) { timeField.setCubaId("timepart"); dateField.setCubaId("datepart"); } }