@Test public void shouldBeAbleToConvert() { when(request.getAttribute(LOCALE_KEY + ".request")).thenReturn("pt_br"); assertThat(converter.convert("10/06/2008", Calendar.class, bundle), is(equalTo((Calendar) new GregorianCalendar(2008, 5, 10)))); }
public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale); try { Date date = format.parse(value); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value)); } }
LocaleBasedCalendarConverter implements Converter<Calendar> { public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale); try { Date date = format.parse(value); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value)); } } }
LocaleBasedCalendarConverter implements Converter<Calendar> { public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale); try { Date date = format.parse(value); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value)); } } LocaleBasedCalendarConverter(Localization localization); }
LocaleBasedCalendarConverter implements Converter<Calendar> { public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale); try { Date date = format.parse(value); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value)); } } LocaleBasedCalendarConverter(Localization localization); Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle); }
LocaleBasedCalendarConverter implements Converter<Calendar> { public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } Locale locale = localization.getLocale(); if (locale == null) { locale = Locale.getDefault(); } DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale); try { Date date = format.parse(value); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value)); } } LocaleBasedCalendarConverter(Localization localization); Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle);  }