@Test public void shouldBeAbleToConvert() throws ParseException { when(request.getAttribute(LOCALE_KEY + ".request")).thenReturn("pt_br"); assertThat(converter.convert("10/06/2008", Date.class, bundle), is(equalTo(new SimpleDateFormat("dd/MM/yyyy") .parse("10/06/2008")))); }
public Date convert(String value, Class<? extends Date> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat formatDateTime = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale); try { return formatDateTime.parse(value); } catch (ParseException pe) { DateFormat formatDate = DateFormat.getDateInstance( DateFormat.SHORT, locale); try { return formatDate.parse(value); } catch (ParseException pe1) { throw new ConversionError(MessageFormat.format( bundle.getString("is_not_a_valid_date"), value)); } } }
LocaleBasedDateConverter implements Converter<Date> { public Date convert(String value, Class<? extends Date> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat formatDateTime = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale); try { return formatDateTime.parse(value); } catch (ParseException pe) { DateFormat formatDate = DateFormat.getDateInstance( DateFormat.SHORT, locale); try { return formatDate.parse(value); } catch (ParseException pe1) { throw new ConversionError(MessageFormat.format( bundle.getString("is_not_a_valid_date"), value)); } } } }
LocaleBasedDateConverter implements Converter<Date> { public Date convert(String value, Class<? extends Date> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat formatDateTime = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale); try { return formatDateTime.parse(value); } catch (ParseException pe) { DateFormat formatDate = DateFormat.getDateInstance( DateFormat.SHORT, locale); try { return formatDate.parse(value); } catch (ParseException pe1) { throw new ConversionError(MessageFormat.format( bundle.getString("is_not_a_valid_date"), value)); } } } LocaleBasedDateConverter(Localization localization); }
LocaleBasedDateConverter implements Converter<Date> { public Date convert(String value, Class<? extends Date> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat formatDateTime = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale); try { return formatDateTime.parse(value); } catch (ParseException pe) { DateFormat formatDate = DateFormat.getDateInstance( DateFormat.SHORT, locale); try { return formatDate.parse(value); } catch (ParseException pe1) { throw new ConversionError(MessageFormat.format( bundle.getString("is_not_a_valid_date"), value)); } } } LocaleBasedDateConverter(Localization localization); Date convert(String value, Class<? extends Date> type, ResourceBundle bundle); }
LocaleBasedDateConverter implements Converter<Date> { public Date convert(String value, Class<? extends Date> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat formatDateTime = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale); try { return formatDateTime.parse(value); } catch (ParseException pe) { DateFormat formatDate = DateFormat.getDateInstance( DateFormat.SHORT, locale); try { return formatDate.parse(value); } catch (ParseException pe1) { throw new ConversionError(MessageFormat.format( bundle.getString("is_not_a_valid_date"), value)); } } } LocaleBasedDateConverter(Localization localization); Date convert(String value, Class<? extends Date> type, ResourceBundle bundle);  }