From 4ceb82cd7c7ce960538243472d0bbd09349dcb4b Mon Sep 17 00:00:00 2001 From: Laki Sik Date: Tue, 20 Sep 2016 13:42:14 +0700 Subject: [PATCH] fix date --- .../com/ahancer/rr/controllers/ProposalController.java | 2 +- src/main/java/com/ahancer/rr/utils/Util.java | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ahancer/rr/controllers/ProposalController.java b/src/main/java/com/ahancer/rr/controllers/ProposalController.java index b39e411..dd68ff2 100644 --- a/src/main/java/com/ahancer/rr/controllers/ProposalController.java +++ b/src/main/java/com/ahancer/rr/controllers/ProposalController.java @@ -148,7 +148,7 @@ public List getNewProposalMessage(@PathVariable Long proposalId @RequestMapping(method=RequestMethod.GET, value="/{proposalId}/proposalmessages/poll") @Authorization({Role.Admin,Role.Brand,Role.Influencer}) - public @ResponseBody DeferredProposalMessage getAllProposalMessagePoll(@PathVariable Long proposalId, @RequestParam(name="timestamp",required=false) String timestamp) throws Exception { + public @ResponseBody DeferredProposalMessage getAllProposalMessagePoll(@PathVariable Long proposalId, @RequestParam(name="timestamp",required=false) String timestamp ) throws Exception { final Date date = Util.parseJacksonDate(timestamp); final DeferredProposalMessage result = new DeferredProposalMessage(proposalId, date, this.getUserRequest().getRole()); if(proposalMessageService.countNewProposalMessage(proposalId, date) > 0L) { diff --git a/src/main/java/com/ahancer/rr/utils/Util.java b/src/main/java/com/ahancer/rr/utils/Util.java index 4eef9a8..2e95696 100644 --- a/src/main/java/com/ahancer/rr/utils/Util.java +++ b/src/main/java/com/ahancer/rr/utils/Util.java @@ -2,14 +2,13 @@ import java.beans.FeatureDescriptor; import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Set; -import java.util.TimeZone; import java.util.stream.Stream; +import org.joda.time.DateTime; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; @@ -39,9 +38,8 @@ public static Date parseJacksonDate(String utc) throws ParseException { if(utc == null) { return null; } - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - formatter.setTimeZone(TimeZone.getTimeZone("Asia/Bangkok")); - return formatter.parse(utc.replaceAll("Z$", "+0000")); + Date date = new DateTime(utc).toDate(); + return date; } public static UserResponse getUserResponse(User user){