File: WindowsDate.java

package info (click to toggle)
libjlha-java 0.0.20050504-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 1,364 kB
  • ctags: 1,338
  • sloc: java: 10,782; xml: 139; makefile: 14
file content (411 lines) | stat: -rw-r--r-- 13,916 bytes parent folder | download | duplicates (6)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
//start of WindowsDate.java
//TEXT_STYLE:CODE=Shift_JIS(Japanese):RET_CODE=CRLF

/**
 * WindowsDate.java
 * 
 * Copyright (C) 2002  Michel Ishizuka  All rights reserved.
 * 
 * ȉ̏ɓӂȂ΃\[XƃoCi`̍ĔzzƎgp
 * ύX̗Lɂ炸‚B
 * 
 * PD\[XR[h̍ĔzzɂĒ쌠\ ̏̃Xg
 *     щL̐ێȂĂ͂ȂȂB
 * 
 * QDoCi`̍ĔzzɂĒ쌠\ ̏̃Xg
 *     щL̐gp ̑̔zz
 *     ܂ގɋLqȂ΂ȂȂB
 * 
 * ̃\tgEFA͐Β˔ڂɂĖۏ؂Œ񋟂A̖
 * IBłƂۏ؁AilLƂۏ؂ɂƂǂ܂炸A
 * Ȃ閾IшÎIȕۏ؂ȂB
 * Β˔ڂ ̃\tgEFA̎gpɂ钼ړIAԐړIA
 * IAȁAT^IȁA邢͕KRIȑQ(gpɂf[^
 * AƖ̒f〈܂Ăv̈⎸A֐i
 * T[rX̓l邪AĂꂾɌ肳Ȃ
 * Q)ɑ΂āAȂ鎖Ԃ̌ƂȂƂĂA_̐
 * C△ߎӔC܂ ȂӔC낤ƂAƂꂪs
 * ŝׂ߂łƂĂA܂͂̂悤ȑQ̉”\
 * ĂƂĂ؂̐ӔC𕉂Ȃ̂ƂB
 */

package jp.gr.java_conf.dangan.util;

//import classes and interfaces
import java.util.Date;
import java.lang.Cloneable;

//import exceptions
import java.lang.IllegalArgumentException;

/**
 * WindowsFILETIME`̏Date̔hNXB<br>
 * FILETIME  1601N 1 1 000b̌oߎԂ
 * 100imbPʂŎ64rbglB<br>
 * ̃NXł FILETIME  long(64rbgl)ƂĈƂ
 * {IɕƂ݂ȂB<br>
 * 1601N 1 1 000bȑO̎Ԃꍇ
 * WindowsDate( Date date ) AWindowsDate.setTime( long time )gpB<br>
 * 
 * <pre>
 * -- revision history --
 * $Log: WindowsDate.java,v $
 * Revision 1.1  2002/12/05 00:00:00  dangan
 * [maintenance]
 *     javadoc Rg̃Xy~XCB
 *     \[X
 *
 * Revision 1.0  2002/08/05 00:00:00  dangan
 * add to version control
 * [bug fix] 
 *     setn\bh ͈͊O̎ԂZbg悤Ƃ
 *     O𓊂P[XŎԂ̏߂sĂȂB
 *     checkRange ̎Ԃ͈̔͂ԈĂB
 * [maintenance]
 *     ^u̔p~
 *     CZX̏C
 *
 * </pre>
 * 
 * @author  $Author: dangan $
 * @version $Revision: 1.1 $
 */
public class WindowsDate extends Date
                         implements Cloneable{


    //------------------------------------------------------------------
    //  class field
    //------------------------------------------------------------------
    //  public static final long TIME_DIFFERENCE
    //------------------------------------------------------------------
    /**
     * FILETIME`̃f[^ƁAjava.util.Date.getTime() 
     * 鎞Ԍ`Ƃ̎ԍ 100imZJhPʂŎlB
     * ȂA[b͍lɓĂȂB
     */
    public static final long TIME_DIFFERENCE = 0x19DB1DED53E8000L;


    //------------------------------------------------------------------
    //  instance field
    //------------------------------------------------------------------
    //  private int NanoSecounds
    //------------------------------------------------------------------
    /**
     * java.util.Date ł͕ێłȂ 
     * imbPʂ̎Ԃێ邽߂ɗpB
     */
    private int NanoSecounds;


    //------------------------------------------------------------------
    //  constructor
    //------------------------------------------------------------------
    //  public WindowsDate()
    //  public WindowsDate( Date date )
    //  public WindowsDate( long time )
    //------------------------------------------------------------------
    /**
     * ftHgRXgN^B
     * ݂̎ԏ WindowsDate\zB
     * imbPʂ̎Ԃ͎擾łȂ߁A0ɐݒ肳B
     * 
     * @exception IllegalArgumentException
     *                  ݂̎Ԃ FILETIME `ŕ\ł
     *                  ͈͊OꍇB
     */
    public WindowsDate(){
        super();
        this.NanoSecounds = 0;

        this.checkRange();
    }

    /**
     * dateŎ鎞Ԃ\ WindowsDate\zB<br>
     * date WindowsDate ̃CX^XȂ
     * imbPʂ̏Rs[邪AȊȌꍇ
     * imbPʂ̏ɂ 0 ݒ肳B
     * 
     * @param date V\z WindowsDate ̌ƂȂ鎞ԏ 
     *             Date ̃IuWFNg
     * 
     * @exception IllegalArgumentException
     *                  ݂̎Ԃ FILETIME `ŕ\ł
     *                  ͈͊OꍇB
     */
    public WindowsDate( Date date ){
        super( date.getTime() );
        if( date instanceof WindowsDate ){
            this.NanoSecounds = ((WindowsDate)date).NanoSecounds;
        }else{
            this.NanoSecounds = 0;
            this.checkRange();
        }
    }

    /**
     * 64rbgFILETIME`̎ԏ񂩂
     * VWindowsDate\zB<br>
     * 
     * @param time FILETIME`̎ԏ
     */
    public WindowsDate( long time ){
        super( 0 <= time 
         ? ( time - WindowsDate.TIME_DIFFERENCE ) / 10000L
         : ( ( time >>> 1 ) - ( WindowsDate.TIME_DIFFERENCE >>> 1 ) ) / 5000L );

        this.NanoSecounds = 
                 (int)( ( time >>> 1 ) % 5000L * 2 + ( time & 1 ) ) * 100;
    }


    //------------------------------------------------------------------
    //  method of java.lang.Cloneable
    //------------------------------------------------------------------
    //  public Object clone()
    //------------------------------------------------------------------
    /**
     * ̃IuWFNg̃Rs[ԂB
     * 
     * @return WindowsDateIuWFNg̕
     */
    public Object clone(){
        return new WindowsDate( this );
    }


    //------------------------------------------------------------------
    //  method of java.util.Date
    //------------------------------------------------------------------
    //  set method with range check
    //------------------------------------------------------------------
    //  public void setYear( int year )
    //  public void setMonth( int month )
    //  public void setDate( int day )
    //  public void setHours( int hour )
    //  public void setMinutes( int minute )
    //  public void setSecounds( int secound )
    //  public void setTime( long time )
    //------------------------------------------------------------------
    /**
     *  WindowsDate ̎N year 
     * w肳ꂽl1900𑫂̂ɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     *
     * @param year 1900𑫂ƂŐ\悤 N̒l
     * 
     * @exception IllegalArgumentException
     *             year ɕύXƂ FILETIME`ňȂ
     *             ͈͂̎ԂɂȂꍇ
     * @deprecated
     */
    public void setYear( int year ){
        long temp = this.getTime();

        try{
            super.setYear( year );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    /**
     *  WindowsDate ̎ month Ŏw肳ꂽlɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     *
     * @param month 01A12悤Ȍ̒l
     * 
     * @exception IllegalArgumentException
     *             month ɕύXƂ FILETIME`ňȂ
     *             ͈͂̎ԂɂȂꍇ
     * @deprecated
     */
    public void setMonth( int month ){
        long temp = this.getTime();

        try{
            super.setMonth( month );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    /**
     *  WindowsDate ̎ ꃖ
     * ł̉ڂ date Ŏw肳ꂽlɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     *
     * @param date 11A22悤ȓ̒l
     * 
     * @exception IllegalArgumentException
     *             date ɕύXƂ FILETIME`ňȂ
     *             ͈͂̎ԂɂȂꍇ
     * @deprecated
     */
    public void setDate( int date ){
        long temp = this.getTime();

        try{
            super.setDate( date );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    /**
     *  WindowsDate ̎̒ł̎Ԃ
     * hours Ŏw肳ꂽlɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     *
     * @param hours Ԃ̒l
     * 
     * @exception IllegalArgumentException
     *             hours ɕύXƂ FILETIME`ňȂ
     *             ͈͂̎ԂɂȂꍇ
     * @deprecated
     */
    public void setHours( int hours ){
        long temp = this.getTime();

        try{
            super.setHours( hours );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    /**
     *  WindowsDate ̎ꎞԂ̒ł̕
     * minutes Ŏw肳ꂽlɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     *
     * @param minutes ̒l
     * 
     * @exception IllegalArgumentException
     *             minutes ɕύXƂ FILETIME`ňȂ
     *             ͈͂̎ԂɂȂꍇ
     * @deprecated
     */
    public void setMinutes( int minutes ){
        long temp = this.getTime();

        try{
            super.setMinutes( minutes );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    /**
     *  WindowsDate ̎ꕪ̒ł̕b
     * secounds Ŏw肳ꂽlɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     *
     * @param secounds b
     * 
     * @exception IllegalArgumentException
     *             secounds ɕύXƂ FILETIME`ňȂ
     *             ͈͂̎ԂɂȂꍇ
     * @deprecated
     */
    public void setSeconds( int seconds ){
        long temp = this.getTime();

        try{
            super.setSeconds( seconds );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    /**
     *  WindowsDate ̎Ԃ 
     * 1970N11 00:00:00 GMT
     * time ~bo߂ɐݒ肷B<br>
     * ̃\bh͔͈̓`FbNŝ߂ɑ݂B<br>
     * 
     * @param time 1970N11 00:00:00GMT ̌o߃~b
     * 
     * @exception IllegalArgumentException
     *             time FILETIME`ňȂ
     *             ͈͂̎ԂĂꍇ
     */
    public void setTime( long time ){
        long temp = this.getTime();

        try{
            super.setTime( time );
            this.checkRange();
        }catch( IllegalArgumentException exception ){
            this.setTime( temp );
            throw exception;
        }
    }

    //------------------------------------------------------------------
    //  original method
    //------------------------------------------------------------------
    //  access method with FILETIME format
    //------------------------------------------------------------------
    //  public void setWindowsTime( long time )
    //  public long getWindowsTime()
    //------------------------------------------------------------------
    /**
     *  WindowsDate  FILETIME`̎ԏݒ肷B
     * 
     * @param time FILETIME`̎ԏ
     */
    public void setWindowsTime( long time ){
        super.setTime( 0 <= time 
         ? ( time - WindowsDate.TIME_DIFFERENCE ) / 10000L
         : ( ( time >>> 1 ) - ( WindowsDate.TIME_DIFFERENCE >>> 1 ) ) / 5000L );

        this.NanoSecounds = 
                 (int)( ( time >>> 1 ) % 5000L * 2 + ( time & 1 ) ) * 100;
    }

    /**
     *  WindowsDateԏ FILETIME `œB
     * 
     * @return FILETIME`̒l
     */
    public long getWindowsTime() {
        return ( super.getTime() * 10000L + WindowsDate.TIME_DIFFERENCE
                 + (long)( this.NanoSecounds / 100 ) );
    }


    //------------------------------------------------------------------
    //  local method
    //------------------------------------------------------------------
    //  private void checkRange()
    //------------------------------------------------------------------
    /**
     *  WindowsDate  FILETIME`ŕ\鎞Ԃ
     * ͈͓ł邩𔻒肷B܂sS
     * 
     * @exception IllegalArgumentException
     *              WindowsDate  FILETIME`ňȂ
     *             ͈͂̎ԂĂꍇ
     */
    private void checkRange(){
        long time = super.getTime();
        if( !( 0xFFFCAE8C71E60F9BL <= time && time <= 0x000683218A10A8CBL ) )
            throw new IllegalArgumentException( "outside of range of Windows FILETIME format. " );
    }

}