OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 156
Line 16... Line 16...
16
import org.openconcerto.utils.io.JSONConverter;
16
import org.openconcerto.utils.io.JSONConverter;
17
 
17
 
18
import java.sql.Timestamp;
18
import java.sql.Timestamp;
19
import java.text.ParseException;
19
import java.text.ParseException;
20
import java.text.SimpleDateFormat;
20
import java.text.SimpleDateFormat;
-
 
21
import java.util.Date;
21
 
22
 
22
import net.minidev.json.JSONObject;
23
import net.minidev.json.JSONObject;
23
 
24
 
24
public class LightUIDate extends LightUserControl {
25
public class LightUIDate extends LightUserControl {
25
 
26
 
-
 
27
    private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.S";
-
 
28
 
-
 
29
    public LightUIDate() {
-
 
30
        // Serialization
-
 
31
    }
-
 
32
 
26
    public LightUIDate(final JSONObject json) {
33
    public LightUIDate(final JSONObject json) {
27
        super(json);
34
        super(json);
28
    }
35
    }
29
 
36
 
30
    public LightUIDate(final String id) {
37
    public LightUIDate(final String id) {
Line 37... Line 44...
37
        super(date);
44
        super(date);
38
    }
45
    }
39
 
46
 
40
    public Timestamp getValueAsDate() {
47
    public Timestamp getValueAsDate() {
41
        if (this.getValue() != null && !this.getValue().isEmpty()) {
48
        if (this.getValue() != null && !this.getValue().isEmpty()) {
42
            SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
49
            SimpleDateFormat df2 = new SimpleDateFormat(DATE_FORMAT);
43
            try {
50
            try {
44
                return new Timestamp(df2.parse(this.getValue()).getTime());
51
                return new Timestamp(df2.parse(this.getValue()).getTime());
45
            } catch (final ParseException ex) {
52
            } catch (final ParseException ex) {
46
                throw new IllegalArgumentException(ex.getMessage(), ex);
53
                throw new IllegalArgumentException(ex.getMessage(), ex);
47
            }
54
            }
48
        }
55
        }
49
        return null;
56
        return null;
50
    }
57
    }
51
 
58
 
52
    @Override
-
 
53
    public JSONToLightUIConvertor getConvertor() {
59
    public void setDate(Date date) {
54
        return new JSONToLightUIConvertor() {
-
 
55
            @Override
-
 
56
            public LightUIElement convert(final JSONObject json) {
60
        SimpleDateFormat df2 = new SimpleDateFormat(DATE_FORMAT);
57
                return new LightUIDate(json);
61
        this.setValue(df2.format(date));
58
            }
-
 
59
        };
-
 
60
    }
62
    }
61
 
63
 
62
    @Override
64
    @Override
63
    public Object getValueForContext() {
65
    public Object getValueForContext() {
64
        return this.getValueAsDate();
66
        return this.getValueAsDate();