private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
@Test public void formatFieldForTypeWithPrinterParserWithCoercion() throws ParseException { formattingService.addConverter(new Converter<DateTime, LocalDate>() { @Override public LocalDate convert(DateTime source) { return source.toLocalDate(); } }); formattingService.addFormatterForFieldType(LocalDate.class, new ReadablePartialPrinter(DateTimeFormat .shortDate()), new DateTimeParser(DateTimeFormat.shortDate())); String formatted = formattingService.convert(new LocalDate(2009, 10, 31), String.class); assertEquals("10/31/09", formatted); LocalDate date = formattingService.convert("10/31/09", LocalDate.class); assertEquals(new LocalDate(2009, 10, 31), date); }
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
public DateContext(Date date, Locale locale) { DateTime dt = new DateTime(date); shortDate = DateTimeFormat.shortDate().withLocale(locale).print(dt); longDate = DateTimeFormat.longDate().withLocale(locale).print(dt); dayOfMonth = dt.getDayOfMonth(); monthOfYear = dt.getMonthOfYear(); year = dt.getYear(); time = dt.toDate().getTime(); dateTime = dt.toString(); }
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
public LocalDate convert(String value, Class<? extends LocalDate> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDate()); if (out == null) { return null; } return out.toLocalDate(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value)); } } }
public DateMidnight convert(String value, Class<? extends DateMidnight> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDate()); if (out == null) { return null; } return out.toDateMidnight(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } } }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { int cafeteriaId = mensaManager.getBestMatchMensaId(); Cafeteria cafeteria = localRepository.getCafeteria(cafeteriaId); for (int appWidgetId : appWidgetIds) { RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.mensa_widget); // TODO: Investigate how this can be null // Set the header for the Widget layout if (cafeteria != null) { rv.setTextViewText(R.id.mensa_widget_header, cafeteria.getName()); } // Set the properly formatted date in the subhead LocalDate localDate = DateTime.now().toLocalDate(); String date = DateTimeFormat.shortDate().print(localDate); rv.setTextViewText(R.id.mensa_widget_subhead, date); // Set the header on click to open the mensa activity Intent mensaIntent = new Intent(context, CafeteriaActivity.class); mensaIntent.putExtra(Const.CAFETERIA_ID, mensaManager.getBestMatchMensaId()); PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, mensaIntent, 0); rv.setOnClickPendingIntent(R.id.mensa_widget_header_container, pendingIntent); // Set the adapter for the list view in the mensa widget Intent intent = new Intent(context, MensaWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); rv.setRemoteAdapter(R.id.food_item, intent); rv.setEmptyView(R.id.empty_view, R.id.empty_view); appWidgetManager.updateAppWidget(appWidgetId, rv); } }