Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.4</version>
</dependency>


</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected String getXmlElementName() {
*/
protected void setupRecurrence(Recurrence recurrence) throws Exception {
super.setupRecurrence(recurrence);
this.endDate = recurrence.getEndDate();
recurrence.setEndDate(this.endDate);
}

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ protected boolean tryReadElementFromXml(EwsServiceXmlReader reader)
} else {
if (reader.getLocalName().equals(XmlElementNames.EndDate)) {

Date temp = reader.readElementValueAsDateTime();
Date temp = reader.readElementValueAsUnspecifiedDate();

if(temp!=null) {
this.endDate = temp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
**************************************************************************/
package microsoft.exchange.webservices.data;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
Expand Down Expand Up @@ -877,8 +882,9 @@ protected static void validateParamCollection(EventType[] eventTypes,
*/
static String dateTimeToXSDate(Date date) {
String format = "yyyy-MM-dd'Z'";
DateFormat utcFormatter = new SimpleDateFormat(format);
return utcFormatter.format(date);
DateTimeFormatter utcFormatter = DateTimeFormat.forPattern(format);
String formatted = utcFormatter.print(new DateTime(date.getTime(), DateTimeZone.UTC));
return formatted;
}

/**
Expand All @@ -890,8 +896,9 @@ static String dateTimeToXSDate(Date date) {
*/
protected static String dateTimeToXSDateTime(Date date) {
String format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
DateFormat utcFormatter = new SimpleDateFormat(format);
return utcFormatter.format(date);
DateTimeFormatter utcFormatter = DateTimeFormat.forPattern(format);
String formatted = utcFormatter.print(new DateTime(date.getTime(), DateTimeZone.UTC));
return formatted;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,21 @@
import java.io.IOException;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Dictionary;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
* Represents an abstract binding to an Exchange Service.
Expand Down Expand Up @@ -479,96 +461,12 @@ private void traceHttpResponseHeaders(TraceFlags traceType,
* @return DateTime Returned date is always in UTC date.
*/
protected Date convertUniversalDateTimeStringToDate(String dateString) {
String localTimeRegex = "^(.*)([+-]{1}\\d\\d:\\d\\d)$";
Pattern localTimePattern = Pattern.compile(localTimeRegex);
String timeRegex = "[0-9]{2,4}-[0-9]{1,2}-[0-9]{1,2}T[0-9]{2}:[0-9]{1,2}:[0-9]{1,2}.[0-9]{1,7}";
Pattern timePattern = Pattern.compile(timeRegex);
String utcPattern = "yyyy-MM-dd'T'HH:mm:ss'Z'";
String utcPattern1 = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'";
String localPattern = "yyyy-MM-dd'T'HH:mm:ssz";
String localPattern1 = "yyyy-MM-dd'Z'";
String pattern = "yyyy-MM-ddz";
String localPattern2 = "yyyy-MM-dd'T'HH:mm:ss";
DateFormat utcFormatter = null;
Date dt = null;
String errMsg = String.format(
"Date String %s not in valid UTC/local format", dateString);
if (dateString == null || dateString.isEmpty()) {
return null;
} else {
if (dateString.endsWith("Z")) {
// String in UTC format yyyy-MM-ddTHH:mm:ssZ
utcFormatter = new SimpleDateFormat(utcPattern);
try {
dt = utcFormatter.parse(dateString);
} catch (ParseException e) {
utcFormatter = new SimpleDateFormat(pattern);
// dateString = dateString.substring(0, 10)+"T12:00:00Z";
try {
dt = utcFormatter.parse(dateString);
} catch (ParseException e1) {
utcFormatter = new SimpleDateFormat(localPattern1);

try {
dt = utcFormatter.parse(dateString);
}catch(ParseException ex){

utcFormatter = new SimpleDateFormat(utcPattern1);
}
try{
dt = utcFormatter.parse(dateString);
}
catch (ParseException e2) {
throw new IllegalArgumentException(errMsg, e);
}

}
// throw new IllegalArgumentException(errMsg,e);
}
} else if (dateString.endsWith("z")) {
// String in UTC format yyyy-MM-ddTHH:mm:ssZ
utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'z'");
try {
dt = utcFormatter.parse(dateString);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
} else {
// dateString is not ending with Z.
// Check for yyyy-MM-ddTHH:mm:ss+/-HH:mm pattern
Matcher localTimeMatcher = localTimePattern.matcher(dateString);
if (localTimeMatcher.find()) {
System.out.println("Pattern matched");
String date = localTimeMatcher.group(1);
String zone = localTimeMatcher.group(2);
// Add the string GMT between DateTime and TimeZone
// since 'z' in yyyy-MM-dd'T'HH:mm:ssz matches
// either format GMT+/-HH:mm or +/-HHmm
dateString = String.format("%sGMT%s", date, zone);
try {
utcFormatter = new SimpleDateFormat(localPattern);
dt = utcFormatter.parse(dateString);
} catch (ParseException e) {
try {
utcFormatter = new SimpleDateFormat(pattern);
dt = utcFormatter.parse(dateString);
} catch (ParseException ex) {
throw new IllegalArgumentException(ex);
}
}
} else {
// Invalid format
utcFormatter = new SimpleDateFormat(localPattern2);
try {
dt = utcFormatter.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
throw new IllegalArgumentException(errMsg);
}
}
}
return dt;
}
if (dateString == null || dateString.isEmpty()) {
return null;
} else {
final Date joda = DateTime.parse(dateString).toDate();
return joda;
}
}

/**
Expand All @@ -580,13 +478,14 @@ protected Date convertUniversalDateTimeStringToDate(String dateString) {
* The string value to parse.
* @return The parsed DateTime value.
*/
protected Date convertStartDateToUnspecifiedDateTime(String value)
protected Date convertStartDateToUnspecifiedDateTime(String value)
throws ParseException {
if (value == null || value.isEmpty()) {
return null;
} else {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'Z'");
return df.parse(value);
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-ddZ");
final Date joda = formatter.parseDateTime(value).toDate();
return joda;
}
}

Expand All @@ -598,11 +497,9 @@ protected Date convertStartDateToUnspecifiedDateTime(String value)
* @return String representation of DateTime in yyyy-MM-ddTHH:mm:ssZ format.
*/
protected String convertDateTimeToUniversalDateTimeString(Date dt) {

DateFormat utcFormatter = null;
DateTime jodaDt = new DateTime(dt.getTime());
String utcPattern = "yyyy-MM-dd'T'HH:mm:ss'Z'";
utcFormatter = new SimpleDateFormat(utcPattern);
return utcFormatter.format(dt);
return jodaDt.toString(DateTimeFormat.forPattern(utcPattern)).toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected String getXmlElementName() {
*/
protected void setupRecurrence(Recurrence recurrence) throws Exception {
super.setupRecurrence(recurrence);
this.numberOfOccurrences = recurrence.getNumberOfOccurrences();
recurrence.setNumberOfOccurrences(this.numberOfOccurrences);
}

/**
Expand Down