package fi.vincit.jmobster.processor.languages.javascript.valueconverters;

/*
 * Copyright 2012 Juha Siponen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

/**
 * Converter for Java Date objects. Converts values to quoted strings.
 */
public class DateTimeConverter extends StringConverter {

    private SimpleDateFormat simpleDateFormat;

    public DateTimeConverter(String pattern) {
        simpleDateFormat = new SimpleDateFormat(pattern);
    }

    public DateTimeConverter(String pattern, Locale locale) {
        simpleDateFormat = new SimpleDateFormat(pattern, locale);
    }

    public DateTimeConverter( SimpleDateFormat simpleDateFormat ) {
        this.simpleDateFormat = simpleDateFormat;
    }

    @Override
    protected String getTypeDefaultValue() {
        Date defaultDate = new Date(0);
        return super.getValueAsString(simpleDateFormat.format(defaultDate));
    }

    @Override
    protected String getValueAsString( Object value ) {
        return super.getValueAsString(simpleDateFormat.format((Date)value));
    }
}

@@ -666,16 +666,45 @@
 e.%0A */%0A%0A
+import java.text.DateFormat;%0A
 import j
@@ -928,22 +928,16 @@
 private 
-Simple
 DateForm
@@ -931,39 +931,33 @@
 vate DateFormat 
-simpleD
+d
 ateFormat;%0A%0A    
@@ -999,39 +999,33 @@
 tern) %7B%0A        
-simpleD
+d
 ateFormat = new 
@@ -1128,23 +1128,17 @@
         
-simpleD
+d
 ateForma
@@ -1217,22 +1217,16 @@
 verter( 
-Simple
 DateForm
@@ -1228,23 +1228,17 @@
 eFormat 
-simpleD
+d
 ateForma
@@ -1256,23 +1256,17 @@
    this.
-simpleD
+d
 ateForma
@@ -1269,23 +1269,17 @@
 ormat = 
-simpleD
+d
 ateForma
@@ -1417,39 +1417,34 @@
 etValueAsString(
-simpleD
+ d
 ateFormat.format
@@ -1444,16 +1444,17 @@
 .format(
+ 
 defaultD
@@ -1456,17 +1456,19 @@
 aultDate
-)
+ ) 
 );%0A    %7D
@@ -1581,15 +1581,10 @@
 ing(
-simpleD
+ d
 ateF
@@ -1596,16 +1596,17 @@
 .format(
+ 
 (Date)va
@@ -1608,17 +1608,19 @@
 te)value
-)
+ ) 
 );%0A    %7D

Change DateTimeConverter to use DateFormat