Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package org.litesoft.core.simpletypes.temporal;

import org.litesoft.core.typeutils.*;

/**
 * A Timestamp with resolution only to the Hour ("Wall" relative) (with tracking for the Offset Minutes from Zulu).
 * <p/>
 * Note: This class supports Gregorian dates only.  As such when working with
 * Java Util Date(s) (or it's descendants) the local (or "Wall") date & time is all that is considered!
 */
@SuppressWarnings("UnusedDeclaration")
public class TimestampH extends AbstractTimestampH<TimestampH, AbstractTimestampH.Mutable>
{
    private static final long serialVersionUID = 1L;

    @SuppressWarnings({"deprecation", "UnusedDeclaration"}) @Deprecated /** for Serialization */
    protected TimestampH()
    {
        super( 0, 0 );
    }

    private TimestampH( int pOriginalZuluOffsetMins, long pUTC )
    {
        super( pOriginalZuluOffsetMins, pUTC );
    }

    private TimestampH( int pOriginalZuluOffsetMins, UtilDateAdaptor pDateAdaptor )
    {
        super( pOriginalZuluOffsetMins, pDateAdaptor );
    }

    public TimestampH( UtilDateAdaptor pDateAdaptor )
    {
        super( pDateAdaptor.force( TemporalResolution.ToHour ) );
    }

    @Override
    protected UtilDateAdaptor createWall()
    {
        return new UtilDateAdaptor( getUTClong(), TemporalResolution.ToHour );
    }

    public static TimestampH fromWallTime( int pYear, int pMonth, int pDay, int pHour )
    {
        return new TimestampH( UtilDateAdaptor.wall( pYear,
                                                     validateMonth( pYear, pMonth ),
                                                     validateDay( pYear, pMonth, pDay ),
                                                     validateHour( pHour ) ) );
    }

    public static TimestampH fromISO8601( int pYear, int pMonth, int pDay, int pHour, boolean pZulu, Integer pUTC_offsetMinutes )
    {
        validateMonth( pYear, pMonth );
        validateDay( pYear, pMonth, pDay );
        validateHour( pHour );
        int zZuluOffsetMins = Integers.deNull( pUTC_offsetMinutes );
        if ( pZulu )
        {
            return new TimestampH( zZuluOffsetMins, UtilDateAdaptor.zulu( pYear, pMonth, pDay, pHour ) );
        }
        Mutable zMutable = new Mutable( pYear, pMonth, pDay, false, pHour ); // Original Wall Time
        zMutable.adjustOrigWallToZulu( zZuluOffsetMins );
        return new TimestampH( zZuluOffsetMins,
                               UtilDateAdaptor.zulu( zMutable.getYear(), zMutable.getMonth(), zMutable.getDay(), zMutable.getHour() ) );
    }

    @Override
    public TemporalResolution getResolution()
    {
        return TemporalResolution.ToHour;
    }

    @Override
    public String toString()
    {
        return toYMDH();
    }

    public static String toString( TimestampH pTimestamp )
    {
        return (pTimestamp != null) ? pTimestamp.toString() : null;
    }

    public static String toYMDH( TimestampH pTimestamp )
    {
        return (pTimestamp != null) ? pTimestamp.toYMDH() : null;
    }

    public String toYMDH()
    {
        return formatSortableDisplayFormYMDH( this, new StringBuilder() ).toString();
    }

    public static TimestampH fromYMDH( String pToYMDH )
            throws IllegalArgumentException
    {
        String[] parts = parseSimple( pToYMDH, "// " );
        return (parts == null) ? null : //
               fromWallTime( parseYear( pToYMDH, parts ), //
                             parseMonth( pToYMDH, parts ), //
                             parseDay( pToYMDH, parts ), //
                             parseHour( pToYMDH, parts ) );
    }

    public final String toSQLvalue()
    {
        return "TODO"; // TODO: xxx
//        Mutable zMutable = new Mutable( getYear(), getMonth(), getDay(), false, getZuluOffsetMins(), getHour() );
//        zMutable.fromWallToZulu();
//        return formatSQLvalueYMDH( zMutable, true, new StringBuilder() ).toString();
    }

    public static TimestampH fromSQLvalue( String pToSQLvalue )
    {
        String[] parts = parseSimple( pToSQLvalue, "--TZ" );
        return (parts == null) ? null : //
               fromISO8601( parseYear( pToSQLvalue, parts ), //
                            parseMonth( pToSQLvalue, parts ), //
                            parseDay( pToSQLvalue, parts ), //
                            parseHour( pToSQLvalue, parts ), //
                            true, parseOffset( pToSQLvalue, parts ) );
    }

    @Override
    public UtilDateAdaptor toUtilDateAdaptor()
    {
        return getWall();
    }

    // vvvvvvvvvvvvvvvvvv Non-common Public methods vvvvvvvvvvvvvvvvv

    public static TimestampH now()
    {
        return new TimestampH( new UtilDateAdaptor() );
    }

    // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv

    @Override
    protected TimestampH createTypeFrom( Mutable pMutable )
    {
        return null; // TODO: new TimestampH( pMutable.getYear(), pMutable.getMonth(), pMutable.getDay(), pMutable.getZuluOffsetMins(), pMutable.getHour() );
    }

    @Override
    protected Mutable createMutable( int pYear, int pNewMonth )
    {
        return null; // TODO: new Mutable( pYear, pNewMonth, getDay(), true, getZuluOffsetMins(), getHour() );
    }

    @Override
    protected Mutable createMutable( int pYear, int pMonth, int pNewDay )
    {
        return null; // TODO: new Mutable( pYear, pMonth, pNewDay, false, getZuluOffsetMins(), getHour() );
    }

    @Override
    protected Mutable createMutable( int pYear, int pMonth, int pDay, int pNewHour )
    {
        return null; // TODO: new Mutable( pYear, pMonth, pDay, false, getZuluOffsetMins(), pNewHour );
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/TimestampH.java

Diff revisions: vs.
Revision Author Commited Message
898 Diff Diff GeorgeS picture GeorgeS Sun 17 Mar, 2013 21:46:33 +0000

Temporal!!!

897 Diff Diff GeorgeS picture GeorgeS Mon 25 Feb, 2013 02:04:34 +0000
893 Diff Diff GeorgeS picture GeorgeS Mon 14 Jan, 2013 01:18:30 +0000
864 GeorgeS picture GeorgeS Mon 19 Nov, 2012 01:48:25 +0000