1 16 package org.joda.time.base; 17 18 import java.io.Serializable ; 19 20 import org.joda.time.Chronology; 21 import org.joda.time.DateTimeUtils; 22 import org.joda.time.DateTimeZone; 23 import org.joda.time.ReadableDateTime; 24 import org.joda.time.chrono.ISOChronology; 25 import org.joda.time.convert.ConverterManager; 26 import org.joda.time.convert.InstantConverter; 27 28 43 public abstract class BaseDateTime 44 extends AbstractDateTime 45 implements ReadableDateTime, Serializable { 46 47 48 private static final long serialVersionUID = -6728882245981L; 49 50 51 private long iMillis; 52 53 private Chronology iChronology; 54 55 60 public BaseDateTime() { 61 this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance()); 62 } 63 64 72 public BaseDateTime(DateTimeZone zone) { 73 this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone)); 74 } 75 76 85 public BaseDateTime(Chronology chronology) { 86 this(DateTimeUtils.currentTimeMillis(), chronology); 87 } 88 89 96 public BaseDateTime(long instant) { 97 this(instant, ISOChronology.getInstance()); 98 } 99 100 109 public BaseDateTime(long instant, DateTimeZone zone) { 110 this(instant, ISOChronology.getInstance(zone)); 111 } 112 113 123 public BaseDateTime(long instant, Chronology chronology) { 124 super(); 125 iChronology = checkChronology(chronology); 126 iMillis = checkInstant(instant, iChronology); 127 } 128 129 145 public BaseDateTime(Object instant, DateTimeZone zone) { 146 super(); 147 InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); 148 Chronology chrono = checkChronology(converter.getChronology(instant, zone)); 149 iChronology = chrono; 150 iMillis = checkInstant(converter.getInstantMillis(instant, chrono), chrono); 151 } 152 153 167 public BaseDateTime(Object instant, Chronology chronology) { 168 super(); 169 InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); 170 iChronology = checkChronology(converter.getChronology(instant, chronology)); 171 iMillis = checkInstant(converter.getInstantMillis(instant, chronology), iChronology); 172 } 173 174 187 public BaseDateTime( 188 int year, 189 int monthOfYear, 190 int dayOfMonth, 191 int hourOfDay, 192 int minuteOfHour, 193 int secondOfMinute, 194 int millisOfSecond) { 195 this(year, monthOfYear, dayOfMonth, hourOfDay, 196 minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstance()); 197 } 198 199 214 public BaseDateTime( 215 int year, 216 int monthOfYear, 217 int dayOfMonth, 218 int hourOfDay, 219 int minuteOfHour, 220 int secondOfMinute, 221 int millisOfSecond, 222 DateTimeZone zone) { 223 this(year, monthOfYear, dayOfMonth, hourOfDay, 224 minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstance(zone)); 225 } 226 227 243 public BaseDateTime( 244 int year, 245 int monthOfYear, 246 int dayOfMonth, 247 int hourOfDay, 248 int minuteOfHour, 249 int secondOfMinute, 250 int millisOfSecond, 251 Chronology chronology) { 252 super(); 253 iChronology = checkChronology(chronology); 254 long instant = iChronology.getDateTimeMillis(year, monthOfYear, dayOfMonth, 255 hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); 256 iMillis = checkInstant(instant, iChronology); 257 } 258 259 269 protected Chronology checkChronology(Chronology chronology) { 270 return DateTimeUtils.getChronology(chronology); 271 } 272 273 283 protected long checkInstant(long instant, Chronology chronology) { 284 return instant; 285 } 286 287 294 public long getMillis() { 295 return iMillis; 296 } 297 298 303 public Chronology getChronology() { 304 return iChronology; 305 } 306 307 316 protected void setMillis(long instant) { 317 iMillis = checkInstant(instant, iChronology); 318 } 319 320 328 protected void setChronology(Chronology chronology) { 329 iChronology = checkChronology(chronology); 330 } 331 332 } 333 | Popular Tags |