org.springframework.format.datetime.joda.DateTimeParser Java Examples

The following examples show how to use org.springframework.format.datetime.joda.DateTimeParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormattingConversionServiceTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #2
Source File: FormattingConversionServiceTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #3
Source File: FormattingConversionServiceTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testFormatFieldForTypeWithPrinterParserWithCoercion() 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);
}