Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
add timezone support, for pull request #1594
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Nov 21, 2017
1 parent eeadb41 commit 327cdb9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, S
lexer.nextToken();

if (type == LocalDateTime.class) {
return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault());
return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), JSON.defaultTimeZone.toZoneId());
}
if (type == LocalDate.class) {
return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault()).toLocalDate();
return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), JSON.defaultTimeZone.toZoneId()).toLocalDate();
}
if (type == LocalTime.class) {
return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault()).toLocalTime();
return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), JSON.defaultTimeZone.toZoneId()).toLocalTime();
}

throw new UnsupportedOperationException();
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/alibaba/json/bvt/jdk8/LocalDateTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.alibaba.json.bvt.jdk8;

import java.time.LocalDate;
import java.util.Locale;
import java.util.TimeZone;

import junit.framework.TestCase;

Expand All @@ -9,6 +11,10 @@
import com.alibaba.fastjson.JSON;

public class LocalDateTest extends TestCase {
protected void setUp() throws Exception {
JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
JSON.defaultLocale = Locale.CHINA;
}

public void test_for_issue() throws Exception {
VO vo = new VO();
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.alibaba.json.bvt.jdk8;

import java.time.LocalTime;
import java.util.Locale;
import java.util.TimeZone;

import junit.framework.TestCase;

Expand All @@ -9,7 +11,11 @@
import com.alibaba.fastjson.JSON;

public class LocalTimeTest extends TestCase {

protected void setUp() throws Exception {
JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
JSON.defaultLocale = Locale.CHINA;
}

public void test_for_issue() throws Exception {
VO vo = new VO();
vo.setDate(LocalTime.now());
Expand Down

0 comments on commit 327cdb9

Please sign in to comment.