package com.alibaba.json.bvt;

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

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import junit.framework.TestCase;

public class SqlDateTest1 extends TestCase {
    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = new Locale("zh_CN");
    }
    
    public void test_date() throws Exception {
        long millis = 1324138987429L;
        Date date = new Date(millis);

        Assert.assertEquals("1324138987429", JSON.toJSONString(date));
        Assert.assertEquals("{\"@type\":\"java.sql.Date\",\"val\":1324138987429}", JSON.toJSONString(date, SerializerFeature.WriteClassName));
        Assert.assertEquals(1324138987429L, ((java.util.Date)JSON.parse("{\"@type\":\"java.util.Date\",\"val\":1324138987429}")).getTime());

        Assert.assertEquals("\"2011-12-18 00:23:07\"",
                            JSON.toJSONString(date, SerializerFeature.WriteDateUseDateFormat));
        Assert.assertEquals("\"2011-12-18 00:23:07.429\"",
                            JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd HH:mm:ss.SSS"));
        Assert.assertEquals("'2011-12-18 00:23:07.429'",
                            JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd HH:mm:ss.SSS",
                                                            SerializerFeature.UseSingleQuotes));
    }

    public void test_date2() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Date d = sdf.parse("2019-09-12 16:00:00");
        java.sql.Date ds = new java.sql.Date(d.getTime());
//        System.out.println("Java Obj: " + sdf.format(ds));

        String jvs = JSON.toJSONString(ds);
//        System.out.println("JSON Str: " + jvs);

        java.sql.Date d2s = JSON.parseObject(jvs, java.sql.Date.class);
//        System.out.println("Java Obj: " + sdf.format(d2s));
//        System.out.println("LONG: " + d2s.getTime());

        assertEquals(d.getTime(), d2s.getTime());
    }
}

@@ -1547,17 +1547,21 @@
 ;%0A    %7D%0A
-%0A
+//%0A//
     publ
@@ -1592,32 +1592,34 @@
 ows Exception %7B%0A
+//
         SimpleDa
@@ -1674,24 +1674,26 @@
 HH:mm:ss%22);%0A
+//
         java
@@ -1737,24 +1737,26 @@
 16:00:00%22);%0A
+//
         java
@@ -1798,24 +1798,26 @@
 getTime());%0A
+//
 //        Sy
@@ -1861,25 +1861,29 @@
 ormat(ds));%0A
-%0A
+//%0A//
         Stri
@@ -1910,24 +1910,26 @@
 String(ds);%0A
+//
 //        Sy
@@ -1962,25 +1962,29 @@
 : %22 + jvs);%0A
-%0A
+//%0A//
         java
@@ -2043,16 +2043,18 @@
 class);%0A
+//
 //      
@@ -2107,16 +2107,18 @@
 (d2s));%0A
+//
 //      
@@ -2157,33 +2157,37 @@
 d2s.getTime());%0A
-%0A
+//%0A//
         assertEq
@@ -2216,20 +2216,22 @@
 getTime());%0A
+//
     %7D%0A%7D%0A

fix testcase