Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2011 Stephen Colebourne
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 package org.joda.time.base;
 
 
BaseDateTime is an abstract implementation of ReadableDateTime that stores data in long and Chronology fields.

This class should generally not be used directly by API users. The org.joda.time.ReadableDateTime interface should be used when different kinds of date/time objects are to be referenced.

BaseDateTime subclasses may be mutable and not thread-safe.

Author(s):
Stephen Colebourne
Kandarp Shah
Brian S O'Neill
Since:
1.0
 
 public abstract class BaseDateTime
         extends AbstractDateTime
         implements ReadableDateTimeSerializable {

    
Serialization lock
 
     private static final long serialVersionUID = -6728882245981L;

    
The millis from 1970-01-01T00:00:00Z
 
     private volatile long iMillis;
    
The chronology to use
 
     private volatile Chronology iChronology;
 
     //-----------------------------------------------------------------------
     
Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.
 
     public BaseDateTime() {
         this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance());
     }

    
Constructs an instance set to the current system millisecond time using ISOChronology in the specified time zone.

If the specified time zone is null, the default zone is used.

Parameters:
zone the time zone, null means default zone
 
     public BaseDateTime(DateTimeZone zone) {
         this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone));
     }

    
Constructs an instance set to the current system millisecond time using the specified chronology.

If the chronology is null, ISOChronology in the default time zone is used.

Parameters:
chronology the chronology, null means ISOChronology in default zone
 
     public BaseDateTime(Chronology chronology) {
         this(DateTimeUtils.currentTimeMillis(), chronology);
     }
 
     //-----------------------------------------------------------------------
     
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the default time zone.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
 
     public BaseDateTime(long instant) {
         this(instant, ISOChronology.getInstance());
     }

    
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the specified time zone.

If the specified time zone is null, the default zone is used.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
zone the time zone, null means default zone
    public BaseDateTime(long instantDateTimeZone zone) {
        this(instant, ISOChronology.getInstance(zone));
    }

    
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using the specified chronology.

If the chronology is null, ISOChronology in the default time zone is used.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
chronology the chronology, null means ISOChronology in default zone
    public BaseDateTime(long instantChronology chronology) {
        super();
         = checkChronology(chronology);
         = checkInstant(instant);
    }
    //-----------------------------------------------------------------------
    
Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.

If the object contains no chronology, ISOChronology is used. If the specified time zone is null, the default zone is used.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

Parameters:
instant the datetime object
zone the time zone
Throws:
java.lang.IllegalArgumentException if the instant is invalid
    public BaseDateTime(Object instantDateTimeZone zone) {
        super();
        InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant);
        Chronology chrono = checkChronology(converter.getChronology(instantzone));
         = chrono;
         = checkInstant(converter.getInstantMillis(instantchrono), chrono);
    }

    
Constructs an instance from an Object that represents a datetime, using the specified chronology.

If the chronology is null, ISO in the default time zone is used.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

Parameters:
instant the datetime object
chronology the chronology
Throws:
java.lang.IllegalArgumentException if the instant is invalid
    public BaseDateTime(Object instantChronology chronology) {
        super();
        InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant);
         = checkChronology(converter.getChronology(instantchronology));
         = checkInstant(converter.getInstantMillis(instantchronology), );
    }
    //-----------------------------------------------------------------------
    
Constructs an instance from datetime field values using ISOChronology in the default time zone.

Parameters:
year the year
monthOfYear the month of the year
dayOfMonth the day of the month
hourOfDay the hour of the day
minuteOfHour the minute of the hour
secondOfMinute the second of the minute
millisOfSecond the millisecond of the second
    public BaseDateTime(
            int year,
            int monthOfYear,
            int dayOfMonth,
            int hourOfDay,
            int minuteOfHour,
            int secondOfMinute,
            int millisOfSecond) {
        this(yearmonthOfYeardayOfMonthhourOfDay,
            minuteOfHoursecondOfMinutemillisOfSecond, ISOChronology.getInstance());
    }

    
Constructs an instance from datetime field values using ISOChronology in the specified time zone.

If the specified time zone is null, the default zone is used.

Parameters:
year the year
monthOfYear the month of the year
dayOfMonth the day of the month
hourOfDay the hour of the day
minuteOfHour the minute of the hour
secondOfMinute the second of the minute
millisOfSecond the millisecond of the second
zone the time zone, null means default time zone
    public BaseDateTime(
            int year,
            int monthOfYear,
            int dayOfMonth,
            int hourOfDay,
            int minuteOfHour,
            int secondOfMinute,
            int millisOfSecond,
            DateTimeZone zone) {
        this(yearmonthOfYeardayOfMonthhourOfDay,
            minuteOfHoursecondOfMinutemillisOfSecond, ISOChronology.getInstance(zone));
    }

    
Constructs an instance from datetime field values using the specified chronology.

If the chronology is null, ISOChronology in the default time zone is used.

Parameters:
year the year
monthOfYear the month of the year
dayOfMonth the day of the month
hourOfDay the hour of the day
minuteOfHour the minute of the hour
secondOfMinute the second of the minute
millisOfSecond the millisecond of the second
chronology the chronology, null means ISOChronology in default zone
    public BaseDateTime(
            int year,
            int monthOfYear,
            int dayOfMonth,
            int hourOfDay,
            int minuteOfHour,
            int secondOfMinute,
            int millisOfSecond,
            Chronology chronology) {
        super();
         = checkChronology(chronology);
        long instant = .getDateTimeMillis(yearmonthOfYeardayOfMonth,
            hourOfDayminuteOfHoursecondOfMinutemillisOfSecond);
         = checkInstant(instant);
    }
    //-----------------------------------------------------------------------
    
Checks the specified chronology before storing it, potentially altering it. This method must not access any instance variables.

This implementation converts nulls to ISOChronology in the default zone.

Parameters:
chronology the chronology to use, may be null
Returns:
the chronology to store in this datetime, not null
    protected Chronology checkChronology(Chronology chronology) {
        return DateTimeUtils.getChronology(chronology);
    }

    
Checks the specified instant before storing it, potentially altering it. This method must not access any instance variables.

This implementation simply returns the instant.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z to round
chronology the chronology to use, not null
Returns:
the instant to store in this datetime
    protected long checkInstant(long instantChronology chronology) {
        return instant;
    }
    //-----------------------------------------------------------------------
    
Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Returns:
the number of milliseconds since 1970-01-01T00:00:00Z
    public long getMillis() {
        return ;
    }

    
Gets the chronology of the datetime.

Returns:
the Chronology that the datetime is using
    public Chronology getChronology() {
        return ;
    }
    //-----------------------------------------------------------------------
    
Sets the milliseconds of the datetime.

All changes to the millisecond field occurs via this method. Override and block this method to make a subclass immutable.

Parameters:
instant the milliseconds since 1970-01-01T00:00:00Z to set the datetime to
    protected void setMillis(long instant) {
         = checkInstant(instant);
    }

    
Sets the chronology of the datetime.

All changes to the chronology field occurs via this method. Override and block this method to make a subclass immutable.

Parameters:
chronology the chronology to set
    protected void setChronology(Chronology chronology) {
         = checkChronology(chronology);
    }
New to GrepCode? Check out our FAQ X