Skip to content

Commit 51990e8

Browse files
committed
Merge pull request OfficeDev#420 from itbw/meetingtimezone
AbsoluteDate and Time by TimeChange fix
2 parents d2a1930 + b73923b commit 51990e8

2 files changed

Lines changed: 112 additions & 9 deletions

File tree

src/main/java/microsoft/exchange/webservices/data/property/complex/TimeChange.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
3333
import microsoft.exchange.webservices.data.misc.Time;
3434
import microsoft.exchange.webservices.data.misc.TimeSpan;
35+
3536
import org.apache.commons.logging.Log;
3637
import org.apache.commons.logging.LogFactory;
3738

38-
import java.text.SimpleDateFormat;
39+
import java.util.Calendar;
3940
import java.util.Date;
41+
import java.util.TimeZone;
42+
43+
import javax.xml.bind.DatatypeConverter;
4044

4145
/**
4246
* Represents a change of time for a time zone.
@@ -217,16 +221,13 @@ public boolean tryReadElementFromXml(EwsServiceXmlReader reader)
217221
return true;
218222
} else if (reader.getLocalName().equalsIgnoreCase(
219223
XmlElementNames.AbsoluteDate)) {
220-
SimpleDateFormat sdfin = new SimpleDateFormat(
221-
"yyyy-MM-dd'T'HH:mm:ss");
222-
Date tempDate = sdfin.parse(reader.readElementValue());
223-
this.absoluteDate = tempDate;
224+
Calendar cal = DatatypeConverter.parseDate(reader.readElementValue());
225+
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
226+
this.absoluteDate = cal.getTime();
224227
return true;
225228
} else if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Time)) {
226-
SimpleDateFormat sdfin = new SimpleDateFormat(
227-
"yyyy-MM-dd'T'HH:mm:ss");
228-
Date tempDate = sdfin.parse(reader.readElementValue());
229-
this.time = new Time(tempDate);
229+
Calendar cal = DatatypeConverter.parseTime(reader.readElementValue());
230+
this.time = new Time(cal.getTime());
230231
return true;
231232
} else {
232233
return false;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* The MIT License Copyright (c) 2012 Microsoft Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5+
* associated documentation files (the "Software"), to deal in the Software without restriction,
6+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
7+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in all copies or
11+
* substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
*/
19+
20+
21+
package microsoft.exchange.webservices.data.property.complex;
22+
23+
import java.util.Calendar;
24+
import java.util.TimeZone;
25+
26+
import javax.xml.bind.DatatypeConverter;
27+
28+
import microsoft.exchange.webservices.data.core.EwsUtilities;
29+
import microsoft.exchange.webservices.data.misc.Time;
30+
31+
import org.junit.Assert;
32+
import org.junit.Test;
33+
import org.junit.runner.RunWith;
34+
import org.junit.runners.JUnit4;
35+
36+
@RunWith(JUnit4.class)
37+
public class TimeChangeTest {
38+
39+
private static String time = "03:00:00";
40+
private static String time_fail1 = "21:32";
41+
private static String time_fail2 = "25:25:10";
42+
private static String time_fail3 = "-10:00:00";
43+
44+
private static String dateUTC = "2001-10-27Z";
45+
private static String date_fail1 = "2001-10-32";
46+
private static String date_fail2 = "2001-13-26+02:00";
47+
private static String date_fail3 = "01-10-26";
48+
49+
@Test
50+
public void testDateUTC() {
51+
Assert.assertEquals("2001-10-27Z", testDate(dateUTC));
52+
}
53+
54+
private String testDate(String value) {
55+
Calendar cal = DatatypeConverter.parseDate(value);
56+
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
57+
String XSDate = EwsUtilities.dateTimeToXSDate(cal.getTime());
58+
return XSDate;
59+
}
60+
61+
@Test(expected = IllegalArgumentException.class)
62+
public void testDateFail1() {
63+
testDate(date_fail1);
64+
}
65+
66+
@Test(expected = IllegalArgumentException.class)
67+
public void testDateFail2() {
68+
testDate(date_fail2);
69+
}
70+
71+
@Test(expected = IllegalArgumentException.class)
72+
public void testDateFail3() {
73+
testDate(date_fail3);
74+
}
75+
76+
private String testTime(String value) {
77+
Calendar cal = DatatypeConverter.parseTime(value);
78+
Time time = new Time(cal.getTime());
79+
return time.toXSTime();
80+
}
81+
82+
@Test(expected = IllegalArgumentException.class)
83+
public void testTimeFail1() {
84+
testTime(time_fail1);
85+
}
86+
87+
@Test(expected = IllegalArgumentException.class)
88+
public void testTimeFail2() {
89+
testTime(time_fail2);
90+
}
91+
92+
@Test(expected = IllegalArgumentException.class)
93+
public void testTimeFail3() {
94+
testTime(time_fail3);
95+
}
96+
97+
@Test
98+
public void testTimeValues() {
99+
Assert.assertEquals("{0:00}:{1:00}:{2:00},3,0,0", testTime(time));
100+
}
101+
102+
}

0 commit comments

Comments
 (0)