0

I need to parse ISO 8601 Week dates into a format that Joda-Time can hopefully work with (eg. use for calculating the days in that week, etc.)

I've looked around a bit, but there doesn't seem to be any clear docs on how to do this.

A full DateTime instance isn't right, since I don't have an Instant in time, I only have a Partial. I can't seem to find any way to parse things into a Partial, however.

Do I need to write my own parse() method that can give me back a partial? There seem to be a couple of built-in parse methods that do this, but they all seem very specific and don't take a general format object.

Specifically, I have ISO 8601 Week dates in the following forms:

1998-W12
2005W23

What I need to do with these (ultimately) is take the week, and then convert that into a collection of the days in a given week (LocalDate JodaTime objects specifically). eg.

2013-W52 =>
2013-12-31
2014-01-01
2014-01-02
2014-01-03
2014-01-04
2014-01-05
2014-01-06
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
cdeszaq
  • 30,869
  • 25
  • 117
  • 173
  • I've only done extensive searching at this point, since I tend to figure out how to correctly use an API before trying to slam my way through it. Joda has all the concepts, but doesn't seem to have the flexibility to parse things into `Partial`s in the same way that it can parse `Instant`s. Since I can't find anything to point me towards a solution with extensive searching, and I'm hopefully just missing something in the API, I asked this question. – cdeszaq Mar 05 '14 at 21:30
  • That makes sense. The edit convinced me :) – Blue Ice Mar 05 '14 at 23:31
  • @cdeszaq What exactly is your input, and what exactly is your desired output? Do you have a pair of date-time values defining a week? Do you have week-of-year number number (integer)? Do you have a [ISO week date](http://en.wikipedia.org/wiki/ISO_week_date) such as `2006-W52-7` which is last day of week (Sunday) of 52nd week of 2006? Show some example data. – Basil Bourque Mar 06 '14 at 05:39
  • @BasilBourque - I added some examples. – cdeszaq Mar 06 '14 at 15:52

1 Answers1

2

JodaTime has ISO-8601 support built in. Look at the ISODateTimeFormatter. http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html

ninnemannk
  • 1,296
  • 1
  • 14
  • 26