4

I'd love to be able to parse relative strings like now and yesterday and get JodaTime DateTimes. Is it possible? DateTimeFormat.forPattern and doesn't seem to support English relative times and I don't know of any other parsing options in JodaTime.

I should add that I'm using scala-time but can easily drop down to the actual JodaTime classes.

pr1001
  • 21,727
  • 17
  • 79
  • 125
  • I'm not sure I understand the question. Can you illustrate an example of what you would like to do? – Ichorus Dec 18 '09 at 02:32

2 Answers2

4

You would need to write either a separate library, or a DateTimeParser. DateTimeParser is the interface used internally by Joda-Time to parse text. Anyone can implement it and plug it directly into the Joda-Time parsing system using DateTimeFormatterBuilder.

JodaStephen
  • 60,927
  • 15
  • 95
  • 117
1

Let's see here - "now", "yesterday", "today", "tomorrow". Is that about it? :-)

JodaTime won't parse them for you but it should be trivial enough to write your own function (or enum) to do so; you can even throw in stuff like "day after tomorrow" if you feel like it.

"Now" seems to be the only value for which DateTime would be appropriate, though - all others look more like LocalDate (or, possibly, DateMidnight) to me.

ChssPly76
  • 99,456
  • 24
  • 206
  • 195