Skip to content

Commit e53047a

Browse files
YakoYako
authored andcommitted
fix issue alibaba#269
1 parent d79a2bf commit e53047a

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/main/java/com/alibaba/fastjson/parser/JSONScanner.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ public boolean scanISO8601DateIfMatch(boolean strict) {
475475
}
476476
}
477477

478+
} else if (timeZoneFlag == 'Z') {// UTC
479+
timzeZoneLength = 1;
480+
if (calendar.getTimeZone().getRawOffset() != 0) {
481+
String[] timeZoneIDs = TimeZone.getAvailableIDs(0);
482+
if (timeZoneIDs.length > 0) {
483+
TimeZone timeZone = TimeZone.getTimeZone(timeZoneIDs[0]);
484+
calendar.setTimeZone(timeZone);
485+
}
486+
}
478487
}
479488

480489
char end = charAt(bp + (20 + millisLen + timzeZoneLength)) ;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.alibaba.json.bvt.serializer;
2+
3+
import java.util.Calendar;
4+
5+
import junit.framework.TestCase;
6+
7+
import org.junit.Assert;
8+
9+
import com.alibaba.fastjson.JSON;
10+
11+
public class DateTest_ISO8601_UTCTime extends TestCase {
12+
13+
public void test_date() throws Exception {
14+
String text = "{\"gmtCreate\":\"2014-10-09T03:07:07.000Z\"}";
15+
16+
Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
17+
Assert.assertNotNull(date);
18+
19+
Assert.assertEquals(0, date.getTimeZone().getRawOffset() / (3600 * 1000));
20+
}
21+
22+
public static class VO {
23+
24+
private Calendar gmtCreate;
25+
26+
public Calendar getGmtCreate() {
27+
return gmtCreate;
28+
}
29+
30+
public void setGmtCreate(Calendar gmtCreate) {
31+
this.gmtCreate = gmtCreate;
32+
}
33+
34+
}
35+
}

0 commit comments

Comments
 (0)