improved date parse support, like ' +800'

This commit is contained in:
shaojin.wensj
2018-12-18 19:01:55 +08:00
parent cc4bdc6639
commit 308968dd54
3 changed files with 14 additions and 3 deletions
+3 -3
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.55_preview_01</version>
<version>1.2.55_preview_05</version>
<packaging>jar</packaging>
<name>fastjson</name>
@@ -464,14 +464,14 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.1.3-2</version>
<version>1.1.51</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>1.1.3-2</version>
<version>1.1.51</version>
<scope>test</scope>
</dependency>
@@ -587,6 +587,12 @@ public final class JSONScanner extends JSONLexerBase {
int timzeZoneLength = 0;
char timeZoneFlag = charAt(bp + date_len + 10 + millisLen);
if (timeZoneFlag == ' ') {
millisLen++;
timeZoneFlag = charAt(bp + date_len + 10 + millisLen);
}
if (timeZoneFlag == '+' || timeZoneFlag == '-') {
char t0 = charAt(bp + date_len + 10 + millisLen + 1);
if (t0 < '0' || t0 > '1') {
@@ -32,4 +32,9 @@ public class DateTest extends TestCase {
JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd HH:mm:ss.SSS",
SerializerFeature.UseSingleQuotes));
}
public void test_parse() throws Exception {
Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
assertEquals(1539308902000L, date.getTime());
}
}