package com.alibaba.json.bvt.date;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import junit.framework.TestCase;
import org.junit.Assert;

public class DateFieldFormatTest extends TestCase {

    protected void setUp() throws Exception {
        //JSON.defaultTimeZone = TimeZone.getTimeZone("GMT-00:00");
        //JSON.defaultLocale = Locale.UK;
    }
    
    public void test_format_() throws Exception {
        Date now = new Date();
        Model model = new Model();
        model.serverTime = now;
        model.publishTime = now;
        model.setStartDate( now );
        
        String text = JSON.toJSONString(model);
        System.out.println(text);

        String t1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
        String t2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(now);
        String t3 = new SimpleDateFormat("yyyy-MM-dd").format(now);

        Assert.assertEquals("{\"publishTime\":\""+t2+"\",\"serverTime\":\""+t1+"\",\"startDate\":\""+t3+"\"}",text);
        
        Model model2 = JSON.parseObject(text, Model.class);
        Assert.assertEquals(t2,new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(model2.publishTime));
        Assert.assertEquals(t1,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(model2.serverTime));
        Assert.assertEquals(t3,new SimpleDateFormat("yyyy-MM-dd").format(model2.getStartDate()));
        
    }

    public static class Model {

        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        public Date serverTime;

        @JSONField(format = "yyyy/MM/dd HH:mm:ss")
        public Date publishTime;

        @JSONField(format = "yyyy-MM-dd")
        private Date startDate;

        public Date getStartDate() {
            return startDate;
        }

        public void setStartDate(Date startDate) {
            this.startDate = startDate;
        }
    }
}

@@ -383,34 +383,32 @@
 ption %7B%0A        
-//
 JSON.defaultTime
@@ -440,17 +440,21 @@
 ne(%22
-GMT-00:00
+Asia/Shanghai
 %22);%0A
@@ -465,10 +465,8 @@
     
-//
 JSON
@@ -493,10 +493,13 @@
 ale.
-UK
+CHINA
 ;%0A  
@@ -869,32 +869,46 @@
 -MM-dd HH:mm:ss%22
+, Locale.CHINA
 ).format(now);%0A 
@@ -960,32 +960,46 @@
 /MM/dd HH:mm:ss%22
+, Locale.CHINA
 ).format(now);%0A 
@@ -1042,32 +1042,46 @@
 mat(%22yyyy-MM-dd%22
+, Locale.CHINA
 ).format(now);%0A%0A
@@ -1331,32 +1331,46 @@
 /MM/dd HH:mm:ss%22
+, Locale.CHINA
 ).format(model2.
@@ -1457,16 +1457,30 @@
 H:mm:ss%22
+, Locale.CHINA
 ).format
@@ -1565,16 +1565,30 @@
 y-MM-dd%22
+, Locale.CHINA
 ).format

add timezone for DateFieldFormatTest