3

I have the below controller for my rest API and it handles negative offset for timezone fine but it complains when i pass +ve offset

public ResponseEntity<?> findStages(@RequestParam(value = "from") @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssZ") DateTime from,
    @RequestParam(value = "to") @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssZ") DateTime to)

For example a "from" value of 2017-07-30T00:00:00.000-00:00 is parsed fine but if i pass +ve offset like 2017-07-30T00:00:00.000+01:00, i get a MethodArgumentTypeMismatchException exception as "Failed to convert value of type 'java.lang.String' to required type 'org.joda.time.DateTime'"

Is it possible to set DateTimeFormat to accept positive offsets?

Sudha Chinnappa
  • 793
  • 4
  • 10
  • 4
    Could be the "+" sign causing problems. You may have to escape it. see https://stackoverflow.com/questions/1005676/urls-and-plus-signs – David Lavender Jul 06 '17 at 11:13
  • Thanks @MrSpoon that helped. using %2B parser the time fine. However when i pass time as 2017-07-30T00:00:00%2B01:00, i receive as 2017-07-29T16:00:00.000-07:00 in my controller, is it possible to retain the timezone sent? – Sudha Chinnappa Jul 06 '17 at 11:34
  • 1
    Check here: https://stackoverflow.com/questions/16794772/joda-time-parse-a-date-with-timezone-and-retain-that-timezone Looks like Joda is losing the timezone when you parse: shifting it into YOUR timezone instead. There's a solution there that might work – David Lavender Jul 06 '17 at 11:39

0 Answers0