litesoft
@ 858
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 |
// 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.gregorian.*; 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, YearMonthDayAccessor { private UtilDateAdaptor( long pUTC, int pTimeFields ) { super( new Date( pUTC ), pTimeFields ); } /** * create with NOW */ public UtilDateAdaptor() { this( System.currentTimeMillis(), 4 ); } public UtilDateAdaptor( Date pDate ) { super( pDate, 4 ); } /** * @param pTimeFields 0-4 */ public UtilDateAdaptor( Date pDate, int pTimeFields ) { super( pDate, (pTimeFields < 0) ? 0 : (4 < pTimeFields) ? 4 : pTimeFields ); } public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec ) { super( calculateCurrentUTCtoWallOffsetMinutes(), 4, pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ); } public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec ) { super( calculateCurrentUTCtoWallOffsetMinutes(), 3, pYear, pMonth, pDay, pHour, pMin, pSec, 0 ); } public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour, int pMin ) { super( calculateCurrentUTCtoWallOffsetMinutes(), 2, pYear, pMonth, pDay, pHour, pMin, 0, 0 ); } public UtilDateAdaptor( int pYear, int pMonth, int pDay, int pHour ) { super( calculateCurrentUTCtoWallOffsetMinutes(), 1, pYear, pMonth, pDay, pHour, 0, 0, 0 ); } public UtilDateAdaptor( int pYear, int pMonth, int pDay ) { super( calculateCurrentUTCtoWallOffsetMinutes(), 0, pYear, pMonth, pDay, 0, 0, 0, 0 ); } public static UtilDateAdaptor fromUtilDateToString( String pDateToString ) { return (pDateToString != null) ? new UtilDateAdaptor( UtilDateAdaptor.parseUtilDate( pDateToString ), 4 ) : null; } public static UtilDateAdaptor fromUtilDateJustDateToString( String pDateToString ) { return (pDateToString != null) ? new UtilDateAdaptor( UtilDateAdaptor.parseUtilDate( pDateToString ), 0 ) : null; } @Override public TimeRes getTimeRes() { return TimeRes.fromIndex( mTimeFields - 1 ); } public int getTimeFields() { return mTimeFields; } public int getUTCtoWallOffsetMinutes() { 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() { 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() { return new SimpleTimestamp( this ).toString(); } private static int calculateCurrentUTCtoWallOffsetMinutes() { return new UtilDateAdaptor( 0, 0 ).getUTCtoWallOffsetMinutes(); } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/UtilDateAdaptor.java
Revision | Author | Commited | Message |
---|---|---|---|
858 Diff | GeorgeS | Sun 04 Nov, 2012 18:40:40 +0000 | |
851 Diff | GeorgeS | Mon 08 Oct, 2012 00:05:32 +0000 | Breaking the code as Temporal changes are implemented... |
50 Diff | GeorgeS | Tue 13 Apr, 2010 11:51:38 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |