This is my scenario: I want to parse time stamps that the user gives me. If the time stamp doesn't have time zone information, I want to assume the time stamp is in the user's timezone, if the timestamp does define it's timezone, use that.
Here are the parts that make it hard:
- I can't set DateTimeZone.setDefault(UserTimeZone) because that will affect all the users on the server, as proven here: Switch Timezone for calculation.
- I can't use withOffsetParsed() because it doesn't tell me if the user explicitly set the timezone or it fell back to the default.
- I can't use withZone() because that overwrites any timezone information in the String.
What I want is something like:
DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser()
DateTimeZone userTimeZone = getUserTimeZone(); //assume -04:00
//returns 2014-05-17T15:36:14+02:00
parser.parseDateTime("2014-05-17T15:36:14+02:00", userTimeZone);
//returns 2014-05-17T15:36:14-04:00
parser.hasTimeZone("2014-05-17T15:36:14", userTimeZone);
Is there any easy way to do this?