Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2005 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.chrono;
 
Abstract implementation of a calendar system based around fixed length months.

As the month length is fixed various calculations can be optimised. This implementation assumes any additional days after twelve months fall into a thirteenth month.

BasicFixedMonthChronology is thread-safe and immutable, and all subclasses must be as well.

Author(s):
Brian S O'Neill
Stephen Colebourne
Since:
1.2, refactored from CopticChronology
 
 abstract class BasicFixedMonthChronology extends BasicChronology {

    
Serialization lock
 
     private static final long serialVersionUID = 261387371998L;

    
The length of the month.
 
     static final int MONTH_LENGTH = 30;

    
The typical millis per year.
 
     static final long MILLIS_PER_YEAR =
         (long) (365.25 * .);

    
The length of the month in millis.
 
     static final long MILLIS_PER_MONTH = ((long) * .;
 
     //-----------------------------------------------------------------------
     
Restricted constructor.

Parameters:
base the base chronology
param the init parameter
minDaysInFirstWeek the minimum days in the first week
 
     BasicFixedMonthChronology(Chronology baseObject paramint minDaysInFirstWeek) {
         super(baseparamminDaysInFirstWeek);
     }
 
     //-----------------------------------------------------------------------
     long setYear(long instantint year) {
         // optimsed implementation of set, due to fixed months
         int thisYear = getYear(instant);
         int dayOfYear = getDayOfYear(instantthisYear);
         int millisOfDay = getMillisOfDay(instant);
 
         if (dayOfYear > 365) {
             // Current year is leap, and day is leap.
             if (!isLeapYear(year)) {
                 // Moving to a non-leap year, leap day doesn't exist.
                 dayOfYear--;
             }
         }
 
         instant = getYearMonthDayMillis(year, 1, dayOfYear);
         instant += millisOfDay;
         return instant;
     }
 
     //-----------------------------------------------------------------------
     long getYearDifference(long minuendInstantlong subtrahendInstant) {
         // optimsed implementation of getDifference, due to fixed months
         int minuendYear = getYear(minuendInstant);
         int subtrahendYear = getYear(subtrahendInstant);
 
         // Inlined remainder method to avoid duplicate calls to get.
         long minuendRem = minuendInstant - getYearMillis(minuendYear);
         long subtrahendRem = subtrahendInstant - getYearMillis(subtrahendYear);
 
         int difference = minuendYear - subtrahendYear;
         if (minuendRem < subtrahendRem) {
             difference--;
         }
         return difference;
     }
 
     //-----------------------------------------------------------------------
    long getTotalMillisByYearMonth(int yearint month) {
        return ((month - 1) * );
    }
    //-----------------------------------------------------------------------
    int getDayOfMonth(long millis) {
        // optimised for fixed months
        return (getDayOfYear(millis) - 1) %  + 1;
    }
    //-----------------------------------------------------------------------
    boolean isLeapYear(int year) {
        return (year & 3) == 3;
    }
    //-----------------------------------------------------------------------
    int getDaysInYearMonth(int yearint month) {
        return (month != 13) ?  : (isLeapYear(year) ? 6 : 5);
    }
    //-----------------------------------------------------------------------
    int getDaysInMonthMax() {
        return ;
    }
    //-----------------------------------------------------------------------
    int getDaysInMonthMax(int month) {
        return (month != 13 ?  : 6);
    }
    //-----------------------------------------------------------------------
    int getMonthOfYear(long millis) {
        return (getDayOfYear(millis) - 1) /  + 1;
    }
    //-----------------------------------------------------------------------
    int getMonthOfYear(long millisint year) {
        long monthZeroBased = (millis - getYearMillis(year)) / ;
        return ((intmonthZeroBased) + 1;
    }
    //-----------------------------------------------------------------------
    int getMaxMonth() {
        return 13;
    }
    //-----------------------------------------------------------------------
    long getAverageMillisPerYear() {
        return ;
    }
    //-----------------------------------------------------------------------
        return  / 2;
    }
    //-----------------------------------------------------------------------
    long getAverageMillisPerMonth() {
        return ;
    }
New to GrepCode? Check out our FAQ X