/**************************************************************************
 Exchange Web Services Java API
 Copyright (c) Microsoft Corporation
 All rights reserved.
 MIT License
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 **************************************************************************/

package microsoft.exchange.webservices.data.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateTimeParser {

  private final SimpleDateFormat[] dateTimeFormats = {
      new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"),
      new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"),
      new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"),
      new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"),
      new SimpleDateFormat("yyyy-MM-ddX"),
      new SimpleDateFormat("yyyy-MM-dd")
  };

  private final SimpleDateFormat[] dateFormats = {
      new SimpleDateFormat("yyyy-MM-ddX"),
      new SimpleDateFormat("yyyy-MM-dd")
  };


  public DateTimeParser() {
    // Set default timezone of the formats to UTC, which will be used when the date string doesn't supply a
    // timezone itself.

    for (SimpleDateFormat format : dateTimeFormats) {
      format.setTimeZone(TimeZone.getTimeZone("UTC"));
    }

    for (SimpleDateFormat format : dateFormats) {
      format.setTimeZone(TimeZone.getTimeZone("UTC"));
    }
  }

  /**
   * Converts a date time string to local date time.
   *
   * Note: this method also allows dates without times, in which case the time will be 00:00:00 in the
   * supplied timezone. UTC timezone will be assumed if no timezone is supplied.
   *
   * @param value The string value to parse.
   * @return The parsed {@link Date}.
   *
   * @throws java.lang.IllegalArgumentException If string can not be parsed.
   */
  public Date convertDateTimeStringToDate(String value) {
    return parseInternal(value, false);
  }

  /**
   * Converts a date string to local date time.
   *
   * UTC timezone will be assumed if no timezone is supplied.
   *
   * @param value The string value to parse.
   * @return The parsed {@link Date}.
   *
   * @throws java.lang.IllegalArgumentException If string can not be parsed.
   */
  public Date convertDateStringToDate(String value) {
    return parseInternal(value, true);
  }

  private Date parseInternal(String value, boolean dateOnly) {
    String originalValue = value;

    if (value == null || value.isEmpty()) {
      return null;
    } else {
      if (value.endsWith("z")) {
        // This seems to be an edge case. Let's uppercase the Z to be sure.
        value = value.substring(0, value.length() - 1) + "Z";
      }

      SimpleDateFormat[] formats = dateOnly ? dateFormats : dateTimeFormats;
      for (SimpleDateFormat format : formats) {
        try {
          return format.parse(value);
        } catch (ParseException e) {
          // Ignore and try the next pattern.
        }
      }
    }

    throw new IllegalArgumentException(
        String.format("Date String %s not in valid UTC/local format", originalValue));
  }
}

@@ -1339,68 +1339,92 @@
 ort 
-java.text.ParseException;%0Aimport java.text.SimpleDat
+org.joda.time.format.DateTimeFormat;%0Aimport org.joda.time.format.DateTim
 eFormat
-;
+ter;%0A
 %0Aimp
@@ -1446,35 +1446,8 @@
 ate;
-%0Aimport java.util.TimeZone;
 %0A%0Apu
@@ -1491,32 +1491,33 @@
 e final 
-SimpleDat
+DateTim
 eFormat
+ter
 %5B%5D dateT
@@ -1537,36 +1537,41 @@
 %7B%0A      
-new SimpleDateForm
+DateTimeFormat.forP
 at
+tern
 (%22yyyy-M
@@ -1589,39 +1589,58 @@
 m:ss
-X%22),%0A      new SimpleDateForm
+Z%22).withZoneUTC(),%0A      DateTimeFormat.forP
 at
+tern
 (%22yy
@@ -1666,39 +1666,58 @@
 .SSS
-X%22),%0A      new SimpleDateForm
+Z%22).withZoneUTC(),%0A      DateTimeFormat.forP
 at
+tern
 (%22yy
@@ -1741,93 +1741,131 @@
 ss%22)
-,%0A      new SimpleDateFormat(%22yyyy-MM-dd'T'HH:mm:ss.SSS%22),%0A      new SimpleDateFormat
+.withZoneUTC(),%0A      DateTimeFormat.forPattern(%22yyyy-MM-dd'T'HH:mm:ss.SSS%22).withZoneUTC(),%0A      DateTimeFormat.forPattern
 (%22yy
@@ -1876,39 +1876,58 @@
 M-dd
-X%22),%0A      new SimpleDateForm
+Z%22).withZoneUTC(),%0A      DateTimeFormat.forP
 at
+tern
 (%22yy
@@ -1932,24 +1932,38 @@
 yyyy-MM-dd%22)
+.withZoneUTC()
 %0A  %7D;%0A%0A  pri
@@ -1973,32 +1973,33 @@
 e final 
-SimpleDat
+DateTim
 eFormat
+ter
 %5B%5D dateF
@@ -2019,71 +2019,33 @@
     
-new SimpleDateFormat(%22yyyy-MM-ddX%22),%0A      new SimpleDateForm
+DateTimeFormat.forP
 at
+tern
 (%22yy
@@ -2056,409 +2056,92 @@
 M-dd
+Z
 %22)
-%0A  %7D;%0A%0A%0A  public DateTimeParser() %7B%0A    // Set default timezone of the formats to UTC, which will be used when the date string doesn't supply a%0A    // timezone itself.%0A%0A    for (SimpleDateFormat format : dateTimeFormats) %7B%0A      format.setTimeZone(TimeZone.getTimeZone(%22UTC%22));%0A    %7D%0A%0A    for (SimpleDateFormat format : dateFormats) %7B%0A      format.setTimeZone(TimeZone.getTime
+.withZoneUTC(),%0A      DateTimeFormat.forPattern(%22yyyy-MM-dd%22).with
 Zone
-(%22
 UTC
-%22));%0A    %7D%0A  %7D
+()%0A  %7D;%0A
 %0A%0A  
@@ -3420,32 +3420,33 @@
 %0A%0A      
-SimpleDat
+DateTim
 eFormat
+ter
 %5B%5D forma
@@ -3507,24 +3507,25 @@
 or (
-SimpleDat
+DateTim
 eFormat
+ter
  for
@@ -3584,22 +3584,39 @@
 at.parse
-(value
+DateTime(value).toDate(
 );%0A     
@@ -3627,21 +3627,31 @@
  catch (
-Parse
+IllegalArgument
 Exceptio

Update DateTimeParser to use joda-time, because Java 6 lacks proper timezone parsing support.