org.springframework.format.annotation.DateTimeFormat.ISO Java Examples

The following examples show how to use org.springframework.format.annotation.DateTimeFormat.ISO. 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: ChainController.java    From WeBASE-Node-Manager with Apache License 2.0 6 votes vote down vote up
@GetMapping(value = "/mointorInfo/{frontId}")
public BaseResponse getChainMoinntorInfo(@PathVariable("frontId") Integer frontId,
    @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime beginDate,
    @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime endDate,
    @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime contrastBeginDate,
    @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime contrastEndDate,
    @RequestParam(required = false, defaultValue = "1") int gap,
    @RequestParam(required = false, defaultValue = "1") int groupId)
    throws NodeMgrException {
    Instant startTime = Instant.now();
    BaseResponse response = new BaseResponse(ConstantCode.SUCCESS);
    log.info(
        "start getChainInfo. startTime:{} frontId:{} beginDate:{} endDate:{} "
            + "contrastBeginDate:{} contrastEndDate:{} gap:{} groupId:{}", startTime.toEpochMilli(),
        frontId, beginDate, endDate, contrastBeginDate, contrastEndDate, gap,groupId);
    Object rspObj = chainService
        .getChainMonitorInfo(frontId, beginDate, endDate, contrastBeginDate, contrastEndDate,
            gap,groupId);

    response.setData(rspObj);
    log.info("end getChainInfo. endTime:{} response:{}",
        Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response));

    return response;
}
 
Example #2
Source File: DateFormatterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseCorrectOrder() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setStyle(DateFormat.SHORT);
	formatter.setStylePattern("L-");
	formatter.setIso(ISO.DATE_TIME);
	formatter.setPattern("yyyy");
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);

	assertThat("uses pattern",formatter.print(date, Locale.US), is("2009"));

	formatter.setPattern("");
	assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));

	formatter.setIso(ISO.NONE);
	assertThat("uses style pattern", formatter.print(date, Locale.US), is("June 1, 2009"));

	formatter.setStylePattern("");
	assertThat("uses style", formatter.print(date, Locale.US), is("6/1/09"));
}
 
Example #3
Source File: EventController.java    From sos with Apache License 2.0 6 votes vote down vote up
@GetMapping("events")
HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler,
		@SortDefault("publicationDate") Pageable pageable,
		@RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since,
		@RequestParam(required = false) String type) {

	QAbstractEvent $ = QAbstractEvent.abstractEvent;

	BooleanBuilder builder = new BooleanBuilder();

	// Apply date
	Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it)));

	// Apply type
	Optional.ofNullable(type) //
			.flatMap(events::findEventTypeByName) //
			.ifPresent(it -> builder.and($.instanceOf(it)));

	Page<AbstractEvent<?>> result = events.findAll(builder, pageable);

	PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event));
	resource
			.add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events"));

	return ResponseEntity.ok(resource);
}
 
Example #4
Source File: DateFormatterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void shouldUseCorrectOrder() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setStyle(DateFormat.SHORT);
	formatter.setStylePattern("L-");
	formatter.setIso(ISO.DATE_TIME);
	formatter.setPattern("yyyy");
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);

	assertThat("uses pattern",formatter.print(date, Locale.US), is("2009"));

	formatter.setPattern("");
	assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));

	formatter.setIso(ISO.NONE);
	assertThat("uses style pattern", formatter.print(date, Locale.US), is("June 1, 2009"));

	formatter.setStylePattern("");
	assertThat("uses style", formatter.print(date, Locale.US), is("6/1/09"));
}
 
Example #5
Source File: ZonedDateTimeFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE_TIME)
public ZonedDateTimeFilter setIn(List<ZonedDateTime> in) {
    super.setIn(in);
    return this;
}
 
Example #6
Source File: DateFormatterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPrintAndParseISOTime() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.TIME);
	Date date = getDate(2009, Calendar.JANUARY, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("14:23:05.003+0000"));
	assertThat(formatter.parse("14:23:05.003+0000", Locale.US),
			is(getDate(1970, Calendar.JANUARY, 1, 14, 23, 5, 3)));
}
 
Example #7
Source File: LocalDateFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE)
public LocalDateFilter setGreaterThan(LocalDate equals) {
    super.setGreaterThan(equals);
    return this;
}
 
Example #8
Source File: LocalDateFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE)
@Deprecated
public LocalDateFilter setGreaterOrEqualThan(LocalDate equals) {
    super.setGreaterOrEqualThan(equals);
    return this;
}
 
Example #9
Source File: DateFormattingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void stringToDateWithGlobalFormat() throws Exception {
	// SPR-10105
	DateFormatterRegistrar registrar = new DateFormatterRegistrar();
	DateFormatter dateFormatter = new DateFormatter();
	dateFormatter.setIso(ISO.DATE_TIME);
	registrar.setFormatter(dateFormatter);
	setUp(registrar);
	// This is a format that cannot be parsed by new Date(String)
	String string = "2009-06-01T14:23:05.003+0000";
	Date date = this.conversionService.convert(string, Date.class);
	assertNotNull(date);
}
 
Example #10
Source File: DateFormatterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPrintAndParseISODateTime() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.DATE_TIME);
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));
	assertThat(formatter.parse("2009-06-01T14:23:05.003+0000", Locale.US), is(date));
}
 
Example #11
Source File: InstantFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE_TIME)
public InstantFilter setGreaterThanOrEqual(Instant equals) {
    super.setGreaterThanOrEqual(equals);
    return this;
}
 
Example #12
Source File: DateTimeFormatterFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormatter.ofPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE;
				break;
			case TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_TIME;
				break;
			case DATE_TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (this.dateStyle != null && this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
	}
	else if (this.dateStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle);
	}
	else if (this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example #13
Source File: DateTimeFormatterFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void createDateTimeFormatterInOrderOfPropertyPriority() throws Exception {
	factory.setStyle("SS");
	String value = applyLocale(factory.createDateTimeFormatter()).print(dateTime);
	assertTrue(value.startsWith("10/21/09"));
	assertTrue(value.endsWith("12:10 PM"));

	factory.setIso(ISO.DATE);
	assertThat(applyLocale(factory.createDateTimeFormatter()).print(dateTime), is("2009-10-21"));

	factory.setPattern("yyyyMMddHHmmss");
	assertThat(factory.createDateTimeFormatter().print(dateTime), is("20091021121000"));
}
 
Example #14
Source File: JodaTimeFormattingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void stringToDateWithGlobalFormat() throws Exception {
	// SPR-10105
	JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
	DateTimeFormatterFactory factory = new DateTimeFormatterFactory();
	factory.setIso(ISO.DATE_TIME);
	registrar.setDateTimeFormatter(factory.createDateTimeFormatter());
	setUp(registrar);
	// This is a format that cannot be parsed by new Date(String)
	String string = "2009-10-31T07:00:00.000-05:00";
	Date date = this.conversionService.convert(string, Date.class);
	assertNotNull(date);
}
 
Example #15
Source File: DateTimeFormatterFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example #16
Source File: DateFormatterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPrintAndParseISODate() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.DATE);
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("2009-06-01"));
	assertThat(formatter.parse("2009-6-01", Locale.US),
			is(getDate(2009, Calendar.JUNE, 1)));
}
 
Example #17
Source File: DateTimeFormatterFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use
 * when no specific factory properties have been set
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		// Using strict parsing to align with Joda-Time and standard DateFormat behavior:
		// otherwise, an overflow like e.g. Feb 29 for a non-leap-year wouldn't get rejected.
		// However, with strict parsing, a year digit needs to be specified as 'u'...
		String patternToUse = StringUtils.replace(this.pattern, "yy", "uu");
		dateTimeFormatter = DateTimeFormatter.ofPattern(patternToUse).withResolverStyle(ResolverStyle.STRICT);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE;
				break;
			case TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_TIME;
				break;
			case DATE_TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (this.dateStyle != null && this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
	}
	else if (this.dateStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle);
	}
	else if (this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example #18
Source File: PerformanceController.java    From WeBASE-Node-Manager with Apache License 2.0 5 votes vote down vote up
/**
 * get ratio of performance.
 */
@GetMapping(value = "/ratio/{frontId}")
public BaseResponse getPerformanceRatio(@PathVariable("frontId") Integer frontId,
    @RequestParam("beginDate") @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime beginDate,
    @RequestParam("endDate") @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime endDate,
    @RequestParam(value = "contrastBeginDate", required = false)
    @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime contrastBeginDate,
    @RequestParam(value = "contrastEndDate", required = false)
    @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime contrastEndDate,
    @RequestParam(value = "gap", required = false, defaultValue = "1") int gap)
    throws NodeMgrException {
    Instant startTime = Instant.now();
    BaseResponse response = new BaseResponse(ConstantCode.SUCCESS);
    log.info(
        "start getPerformanceRatio. startTime:{} frontId:{} beginDate:{}"
            + " endDate:{} contrastBeginDate:{} contrastEndDate:{} gap:{}",
        startTime.toEpochMilli(), frontId, beginDate, endDate, contrastBeginDate,
        contrastEndDate, gap);

    Object rspObj = performanceService
        .getPerformanceRatio(frontId, beginDate, endDate, contrastBeginDate, contrastEndDate,
            gap);
    response.setData(rspObj);
    log.info("end getPerformanceRatio. useTime:{} response:{}",
        Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response));

    return response;
}
 
Example #19
Source File: DateFormatterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldParseIsoTimeWithZeros() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setIso(ISO.TIME);
	Date date = formatter.parse("12:00:00.000-00005", Locale.US);
	System.out.println(date);
}
 
Example #20
Source File: UserAPIController.java    From onboard with Apache License 2.0 5 votes vote down vote up
/**
 * 看一个人完成的所有todo
 * 
 * @param companyId
 * @param userId
 * @param model
 * @return
 */
@RequestMapping(value = "/{companyId}/user/{userId}/completed_todos", method = RequestMethod.GET)
@Interceptors({ CompanyMemberRequired.class, UserChecking.class })
@ResponseBody
public Map<String, Object> viewUserCompletedTodos(@PathVariable int companyId, @PathVariable int userId,
        @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until, Model model) {
    Builder<String, Object> builder = ImmutableMap.builder();
    DateTime dt = until == null ? new DateTime() : new DateTime(until);
    until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate();
    List<Integer> projectList = getProjectListOfCurrentUser(companyId);

    TreeMap<Date, List<Todolist>> map = todoService.getCompletedTodolistsGroupByDateByUser(companyId, userId,
            projectList, until, PER_PAGE);
    TreeMap<String, List<TodolistDTO>> mapDTO = makeUserCompletedTodosMapSerilizable(map);
    builder.put("completedTodos", mapDTO);
    Map<Integer, String> projectIdToName = getProjectIdAndNameByCompanyId(companyId);
    builder.put("projectsName", projectIdToName);

    boolean hasNext = false;

    if (map != null && map.size() > 0) {
        Date newUntil = new DateTime(map.lastKey()).withTime(0, 0, 0, 0).plusMillis(-1).toDate();

        TreeMap<Date, List<Todolist>> nextMap = todoService.getCompletedTodolistsGroupByDateByUser(companyId,
                userId, projectList, newUntil, PER_PAGE);
        hasNext = nextMap.size() > 0;
        builder.put("nextPage", dtf.print(new DateTime(newUntil)));
    }

    builder.put("hasNext", hasNext);

    return builder.build();
}
 
Example #21
Source File: ZonedDateTimeFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE_TIME)
public ZonedDateTimeFilter setGreaterThanOrEqual(ZonedDateTime equals) {
    super.setGreaterThanOrEqual(equals);
    return this;
}
 
Example #22
Source File: DateTimeFormatterFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example #23
Source File: UserAPIController.java    From onboard with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/{companyId}/user/{userId}/activities", method = RequestMethod.GET)
@Interceptors({ CompanyMemberRequired.class, UserChecking.class })
@ResponseBody
public Map<String, Object> viewUserActivities(@PathVariable int companyId, @PathVariable int userId,
        @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until, Model model) {

    Builder<String, Object> builder = ImmutableMap.builder();

    DateTime dt = until == null ? new DateTime() : new DateTime(until);
    until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate();
    List<Integer> projectList = getProjectListOfCurrentUser(companyId);
    TreeMap<Date, List<Activity>> map = activityService.getByUserGroupByDate(companyId, userId, ACTIVITY_PER_PAGE,
            projectList, until);

    TreeMap<String, List<ActivityDTO>> mapDTO = makeMapSerilizable(map);
    builder.put("activities", mapDTO);
    boolean hasNext = false;

    if (map != null && map.size() > 0) {
        Date newUntil = new DateTime(map.lastKey()).plusDays(-1).withTime(0, 0, 0, 0).toDate();
        TreeMap<Date, List<Activity>> nextMap = activityService.getByUserGroupByDate(companyId, userId,
                ACTIVITY_PER_PAGE, projectList, newUntil);
        hasNext = nextMap != null;
        builder.put("nextPage", dtf.print(new DateTime(newUntil)));
    }
    builder.put("hasNext", hasNext);

    return builder.build();
}
 
Example #24
Source File: DateFormattingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test  // SPR-10105
public void stringToDateWithGlobalFormat() {
	DateFormatterRegistrar registrar = new DateFormatterRegistrar();
	DateFormatter dateFormatter = new DateFormatter();
	dateFormatter.setIso(ISO.DATE_TIME);
	registrar.setFormatter(dateFormatter);
	setup(registrar);
	// This is a format that cannot be parsed by new Date(String)
	String string = "2009-06-01T14:23:05.003+00:00";
	Date date = this.conversionService.convert(string, Date.class);
	assertNotNull(date);
}
 
Example #25
Source File: DateFormatterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void shouldPrintAndParseISODateTime() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.DATE_TIME);
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
	assertThat(formatter.parse("2009-06-01T14:23:05.003Z", Locale.US), is(date));
}
 
Example #26
Source File: DateFormatterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void shouldPrintAndParseISODate() throws Exception {
	DateFormatter formatter = new DateFormatter();
	formatter.setTimeZone(UTC);
	formatter.setIso(ISO.DATE);
	Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
	assertThat(formatter.print(date, Locale.US), is("2009-06-01"));
	assertThat(formatter.parse("2009-6-01", Locale.US),
			is(getDate(2009, Calendar.JUNE, 1)));
}
 
Example #27
Source File: DateTimeFormatterFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void createDateTimeFormatterInOrderOfPropertyPriority() {
	factory.setStylePattern("SS");
	String value = applyLocale(factory.createDateTimeFormatter()).format(dateTime);
	assertTrue(value.startsWith("10/21/09"));
	assertTrue(value.endsWith("12:10 PM"));

	factory.setIso(ISO.DATE);
	assertThat(applyLocale(factory.createDateTimeFormatter()).format(dateTime), is("2009-10-21"));

	factory.setPattern("yyyyMMddHHmmss");
	assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000"));
}
 
Example #28
Source File: JodaTimeFormattingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test  // SPR-10105
public void stringToDateWithGlobalFormat() {
	JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
	DateTimeFormatterFactory factory = new DateTimeFormatterFactory();
	factory.setIso(ISO.DATE_TIME);
	registrar.setDateTimeFormatter(factory.createDateTimeFormatter());
	setup(registrar);
	// This is a format that cannot be parsed by new Date(String)
	String string = "2009-10-31T07:00:00.000-05:00";
	Date date = this.conversionService.convert(string, Date.class);
	assertNotNull(date);
}
 
Example #29
Source File: ZonedDateTimeFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE_TIME)
public ZonedDateTimeFilter setEquals(ZonedDateTime equals) {
    super.setEquals(equals);
    return this;
}
 
Example #30
Source File: ZonedDateTimeFilter.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
@DateTimeFormat(iso = ISO.DATE_TIME)
public ZonedDateTimeFilter setNotIn(List<ZonedDateTime> notIn) {
    super.setNotIn(notIn);
    return this;
}