Subversion Repository Public Repository

litesoft

Diff Revisions 850 vs 851 for /trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/UtilDateAdaptor.java

Diff revisions: vs.
  @@ -4,9 +4,13 @@
4 4 import java.util.*;
5 5
6 6 import org.litesoft.core.simpletypes.temporal.nonpublic.*;
7 + import org.litesoft.core.typeutils.gregorian.*;
7 8 import org.litesoft.deprecated.*;
8 9
9 - public class UtilDateAdaptor extends LL_UtilDateAdaptor implements TimestampWithResolutionAccessor
10 + /**
11 + * This class is for interacting with Java's Util Date in Local (or Wall) Time, except where UTC is explicitly mentioned!
12 + */
13 + public class UtilDateAdaptor extends LL_UtilDateAdaptor implements TimestampWithResolutionAccessor, YearMonthDayAccessor
10 14 {
11 15 /**
12 16 * create with NOW
  @@ -31,42 +35,42 @@
31 35
32 36 public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec )
33 37 {
34 - super( 4, pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec );
38 + super( calculateCurrentUTCtoWallOffsetMinutes(), 4, pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec );
35 39 }
36 40
37 41 public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec )
38 42 {
39 - super( 3, pYear, pMonth, pDay, pHour, pMin, pSec, 0 );
43 + super( calculateCurrentUTCtoWallOffsetMinutes(), 3, pYear, pMonth, pDay, pHour, pMin, pSec, 0 );
40 44 }
41 45
42 46 public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour, int pMin )
43 47 {
44 - super( 2, pYear, pMonth, pDay, pHour, pMin, 0, 0 );
48 + super( calculateCurrentUTCtoWallOffsetMinutes(), 2, pYear, pMonth, pDay, pHour, pMin, 0, 0 );
45 49 }
46 50
47 51 public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour )
48 52 {
49 - super( 1, pYear, pMonth, pDay, pHour, 0, 0, 0 );
53 + super( calculateCurrentUTCtoWallOffsetMinutes(), 1, pYear, pMonth, pDay, pHour, 0, 0, 0 );
50 54 }
51 55
52 56 public UtilDateAdaptor( int pYear, int pMonth, int pDay )
53 57 {
54 - super( 0, pYear, pMonth, pDay, 0, 0, 0, 0 );
58 + super( calculateCurrentUTCtoWallOffsetMinutes(), 0, pYear, pMonth, pDay, 0, 0, 0, 0 );
55 59 }
56 60
57 - private UtilDateAdaptor( String pDate, int pTimeFields )
61 + private UtilDateAdaptor( long pUTC, int pTimeFields )
58 62 {
59 - super( pDate, pTimeFields );
63 + super( new Date( pUTC ), pTimeFields );
60 64 }
61 65
62 - public static UtilDateAdaptor fromDateToString( String pDateToString )
66 + public static UtilDateAdaptor fromUtilDateToString( String pDateToString )
63 67 {
64 - return (pDateToString != null) ? new UtilDateAdaptor( pDateToString, 4 ) : null;
68 + return (pDateToString != null) ? new UtilDateAdaptor( UtilDateAdaptor.parseUtilDate( pDateToString ), 4 ) : null;
65 69 }
66 70
67 - public static UtilDateAdaptor fromJustDateToString( String pDateToString )
71 + public static UtilDateAdaptor fromUtilDateJustDateToString( String pDateToString )
68 72 {
69 - return (pDateToString != null) ? new UtilDateAdaptor( pDateToString, 0 ) : null;
73 + return (pDateToString != null) ? new UtilDateAdaptor( UtilDateAdaptor.parseUtilDate( pDateToString ), 0 ) : null;
70 74 }
71 75
72 76 @Override
  @@ -80,9 +84,98 @@
80 84 return mTimeFields;
81 85 }
82 86
87 + public int getUTCtoWallOffsetMinutes()
88 + {
89 + return mUTCtoWallOffsetMinutes;
90 + }
91 +
92 + public int getYear()
93 + {
94 + return mYear;
95 + }
96 +
97 + public int getMonth()
98 + {
99 + return mMonth;
100 + }
101 +
102 + public int getDay()
103 + {
104 + return mDay;
105 + }
106 +
107 + public int getHour()
108 + {
109 + return mHour;
110 + }
111 +
112 + public int getMin()
113 + {
114 + return mMin;
115 + }
116 +
117 + public int getSec()
118 + {
119 + return mSec;
120 + }
121 +
122 + public int getMilliSec()
123 + {
124 + return mMilliSec;
125 + }
126 +
127 + public long getUTClong()
128 + {
129 + int zYear = mYear;
130 + int zMonth = mMonth;
131 + int zDay = mDay;
132 + int zHour = mHour;
133 + int zMin = mMin;
134 + if ( mUTCtoWallOffsetMinutes != 0 ) // then Adjust the time to UTC
135 + {
136 + zMin -= mUTCtoWallOffsetMinutes; // subtract the offset to to advance those to the west, and retard those to the east.
137 + while ( zMin < 0 )
138 + {
139 + zMin += 60;
140 + if ( --zHour < 0 )
141 + {
142 + zHour += 24;
143 + if ( --zDay < 1 )
144 + {
145 + if ( --zMonth < 1 )
146 + {
147 + zMonth = 12;
148 + zYear--;
149 + }
150 + zDay = Month.daysIn( zYear, zMonth );
151 + }
152 + }
153 + }
154 + while ( 60 <= zMin )
155 + {
156 + zMin -= 60;
157 + if ( 23 < ++zHour )
158 + {
159 + zHour -= 24;
160 + }
161 + }
162 + }
163 + return UTC( zYear, zMonth, zDay, zHour, zMin, mSec, mMilliSec );
164 + }
165 +
166 + public Date getWallDate()
167 + {
168 + return new Date( getUTClong() );
169 + }
170 +
83 171 @Override
84 172 public String toString()
85 173 {
86 174 return new SimpleTimestamp( this ).toString();
87 175 }
176 +
177 + private static int calculateCurrentUTCtoWallOffsetMinutes()
178 + {
179 + return new UtilDateAdaptor( 0, 0 ).getUTCtoWallOffsetMinutes();
180 + }
88 181 }