List of usage examples for org.joda.time.format DateTimeFormat shortDate
public static DateTimeFormatter shortDate()
From source file:org.emonocot.portal.view.Functions.java
License:Open Source License
public static String formatDateRange(String dateRange) { Matcher matcher = pattern.matcher(dateRange); if (matcher.matches()) { String beginningString = matcher.group(1); String endString = matcher.group(2); DateTime beginning = solrDateTimeFormatter.parseDateTime(beginningString); DateTime end = solrDateTimeFormatter.parseDateTime(endString); Integer gap = Integer.parseInt(matcher.group(3)); String increment = matcher.group(4); DateTimeFormatter dateTimeFormatter = null; switch (increment) { case "DAY": end = end.plusDays(gap);//from w w w . j av a 2 s .c o m dateTimeFormatter = DateTimeFormat.shortDate(); break; case "WEEK": end = end.plusWeeks(gap); dateTimeFormatter = DateTimeFormat.shortDate(); break; case "MONTH": end = end.plusMonths(gap); dateTimeFormatter = DateTimeFormat.forPattern("yyyy/MM"); break; case "YEAR": end = end.plusYears(gap); dateTimeFormatter = DateTimeFormat.forPattern("yyyy"); break; } return dateTimeFormatter.print(beginning) + " - " + dateTimeFormatter.print(end); } else { return dateRange; } }
From source file:org.mayocat.shop.front.context.DateContext.java
License:Mozilla Public License
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();//from w w w.j a v a 2s. c o m monthOfYear = dt.getMonthOfYear(); year = dt.getYear(); time = dt.toDate().getTime(); dateTime = dt.toString(); }
From source file:org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar.java
License:Apache License
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE:// w ww . j a va 2 s . com return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
From source file:org.springframework.format.datetime.joda.JodaTimeFormattingConfigurer.java
License:Apache License
private DateTimeFormatter getJodaDateFormatter() { if (this.useIsoFormat) { return ISODateTimeFormat.date(); }//w w w . ja v a 2s . c om if (this.dateStyle != null) { return DateTimeFormat.forStyle(this.dateStyle + "-"); } else { return DateTimeFormat.shortDate(); } }
From source file:org.vaadin.addons.javaee.fields.converter.StringToDateTimeConverter.java
License:Apache License
@Override public DateTime convertToModel(String value, Class<? extends DateTime> targetType, Locale locale) throws Converter.ConversionException { if (value == null) { return null; }/*from w ww. j a va 2 s.co m*/ return DateTime.parse(value, DateTimeFormat.shortDate().withLocale(locale)); }
From source file:org.vaadin.addons.javaee.fields.converter.StringToDateTimeConverter.java
License:Apache License
@Override public String convertToPresentation(DateTime value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { if (value == null) { return null; }/*from ww w . j a va 2 s. c o m*/ return value.toString(DateTimeFormat.shortDate().withLocale(locale)); }
From source file:org.vaadin.addons.javaee.fields.converter.StringToLocalDateConverter.java
License:Apache License
@Override public LocalDate convertToModel(String value, Class<? extends LocalDate> targetType, Locale locale) throws Converter.ConversionException { if (value == null) { return null; }/*from w w w. j av a2 s . co m*/ return LocalDate.parse(value, DateTimeFormat.shortDate().withLocale(locale)); }
From source file:org.vaadin.addons.javaee.fields.converter.StringToLocalDateConverter.java
License:Apache License
@Override public String convertToPresentation(LocalDate value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { if (value == null) { return null; }//from www . ja v a 2 s. c o m return value.toString(DateTimeFormat.shortDate().withLocale(locale)); }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * Initialize the {@link LocalDate} converter for the text field. *///from w w w . j a v a2 s .co m private void initConverter() { Converter<String, LocalDate> converter = new Converter<String, LocalDate>() { private static final long serialVersionUID = -2161506497954814519L; @Override public LocalDate convertToModel(String value, Class<? extends LocalDate> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; } LocalDate modelValue = null; try { DateTimeFormatter dateTimeFormatter; if (dateTimeFormatterPattern == null) { dateTimeFormatter = DateTimeFormat.shortDate().withLocale(locale); } else { dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatterPattern).withLocale(locale); } modelValue = dateTimeFormatter.parseLocalDate(value); } catch (IllegalArgumentException e) { throw new ConversionException("Cannot convert to model", e); } return modelValue; } @Override public String convertToPresentation(LocalDate value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value == null) { return null; } String presentationValue = null; try { DateTimeFormatter dateTimeFormatter; if (dateTimeFormatterPattern == null) { dateTimeFormatter = DateTimeFormat.shortDate().withLocale(locale); } else { dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatterPattern).withLocale(locale); } presentationValue = dateTimeFormatter.print(value); } catch (IllegalArgumentException e) { throw new ConversionException("Cannot convert to presentation", e); } return presentationValue; } @Override public Class<LocalDate> getModelType() { return LocalDate.class; } @Override public Class<String> getPresentationType() { return String.class; } }; setConverter(converter); }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
protected void registerRpc() { registerRpc(new TuningDateFieldRpc() { private static final long serialVersionUID = 3572898507878457932L; @Override/*w w w. j av a 2s.c o m*/ public void onCalendarOpen() { TuningDateField.this.onCalendarOpen(); } @Override public void onCalendarClosed() { calendarOpen = false; markAsDirty(); } @Override public void calendarItemClicked(Integer itemIndex, Integer relativeDateIndex, MouseEventDetails mouseDetails) { onCalendarItemClicked(itemIndex, relativeDateIndex, mouseDetails); } @Override public void dateTextChanged(String dateText) { try { // First try to convert to model in order to check if text is parseable if (dateText != null) { DateTimeFormatter dateTimeFormatter; if (dateTimeFormatterPattern == null) { dateTimeFormatter = DateTimeFormat.shortDate().withLocale(getLocale()); } else { dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatterPattern) .withLocale(getLocale()); } dateTimeFormatter.parseLocalDate(dateText); } // If parsing text is successful, set value uiHasValidDateString = true; setComponentError(null); setValue(dateText); } catch (IllegalArgumentException e) { // Date is not parseable, keep previous value uiHasValidDateString = false; markAsDirty(); } } @Override public void previousControlClicked() { if (controlsEnabled) { goToPreviousCalendarPage(); } else { // wtf ? should never happen } } @Override public void nextControlClicked() { if (controlsEnabled) { goToNextCalendarPage(); } else { // wtf ? should never happen } } @Override public void resolutionControlClicked() { if (controlsEnabled) { swithToHigherCalendarResolution(); } else { // wtf ? should never happen } } }); }