litesoft
@ 942
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 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.commonfoundation.typeutils.gregorian; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.deprecated.*; import java.util.*; /** * 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 TimestampAccessorHMSM { public static int calculateCurrentUTCtoWallOffsetMinutes() { return new UtilDateAdaptor( 0, null ).getUTCtoWallOffsetMinutes(); } /** * create with NOW */ public UtilDateAdaptor() { this( System.currentTimeMillis(), null ); } public UtilDateAdaptor( Date pDate ) { this( pDate, null ); } public UtilDateAdaptor( Date pDate, TemporalResolution pTemporalResolution ) { super( pDate, TemporalResolution.deNull( pTemporalResolution ).ordinal() ); } private UtilDateAdaptor( int pOffsetMinutes, TemporalResolution pTemporalResolution, int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec ) { super( pOffsetMinutes, pTemporalResolution.ordinal(), pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ); } public static UtilDateAdaptor offsetWallToMilliSec( int pOffsetMinutes, int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToMilliSec, pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ); } public static UtilDateAdaptor currentWall( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec ) { return offsetWallToMilliSec( calculateCurrentUTCtoWallOffsetMinutes(), pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ); } public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec ) { return offsetWallToMilliSec( 0, pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ); } public static UtilDateAdaptor offsetWallToSec( int pOffsetMinutes, int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToSec, pYear, pMonth, pDay, pHour, pMin, pSec, 0 ); } public static UtilDateAdaptor currentWall( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec ) { return offsetWallToSec( calculateCurrentUTCtoWallOffsetMinutes(), pYear, pMonth, pDay, pHour, pMin, pSec ); } public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec ) { return offsetWallToSec( 0, pYear, pMonth, pDay, pHour, pMin, pSec ); } public static UtilDateAdaptor offsetWallToMin( int pOffsetMinutes, int pYear, int pMonth, int pDay, int pHour, int pMin ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToMin, pYear, pMonth, pDay, pHour, pMin, 0, 0 ); } public static UtilDateAdaptor currentWall( int pYear, int pMonth, int pDay, int pHour, int pMin ) { return offsetWallToMin( calculateCurrentUTCtoWallOffsetMinutes(), pYear, pMonth, pDay, pHour, pMin ); } public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour, int pMin ) { return offsetWallToMin( 0, pYear, pMonth, pDay, pHour, pMin ); } public static UtilDateAdaptor offsetWallToHour( int pOffsetMinutes, int pYear, int pMonth, int pDay, int pHour ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToHour, pYear, pMonth, pDay, pHour, 0, 0, 0 ); } public static UtilDateAdaptor currentWall( int pYear, int pMonth, int pDay, int pHour ) { return offsetWallToHour( calculateCurrentUTCtoWallOffsetMinutes(), pYear, pMonth, pDay, pHour ); } public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay, int pHour ) { return offsetWallToHour( 0, pYear, pMonth, pDay, pHour ); } public static UtilDateAdaptor offsetWallToDay( int pOffsetMinutes, int pYear, int pMonth, int pDay ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToDay, pYear, pMonth, pDay, 0, 0, 0, 0 ); } public static UtilDateAdaptor currentWall( int pYear, int pMonth, int pDay ) { return offsetWallToDay( calculateCurrentUTCtoWallOffsetMinutes(), pYear, pMonth, pDay ); } public static UtilDateAdaptor zulu( int pYear, int pMonth, int pDay ) { return offsetWallToDay( 0, pYear, pMonth, pDay ); } public static UtilDateAdaptor offsetWallToMonth( int pOffsetMinutes, int pYear, int pMonth ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToMonth, pYear, pMonth, 0, 0, 0, 0, 0 ); } public static UtilDateAdaptor currentWall( int pYear, int pMonth ) { return offsetWallToMonth( calculateCurrentUTCtoWallOffsetMinutes(), pYear, pMonth ); } public static UtilDateAdaptor zulu( int pYear, int pMonth ) { return offsetWallToMonth( 0, pYear, pMonth ); } public static UtilDateAdaptor offsetWallToYear( int pOffsetMinutes, int pYear ) { return new UtilDateAdaptor( pOffsetMinutes, TemporalResolution.ToYear, pYear, 0, 0, 0, 0, 0, 0 ); } public static UtilDateAdaptor currentWall( int pYear ) { return offsetWallToYear( calculateCurrentUTCtoWallOffsetMinutes(), pYear ); } public static UtilDateAdaptor zulu( int pYear ) { return offsetWallToYear( 0, pYear ); } 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; } public TemporalResolution getTemporalResolution() { return TemporalResolution.values()[mTemporalFields]; } public int getUTCtoWallOffsetMinutes() { return mUTCtoWallOffsetMinutes; } @Override public int getZuluOffsetMins() { return mUTCtoWallOffsetMinutes; } @Override public int getYear() { return mYear; } @Override public int getMonth() { return mMonth; } @Override public int getDay() { return mDay; } @Override public int getHour() { return mHour; } @Override public int getMin() { return mMin; } @Override public int getSec() { return mSec; } @Override public int getMilliSec() { return mMilliSec; } public long getUTClong() { int zYear = mYear; int zMonth = mMonth; int zDay = mDay; int zHour = mHour; int zMin = mMin; if ( mUTCtoWallOffsetMinutes != 0 ) // then Adjust the time to UTC { zMin -= mUTCtoWallOffsetMinutes; // subtract the offset: to advance those to the west, and retard those to the east. while ( zMin < 0 ) { zMin += 60; if ( --zHour < 0 ) { zHour += 24; if ( --zDay < 1 ) { if ( --zMonth < 1 ) { zMonth = 12; zYear--; } zDay = Month.daysIn( zYear, zMonth ); } } } while ( 60 <= zMin ) { zMin -= 60; if ( 23 < ++zHour ) { zHour -= 24; } } } return UTC( zYear, zMonth, zDay, zHour, zMin, mSec, mMilliSec ); } 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(); } private UtilDateAdaptor( long pUTC, TemporalResolution pTemporalResolution ) { super( new Date( pUTC ), TemporalResolution.deNull( pTemporalResolution ).ordinal() ); } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/commonfoundation/typeutils/gregorian/UtilDateAdaptor.java
Revision | Author | Commited | Message |
---|---|---|---|
942 Diff | GeorgeS | Mon 02 Jun, 2014 23:41:46 +0000 | Extracting commonfoundation |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
912 Diff | GeorgeS | Fri 28 Jun, 2013 06:48:05 +0000 | Revert to mixed & Working (PEDS & Prioritizer) code! |
898 Diff | GeorgeS | Sun 17 Mar, 2013 21:46:33 +0000 | Temporal!!! |
897 Diff | GeorgeS | Mon 25 Feb, 2013 02:04:34 +0000 | |
868 Diff | GeorgeS | Mon 26 Nov, 2012 01:28:51 +0000 | |
867 Diff | GeorgeS | Sun 25 Nov, 2012 22:20:46 +0000 | Updated Field Name |
865 Diff | GeorgeS | Mon 19 Nov, 2012 02:25:29 +0000 | |
864 Diff | GeorgeS | Mon 19 Nov, 2012 01:48:25 +0000 | |
859 | GeorgeS | Mon 05 Nov, 2012 01:26:38 +0000 |