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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.core.simpletypes.temporal;

import java.util.*;

import org.litesoft.core.simpletypes.temporal.nonpublic.*;
import org.litesoft.core.typeutils.*;
import org.litesoft.deprecated.*;

/**
 * This class is for interacting with Java's Util Date in Local (or Wall) Time, except where UTC is explicitly mentioned!
 */
public class UtilDateAdaptor extends LL_UtilDateAdaptor implements TimestampWithResolutionAccessor,
                                                                   TimestampAccessorHMSM
{
    public UtilDateAdaptor( Date pDate, TemporalResolution pTemporalResolution )
    {
        super( pDate, TemporalResolution.deNull( pTemporalResolution ).ordinal() );
    }

    public UtilDateAdaptor( Date pDate )
    {
        this( pDate, null );
    }

    public UtilDateAdaptor( long pUTC, TemporalResolution pTemporalResolution )
    {
        this( new Date( pUTC ), pTemporalResolution );
    }

    /**
     * create with NOW
     */
    public UtilDateAdaptor()
    {
        this( System.currentTimeMillis(), null );
    }

    public UtilDateAdaptor force( TemporalResolution pResolution )
    {
        return (getTemporalResolution() == pResolution) ? this : new UtilDateAdaptor( getUTClong(), pResolution );
    }

    public static UtilDateAdaptor wall( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec )
    {
        return new UtilDateAdaptor( longForWall( pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ), TemporalResolution.ToMilliSec );
    }

    public static UtilDateAdaptor wall( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec )
    {
        return new UtilDateAdaptor( longForWall( pYear, pMonth, pDay, pHour, pMin, pSec, 0 ), TemporalResolution.ToSec );
    }

    public static UtilDateAdaptor wall( int pYear, int pMonth, int pDay, int pHour, int pMin )
    {
        return new UtilDateAdaptor( longForWall( pYear, pMonth, pDay, pHour, pMin, 0, 0 ), TemporalResolution.ToMin );
    }

    public static UtilDateAdaptor wall( int pYear, int pMonth, int pDay, int pHour )
    {
        return new UtilDateAdaptor( longForWall( pYear, pMonth, pDay, pHour, 0, 0, 0 ), TemporalResolution.ToHour );
    }

    public static UtilDateAdaptor wall( int pYear, int pMonth, int pDay )
    {
        return new UtilDateAdaptor( longForWall( pYear, pMonth, pDay, 0, 0, 0, 0 ), TemporalResolution.ToDay );
    }

    public static UtilDateAdaptor wall( int pYear, int pMonth )
    {
        return new UtilDateAdaptor( longForWall( pYear, pMonth, 1, 0, 0, 0, 0 ), TemporalResolution.ToMonth );
    }

    public static UtilDateAdaptor wall( int pYear )
    {
        return new UtilDateAdaptor( longForWall( pYear, 1, 1, 0, 0, 0, 0 ), TemporalResolution.ToYear );
    }

    public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec )
    {
        return new UtilDateAdaptor( UTC( pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ), TemporalResolution.ToMilliSec );
    }

    public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec )
    {
        return new UtilDateAdaptor( UTC( pYear, pMonth, pDay, pHour, pMin, pSec, 0 ), TemporalResolution.ToSec );
    }

    public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour, int pMin )
    {
        return new UtilDateAdaptor( UTC( pYear, pMonth, pDay, pHour, pMin, 0, 0 ), TemporalResolution.ToMin );
    }

    public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour )
    {
        return new UtilDateAdaptor( UTC( pYear, pMonth, pDay, pHour, 0, 0, 0 ), TemporalResolution.ToHour );
    }

    public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay )
    {
        return new UtilDateAdaptor( UTC( pYear, pMonth, pDay, 0, 0, 0, 0 ), TemporalResolution.ToDay );
    }

    public static UtilDateAdaptor zulu( int pYear, int pMonth )
    {
        return new UtilDateAdaptor( UTC( pYear, pMonth, 1, 0, 0, 0, 0 ), TemporalResolution.ToMonth );
    }

    public static UtilDateAdaptor zulu( int pYear )
    {
        return new UtilDateAdaptor( UTC( pYear, 1, 1, 0, 0, 0, 0 ), TemporalResolution.ToYear );
    }

    public static UtilDateAdaptor fromUtilDateToString( String pDateToString )
    {
        return (pDateToString != null) ? new UtilDateAdaptor( UtilDateAdaptor.parseUtilDate( pDateToString ), null ) : null;
    }

    public static UtilDateAdaptor fromUtilDateJustDateToString( String pDateToString )
    {
        return (pDateToString != null) ? new UtilDateAdaptor( UtilDateAdaptor.parseUtilDate( pDateToString ), TemporalResolution.ToDay ) : null;
    }

    @Override
    public TimeRes getTimeRes()
    {
        return (mTemporalFields < 3) ? null : TimeRes.fromIndex( mTemporalFields - 3 );
    }

    public TemporalResolution getTemporalResolution()
    {
        return TemporalResolution.values()[mTemporalFields];
    }

    public int getUTCtoWallOffsetMinutes()
    {
        return mUTCtoWallOffsetMinutes;
    }

    @Override
    public int getZuluOffsetMins()
    {
        return mUTCtoWallOffsetMinutes;
    }

    public int getYear()
    {
        return mYear;
    }

    public int getMonth()
    {
        return mMonth;
    }

    public int getDay()
    {
        return mDay;
    }

    public int getHour()
    {
        return mHour;
    }

    public int getMin()
    {
        return mMin;
    }

    public int getSec()
    {
        return mSec;
    }

    public int getMilliSec()
    {
        return mMilliSec;
    }

    public long getUTClong()
    {
        return mUTC;
    }

    public Date getWallDate()
    {
        return new Date( getUTClong() );
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append( Integers.zeroPadIt( 4, getYear() ) );
        sb.append( getTemporalResolution() == TemporalResolution.ToYear ? '|' : '-' );
        sb.append( Integers.zeroPadIt( 2, getMonth() ) );
        sb.append( getTemporalResolution() == TemporalResolution.ToMonth ? '|' : '-' );
        sb.append( Integers.zeroPadIt( 2, getDay() ) );
        sb.append( getTemporalResolution() == TemporalResolution.ToDay ? '|' : 't' );
        sb.append( Integers.zeroPadIt( 2, getHour() ) );
        sb.append( getTemporalResolution() == TemporalResolution.ToHour ? '|' : ':' );
        sb.append( Integers.zeroPadIt( 2, getMin() ) );
        sb.append( getTemporalResolution() == TemporalResolution.ToMin ? '|' : ':' );
        sb.append( Integers.zeroPadIt( 2, getSec() ) );
        sb.append( getTemporalResolution() == TemporalResolution.ToSec ? '|' : '.' );
        sb.append( Integers.zeroPadIt( 3, getMilliSec() ) );
        int zOffsetMinutes = getUTCtoWallOffsetMinutes();
        if ( zOffsetMinutes == 0 )
        {
            sb.append( 'Z' );
        }
        else
        {
            if ( zOffsetMinutes > 0 )
            {
                sb.append( '+' );
            }
            else
            {
                sb.append( '-' );
                zOffsetMinutes = -zOffsetMinutes;
            }
            int zHours = zOffsetMinutes / 60;
            int zMins = zOffsetMinutes - (zHours * 60);
            sb.append( Integers.zeroPadIt( 2, zHours ) );
            if ( zMins != 0 )
            {
                sb.append( ':' ).append( Integers.zeroPadIt( 2, zMins ) );
            }
        }
        return sb.toString();
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/UtilDateAdaptor.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
868 Diff Diff GeorgeS picture GeorgeS Mon 26 Nov, 2012 01:28:51 +0000
867 Diff Diff GeorgeS picture GeorgeS Sun 25 Nov, 2012 22:20:46 +0000

Updated Field Name

865 Diff Diff GeorgeS picture GeorgeS Mon 19 Nov, 2012 02:25:29 +0000
864 Diff Diff GeorgeS picture GeorgeS Mon 19 Nov, 2012 01:48:25 +0000
859 Diff Diff GeorgeS picture GeorgeS Mon 05 Nov, 2012 01:26:38 +0000
858 Diff Diff GeorgeS picture GeorgeS Sun 04 Nov, 2012 18:40:40 +0000
851 Diff Diff GeorgeS picture GeorgeS Mon 08 Oct, 2012 00:05:32 +0000

Breaking the code as Temporal changes are implemented...

50 GeorgeS picture GeorgeS Tue 13 Apr, 2010 11:51:38 +0000