Class BigDate

  • All Implemented Interfaces:
    Serializable, Cloneable, Comparable<Object>

    public class BigDate
    extends Object
    implements Cloneable, Serializable, Comparable<Object>
    Convert Gregorian YYYY MM DD back and forth to ordinal days since 1970 Jan 1, Thursday (sometimes called Julian or datestamp form). BigDate objects are not designed for storing dates in a database, just for conversion. Long term storage should store the ordinal either as an int, or possibly as a short. The BigDate constructor stores the date both in ordinal and Gregorian forms internally. If you store one, it creates the other.

    The standard Sun Date won't handle dates prior to 1970 among other problems. BigDate handles dates 999,999 BC Jan 1 to 999,999 AD Dec 31, 0 = 1970 Jan 1.

    Are the following quirks of the calendar considered in this code?

    yes
    1900 is not a leap year (mod 100).
    yes
    2000 is a leap year (mod 400).
    yes
    The 10 missing days in 1582 October. (Pope Gregory's correction) 1582 Oct 5 to 1582 Oct 14 never happened.
    partly
    Britain and its territories (including the USA and Canada) adopted the Gregorian correction in 1752. By then, 11 days had to be dropped. 1752 September 3 to 1752 September 13 never happened. However, you can modify constants in BigDate to use the British calendar. Such a change only affects dates prior to 1753 since BigDate calendar is based on Jan 1, 1970. toOrdinal with the Gregorian and British scheme will give the same number for recent dates. You must recompile with the isBritish boolean changed to true.
    yes
    missing year 0 between 1 BC and 1 AD.
    no
    in Roman times leap years occurred at irregular intervals, Considered inauspicious, they were avoided during war. Instead we presume leap years every 4 years even back to 999,999BC.
    no
    leap seconds.

    Normally all you need is one BigDate object that you use for all interconversions with set(ordinal), set(yyy,mm,dd) and getOrdinal(), getYYYY(), getMM(), getDD().

    java.util.Date has some odd habits, using 101 to represent the year 2001, and 11 to represent December. BigDate is more conventional. You use 2001 to represent the year 2001 and 12 to represent December.

    BigDate implements proleptic Gregorian and Julian calendars. That is, dates are computed by extrapolating the current rules indefinitely far backward and forward in time. As a result, BigDate may be used for all years to generate meaningful and consistent results. However, dates obtained using BigDate are historically accurate only from March 1, 4 AD onward, when modern Julian calendar rules were adopted. Before this date, leap year rules were applied irregularly, and before 45 BC the Julian calendar did not even exist. Prior to the institution of the Gregorian calendar, New Year's Day was March 25. To avoid confusion, this calendar always uses January 1.

    TODO Future enhancements: - handle time, and timezones, interconversion with GregorianCalendar dates.

    Version:
    4.9, 2006-03-04

    Author:
    Roedy Green, Canadian Mind Products
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BYPASSCHECK
      Constant: when passed to a constructor, it means caller guarantees YYYY MM DD are valid including leap year effects and missing day effects.
      static int CHECK
      constant: when passed to a contructor it means BigDate should check that YYYY MM DD are valid.
      protected int dd
      Day, 1 to 31.
      static boolean isBritish
      PLEASE CONFIGURE isBritish BEFORE COMPILING.
      static int MAX_ORDINAL
      Constant: biggest ordinal that BigDate will accept, corresponds to 999,999 Dec 31 AD.
      static int MAX_YEAR
      Constant: biggest year that BigDate handles, 999,999 AD.
      static int MIN_ORDINAL
      Constant: earliest ordinal that BigDate handles; corresponds to 999,999 Jan 01 BC.
      static int MIN_YEAR
      Constant: earliest year that BigDate handles, 999,999 BC.
      protected int mm
      Month, 1 to 12.
      static int NORMALISE
      Constant: when passed to a constructor, it means any invalid dates are converted into the equivalent valid one.
      e.g.
      static int NORMALIZE
      Constant: American spelling alias for NORMALISE.
      static int NULL_ORDINAL
      Constant: ordinal to represent a null date -2,147,483,648, null Gregorian is 0,0,0.
      static long NULL_TIMESTAMP
      Constant : value for a null TimeStamp -9,223,372,036,854,775,808
      protected int ordinal
      Ordinal days since Jan 01, 1970.
      protected int yyyy
      Year, -999,999 to +999,999, negative is BC, positive is AD, 0 is null.
    • Constructor Summary

      Constructors 
      Constructor Description
      BigDate()
      Constructor for the null date.
      BigDate​(double prolepticJulianDay)
      Construct a BigDate object given the Propleptic Julian day number.
      BigDate​(int ordinal)
      Ordinal constructor.
      BigDate​(int yyyy, int mm, int dd)
      Construct a BigDate object given a Gregorian date yyyy, mm, dd; always rejects invalid dates.
      BigDate​(int yyyy, int mm, int dd, int how)
      Construct a BigDate object given a Gregorian date yyyy, mm, dd; allows control of how invalid dates are handled.
      BigDate​(BigDate b)
      Copy constructor
      BigDate​(String yyyy_mm_dd)
      Create a BigDate object from a sting of the form: yyyy-mm-dd must have 4-digit years, and use dashes between the number and no sign Does extensive checks considering leap years, missing days etc.
      BigDate​(Date utc, TimeZone timeZone)
      Constructor from Date, loses time information.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDays​(int days)
      increment this date by a number of days.
      static int[] age​(BigDate birthDate, BigDate asof)
      calculate the age in years, months and days.
      static int calendarDayOfWeek​(int ordinal)
      Get day of week for given ordinal.
      int compareTo​(Object anotherBigDate)
      Defines Natural Order for the BigDate class.
      static int dayOfWeek​(int ordinal)
      Get day of week for given ordinal.
      static int daysInMonth​(int mm, boolean leap)
      How many days are there in a given month?
      static int daysInMonth​(int mm, int yyyy)
      How many days are there in a given month?
      protected static int daysInYearPriorToMonth​(int mm, boolean leap)
      How many days were there in the year prior to the first day of the given month?
      protected static int dddToMM​(int ddd, boolean leap)
      Convert day number ddd in year to month.
      boolean equals​(Object d)
      Compares with another BigDate to see if they refer to the same date.
      static int flooredMulDiv​(int multiplicand, int multiplier, int divisor)
      Multiply then divide using floored rather than the usual truncated arithmetic, using a long intermediate.
      int getCalendarDayOfWeek()
      Get day of week for this BigDate.
      static String getCopyright()
      Embeds copyright notice
      Date getDate​(TimeZone timeZone)
      Get java.util.Date object corresponding to this BigDate,
      int getDayOfWeek()
      Get day of week for this BigDate.
      int getDD()
      get day of month for this BigDate.
      int getDDD()
      Get day number in the year for this BigDate.
      int getISODayOfWeek()
      Get day of week 1 to 7 for this BigDate according to the ISO standard IS-8601.
      int getISOWeekNumber()
      Get week number 1 to 53 of the year this date falls in, according to the rules of ISO standard IS-8601 section 5.5.
      Date getLocalDate()
      Get java.util.Date object corresponding to this BigDate.
      long getLocalTimeStamp()
      Get milliseconds since 1970 Jan 01 00:00 GMT for this BigDate.
      int getMM()
      Get month of year for this BigDate.
      int getOrdinal()
      get days since 1970 Jan 01 for this BigDate.
      double getProplepticJulianDay()  
      int getSeason()
      Get season of year for this BigDate.
      long getTimeStamp​(TimeZone timeZone)
      Get milliseconds since 1970 Jan 01 00:00 GMT for this BigDate, as at the start of day 0:00.
      Date getUTCDate()
      Get java.util.Date object corresponding to this BigDate.
      long getUTCTimeStamp()
      Get milliseconds since 1970 Jan 01 00:00 GMT for this BigDate.
      int getWeekNumber()
      Get week number 1 to 53 of the year this date falls in.
      int getYYYY()
      Get year for this BigDate.
      int hashCode()
      hashCode for use in Hashtable lookup
      static boolean isLeap​(int yyyy)
      Is the given year a leap year, considering history, mod 100 and mod 400 rules? By 1582, this excess of leap years had built up noticeably.
      static int isoDayOfWeek​(int ordinal)
      Get day of week 1 to 7 for this ordinal according to the ISO standard IS-8601.
      static boolean isValid​(int yyyy, int mm, int dd)
      Test to see if the given yyyy, mm, dd date is legitimate.
      static boolean isValid​(String yyyy_mm_dd)
      Test to see if the given yyyy-mm-dd is a date as a String is legitimate.
      protected static int jan01OfYear​(int yyyy)
      Ordinal date of Jan 01 of the given year.
      static BigDate localToday()
      Returns a BigDate object initialised to today's local date.
      protected void normalise()
      Clean up an invalid date, leaving the results internally.
      e.g.
      static int nthXXXDay​(int which, int dayOfWeek, int yyyy, int mm)
      Find the first monday in a given month, the 3rd monday or the last Thursday...
      static int ordinalOfnthXXXDay​(int which, int dayOfWeek, int yyyy, int mm)
      Find the first monday in a given month, the 3rd monday or the last Thursday...
      void set​(int ordinal)
      Set the ordinal field, and compute the equivalent internal Gregorian yyyy mm dd fields.
      void set​(int yyyy, int mm, int dd)
      Set the yyyy mm dd Gregorian fields, and compute the internal ordinal equivalent.
      void set​(int yyyy, int mm, int dd, int how)
      Set the Gregorian fields, and compute the ordinal equivalent with the same modifiers CHECK, NORMALIZE, BYPASSCHECK as the constructor.
      void setDateAtTime​(long utcTimestamp, TimeZone timeZone)
      Sets the date that corresponding to a given utc timestamp at a given TimeZone.
      void setOrdinal​(int ordinal)
      Set the ordinal field, and compute the equivalent internal Gregorian yyyy mm dd fields.
      static BigDate today​(TimeZone timeZone)
      Returns a BigDate object initialised to the date right now in the given timezone.
      String toDowMMDDYY()
      Convert date to a human-readable String wed mm/dd/yy
      protected void toGregorian()
      converts ordinal to YYYY MM DD, leaving results internally.
      protected void toOrdinal()
      Convert date in form YYYY MM DD into days since the epoch, leaving results internally.
      static int toOrdinal​(int yyyy, int mm, int dd)
      Convert date in form YYYY MM DD into days since the 1970 Jan 01.
      String toString()
      Convert date to a human-readable String.
      static BigDate UTCToday()
      Returns a BigDate object initialised to today's UTC (Greenwich GMT) date, in other words that date the people in Greenwich England think it is right now.
    • Field Detail

      • BYPASSCHECK

        public static final int BYPASSCHECK
        Constant: when passed to a constructor, it means caller guarantees YYYY MM DD are valid including leap year effects and missing day effects. BigDate will not bother to check them.
        See Also:
        Constant Field Values
      • CHECK

        public static final int CHECK
        constant: when passed to a contructor it means BigDate should check that YYYY MM DD are valid.
        See Also:
        Constant Field Values
      • MAX_ORDINAL

        public static final int MAX_ORDINAL
        Constant: biggest ordinal that BigDate will accept, corresponds to 999,999 Dec 31 AD.
      • MAX_YEAR

        public static final int MAX_YEAR
        Constant: biggest year that BigDate handles, 999,999 AD.
        See Also:
        Constant Field Values
      • MIN_ORDINAL

        public static final int MIN_ORDINAL
        Constant: earliest ordinal that BigDate handles; corresponds to 999,999 Jan 01 BC.
      • MIN_YEAR

        public static final int MIN_YEAR
        Constant: earliest year that BigDate handles, 999,999 BC.
        See Also:
        Constant Field Values
      • NORMALISE

        public static final int NORMALISE
        Constant: when passed to a constructor, it means any invalid dates are converted into the equivalent valid one.
        e.g. 1954 September 31 -> 1954 October 1.
        1954 October -1 -> 1954 September 29.
        1954 13 01 -> 1955 01 01.
        See Also:
        Constant Field Values
      • NORMALIZE

        public static final int NORMALIZE
        Constant: American spelling alias for NORMALISE.
        See Also:
        NORMALISE
      • NULL_ORDINAL

        public static final int NULL_ORDINAL
        Constant: ordinal to represent a null date -2,147,483,648, null Gregorian is 0,0,0.
        See Also:
        Constant Field Values
      • NULL_TIMESTAMP

        public static final long NULL_TIMESTAMP
        Constant : value for a null TimeStamp -9,223,372,036,854,775,808
        See Also:
        Constant Field Values
      • isBritish

        public static final boolean isBritish
        PLEASE CONFIGURE isBritish BEFORE COMPILING. Mysterious missing days in the calendar. Pope Gregory: 1582 Oct 4 Thursday, was followed immediately by 1582 Oct 15 Friday dropping 10 days. British: 1752 Sep 2 Wednesday was followed immediately by 1752 Sep 14 Thursday dropping 12 days. Constant: true if you want the British calender, false if Pope Gregory's. You must recompile for it to have effect. For Britain, the USA and Canada it should be true.
        See Also:
        Constant Field Values
      • dd

        protected transient int dd
        Day, 1 to 31. If size of BigDate objects were a consideration, you could make this a byte.
      • mm

        protected transient int mm
        Month, 1 to 12. If size of BigDate objects were a consideration, you could make this a byte.
      • ordinal

        protected int ordinal
        Ordinal days since Jan 01, 1970. -365968798 to 364522971. i.e. 999,999 BC to 999,999 AD.
      • yyyy

        protected transient int yyyy
        Year, -999,999 to +999,999, negative is BC, positive is AD, 0 is null.
    • Constructor Detail

      • BigDate

        public BigDate()
        Constructor for the null date. Gets set to null date, NOT current date like Java Date!!. BigDate.localToday() will create an object initialised to today's date.
        See Also:
        localToday(), UTCToday(), today(java.util.TimeZone)
      • BigDate

        public BigDate​(double prolepticJulianDay)
        Construct a BigDate object given the Propleptic Julian day number. The Propleptic Julian calendar that astronomers use starts with 0 at noon on 4713 BCE January 1. In contrast, BigDate's Ordinal base is 1970 Jan 1.
        Parameters:
        prolepticJulianDay - days since 4713 BC Jan 1 noon. Such numbers usually arise in astronomical calculation. You don't need to concern yourself with the strangeness of the Julian calendar, just its simple day numbering. BEWARE! after adjusting for noon, fractional parts are discarded. BigDate tracks only dates, not dates and times. e.g. 2000-3-20 noon is 2,451,624 in proleptic day numbers. 1970-1-1 is 2,440,588 1600-1-1 is 2,305,448 1500-1-1 is 2,268,933 0001-1-1 is 1,721,424 -0001-12-31 is 1,721,423 -0006-1-1 is 1,719,232 -4713-1-1 is 0
      • BigDate

        public BigDate​(int ordinal)
        Ordinal constructor. The ordinal must be NULL_ORDINAL or in the range -365968798 to 364522971 i.e. 999,999 BC to 999,999 AD
        Parameters:
        ordinal - days since 1970 Jan 01.
      • BigDate

        public BigDate​(String yyyy_mm_dd)
        Create a BigDate object from a sting of the form: yyyy-mm-dd must have 4-digit years, and use dashes between the number and no sign Does extensive checks considering leap years, missing days etc.
        Parameters:
        yyyy_mm_dd - string of form "yyyy-mm-dd".
      • BigDate

        public BigDate​(BigDate b)
        Copy constructor
        Parameters:
        b - an existing BigDate object to use as a model for cloning another.
      • BigDate

        public BigDate​(Date utc,
                       TimeZone timeZone)
        Constructor from Date, loses time information.
        Parameters:
        utc - Date ( UTC date/time stamp )
        timeZone - Which timeZone do you want to know the date for that UTC time. e.g. TimeZone.getDefault(), new TimeZone("GMT")
      • BigDate

        public BigDate​(int yyyy,
                       int mm,
                       int dd)
        Construct a BigDate object given a Gregorian date yyyy, mm, dd; always rejects invalid dates. A null date is yyyy,mm,dd=0. BEWARE! In Java a lead 0 on an integer implies OCTAL.
        Parameters:
        yyyy - -999,999 (BC) to +999,999 (AD)
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        dd - day 1 to 31
        Throws:
        IllegalArgumentException - for invalid yyyy mm dd
      • BigDate

        public BigDate​(int yyyy,
                       int mm,
                       int dd,
                       int how)
        Construct a BigDate object given a Gregorian date yyyy, mm, dd; allows control of how invalid dates are handled. A null date is yyyy,mm,dd=0. BEWARE! In Java a lead 0 on an integer implies OCTAL.
        Parameters:
        yyyy - -999,999 (BC) to +999,999 (AD)
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        dd - day 1 to 31
        how - one of CHECK BYPASSCHECK NORMALIZE NORMALISE
    • Method Detail

      • UTCToday

        public static BigDate UTCToday()
        Returns a BigDate object initialised to today's UTC (Greenwich GMT) date, in other words that date the people in Greenwich England think it is right now. It works even if Java's default Timezone is not configured correctly, but it requires your system clock accurately set to UTC time. Experiment setting your system date/time to various values and making sure you are getting the expected results. Note the date in the created object does not keep updating every time you reference it with methods like getOrdinal or getDD. You always get the date the object was created.
        Returns:
        BigDate object initialised to today, in Greenwich.
        See Also:
        localToday(), today(java.util.TimeZone)
      • age

        public static int[] age​(BigDate birthDate,
                                BigDate asof)
        calculate the age in years, months and days.
        Parameters:
        birthDate - usually the birth of a person.
        asof - usually today, the day you want the age as of. asof must come after birthDate to get a meaningful result.
        Returns:
        array of three ints (not Integers). [0]=age in years, [1]=age in months, [2]=age in days.
        See Also:
        localToday(), today(java.util.TimeZone), UTCToday()
      • calendarDayOfWeek

        public static int calendarDayOfWeek​(int ordinal)
        Get day of week for given ordinal. It is one-based starting with Sunday.
        Parameters:
        ordinal - days since Jan 1, 1970 to test.
        Returns:
        day of week 1=Sunday 2=Monday 3=Tuesday 4=Wednesday 5=Thursday 6=Friday 7=Saturday Compatible with Sun's 1=Calendar.SUNDAY Not compatiblse with BigDate.getDayOfWeek.
        See Also:
        isoDayOfWeek(int), dayOfWeek(int), getCalendarDayOfWeek()
      • dayOfWeek

        public static int dayOfWeek​(int ordinal)
        Get day of week for given ordinal. Is it zero-based starting with Sunday.
        Parameters:
        ordinal - days since Jan 1, 1970 to test.
        Returns:
        day of week 0=Sunday 1=Monday 2=Tuesday 3=Wednesday 4=Thursday 5=Friday 6=Saturday WARNING: not compatible with 1=Calendar.SUNDAY
        See Also:
        calendarDayOfWeek(int), isoDayOfWeek(int), getDayOfWeek()
      • daysInMonth

        public static int daysInMonth​(int mm,
                                      boolean leap)
        How many days are there in a given month?
        Parameters:
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        leap - true if you are interested in a leap year
        Returns:
        how many days are in that month
      • daysInMonth

        public static int daysInMonth​(int mm,
                                      int yyyy)
        How many days are there in a given month?
        Parameters:
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        yyyy - year of interest.
        Returns:
        how many days are in that month
      • daysInYearPriorToMonth

        protected static int daysInYearPriorToMonth​(int mm,
                                                    boolean leap)
        How many days were there in the year prior to the first day of the given month?
        Parameters:
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date).
        leap - true if you are interested in a leap year.
        Returns:
        how many days in year prior to the start of that month.
      • dddToMM

        protected static int dddToMM​(int ddd,
                                     boolean leap)
        Convert day number ddd in year to month.
        Parameters:
        ddd - day number in year Jan 01 = 1, 1 to 366.
        leap - true if year of interest is boolean.
        Returns:
        month that day number would fall in.
      • flooredMulDiv

        public static int flooredMulDiv​(int multiplicand,
                                        int multiplier,
                                        int divisor)
        Multiply then divide using floored rather than the usual truncated arithmetic, using a long intermediate.
        Parameters:
        multiplicand - one of two numbers to multiply together
        multiplier - one of two numbers to multiply together
        divisor - number to divide by
        Returns:
        ( multiplicand * multiplier ) / divisor
      • getCopyright

        public static String getCopyright()
        Embeds copyright notice
        Returns:
        copyright notice
      • isLeap

        public static boolean isLeap​(int yyyy)
        Is the given year a leap year, considering history, mod 100 and mod 400 rules? By 1582, this excess of leap years had built up noticeably. At the suggestion of astronomers Luigi Lilio and Chistopher Clavius, Pope Gregory XIII dropped 10 days from the calendar. Thursday 1582 October 4 Julian was followed immediately by Friday 1582 October 15 Gregorian. He decreed that every 100 years, a leap year should be dropped except that every 400 years the leap year should be restored. Only Italy, Poland, Portugual and Spain went along with the new calendar immediately. One by one other countries adopted it in different years. Britain and its territories (including the USA and Canada) adopted it in 1752. By then, 11 days had to be dropped. 1752 September 2 was followed immediately by 1752 September 14. The Gregorian calendar is the most widely used scheme. This is the scheme endorsed by the US Naval observatory. It corrects the year to 365.2425. It gets ahead 1 day every 3289 years. For BC dates, the years the years 1, 5, 9 are leap years, not 4, 8, 12 as you might expect, from the general rule.
        Parameters:
        yyyy - year to test.
        Returns:
        true if the year is a leap year.
      • isValid

        public static boolean isValid​(String yyyy_mm_dd)
        Test to see if the given yyyy-mm-dd is a date as a String is legitimate. must have 4-digit years, and use dashes between the number and no sign Does extensive checks considering leap years, missing days etc.
        Parameters:
        yyyy_mm_dd - string of form "yyyy-mm-dd".
        Returns:
        true if that represents a valid date.
      • isValid

        public static boolean isValid​(int yyyy,
                                      int mm,
                                      int dd)
        Test to see if the given yyyy, mm, dd date is legitimate. Does extensive checks considering leap years, missing days etc.
        Parameters:
        yyyy - -999,999 (BC) to +999,999 (AD)
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        dd - day 1 to 31
        Returns:
        true if yyyy mm dd is a valid date.
      • isoDayOfWeek

        public static int isoDayOfWeek​(int ordinal)
        Get day of week 1 to 7 for this ordinal according to the ISO standard IS-8601. It is one-based starting with Monday.
        Parameters:
        ordinal - days since Jan 1, 1970 to test.
        Returns:
        day of week 1=Monday to 7=Sunday, 0 for null date. WARNING: not compatible with 1=Calendar.SUNDAY.
        See Also:
        dayOfWeek(int)
      • jan01OfYear

        protected static int jan01OfYear​(int yyyy)
        Ordinal date of Jan 01 of the given year.
        Parameters:
        yyyy - year of interest
        Returns:
        ordinal of Jan 01 of that year.
      • localToday

        public static BigDate localToday()
        Returns a BigDate object initialised to today's local date. It depends on Java's default Timezone being configured, and your system clock accurately set to UTC time. Experiment setting your system date/time to various values and making sure you are getting the expected results. Note the date in the created object does not keep updating every time you reference it with methods like getOrdinal or getDD. You always get the date the object was created. It is quite a production to get the local date. Best to ask once and save the today object.
        Returns:
        BigDate object initialised to today, local time.
        See Also:
        #see #UTCToday
      • nthXXXDay

        public static int nthXXXDay​(int which,
                                    int dayOfWeek,
                                    int yyyy,
                                    int mm)
        Find the first monday in a given month, the 3rd monday or the last Thursday...
        Parameters:
        which - 1=first 2=second 3=third 4=fourth 5=last (might be 4th or 5th)
        dayOfWeek - 0=Sunday 1=Monday 2=Tuesday 3=Wednesday 4=Thursday 5=Friday 6=Saturday WARNING: not compatible with 1=Calendar.SUNDAY.
        yyyy - year of interest.
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        Returns:
        day of month 1..31
      • ordinalOfnthXXXDay

        public static int ordinalOfnthXXXDay​(int which,
                                             int dayOfWeek,
                                             int yyyy,
                                             int mm)
        Find the first monday in a given month, the 3rd monday or the last Thursday...
        Parameters:
        which - 1=first 2=second 3=third 4=fourth 5=last (might be 4th or 5th)
        dayOfWeek - 0=Sunday 1=Monday 2=Tuesday 3=Wednesday 4=Thursday 5=Friday 6=Saturday WARNING: not compatible with 1=Calendar.SUNDAY.
        yyyy - year of interest.
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        Returns:
        day of month 1..31
      • toOrdinal

        public static int toOrdinal​(int yyyy,
                                    int mm,
                                    int dd)
        Convert date in form YYYY MM DD into days since the 1970 Jan 01. This method lets you convert directly from Gregorian to ordinal without creating a BigDate object. yyyy mm dd must be a valid date.
        Parameters:
        yyyy - -999,999 (BC) to +999,999 (AD)
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        dd - day 1 to 31
        Returns:
        ordinal, days since 1970 Jan 01.
      • today

        public static BigDate today​(TimeZone timeZone)
        Returns a BigDate object initialised to the date right now in the given timezone. It depends on your system clock accurately set to UTC time. Experiment setting your system date/time to various values and making sure you are getting the expected results. Note the date in the created object does not keep updating every time you reference it with methods like getOrdinal or getDD. You always get the date the object was created. It is quite a production to get the this date. Best to ask once and save the today object.
        Parameters:
        timeZone - in which we want to know the today's date.
        Returns:
        BigDate object initialised to today at given timezone.
        See Also:
        localToday(), UTCToday()
      • equals

        public final boolean equals​(Object d)
        Compares with another BigDate to see if they refer to the same date.
        Overrides:
        equals in class Object
        Parameters:
        d - other BigDate to compare with this one.
        Returns:
        true if BigDate d refers to the same date
      • hashCode

        public final int hashCode()
        hashCode for use in Hashtable lookup
        Overrides:
        hashCode in class Object
        Returns:
        the ordinal which is perfectly unique for the date.
      • toString

        public String toString()
        Convert date to a human-readable String.
        Overrides:
        toString in class Object
        Returns:
        this BigDate as a String in form YYYY-MM-DD ISO 8601:1988 international standard format. NOT final so you can override to suit yourself.
      • compareTo

        public final int compareTo​(Object anotherBigDate)
        Defines Natural Order for the BigDate class. Determines if this date comes after some other date. Conceptually returns (this - anotherBigDate). compareTo() == 0 is faster than equals().
        Specified by:
        compareTo in interface Comparable<Object>
        Parameters:
        anotherBigDate - date to compare against
        Returns:
        a positive number if this date > (after) anotherBigDate.
        zero if this date = anotherBigDate.
        a negative number if this date < (before) anotherBigDate.
      • addDays

        public final void addDays​(int days)
        increment this date by a number of days.
        Parameters:
        days - postive or negative, -1 gets day before this one.
      • getCalendarDayOfWeek

        public final int getCalendarDayOfWeek()
        Get day of week for this BigDate. Is it one-based starting with Sunday.
        Returns:
        day of week 1=Sunday 2=Monday 3=Tuesday 4=Wednesday 5=Thursday 6=Friday 7=Saturday Compatible with Sun's 1=Calendar.SUNDAY Not compatible with BigDate.getDayOfWee
        See Also:
        getISODayOfWeek(), getDayOfWeek(), calendarDayOfWeek(int)
      • getDD

        public final int getDD()
        get day of month for this BigDate.
        Returns:
        day 1 to 31, 0 for null date.
      • getDDD

        public final int getDDD()
        Get day number in the year for this BigDate.
        Returns:
        day number Jan 01 = 1, 1 to 366
      • getDayOfWeek

        public final int getDayOfWeek()
        Get day of week for this BigDate. It is zero-based starting with Sunday.
        Returns:
        day of week 0=Sunday 1=Monday 2=Tuesday 3=Wednesday 4=Thursday 5=Friday 6=Saturday WARNING: not compatible with 1=Calendar.SUNDAY
        See Also:
        getCalendarDayOfWeek(), getISODayOfWeek(), dayOfWeek(int)
      • getISODayOfWeek

        public final int getISODayOfWeek()
        Get day of week 1 to 7 for this BigDate according to the ISO standard IS-8601. It is one-based starting with Monday.
        Returns:
        day of week 1=Monday to 7=Sunday, 0 for null date. WARNING: not compatible with 1=Calendar.SUNDAY
        See Also:
        getCalendarDayOfWeek(), getDayOfWeek(), isoDayOfWeek(int)
      • getISOWeekNumber

        public final int getISOWeekNumber()
        Get week number 1 to 53 of the year this date falls in, according to the rules of ISO standard IS-8601 section 5.5. A week that lies partly in one year and partly in another is assigned a number in the year in which most of its days lie. This means that week 1 of any year is the week that contains 4 January, or equivalently week 1 of any year is the week that contains the first Thursday in January. Most years have 52 weeks, but years that start on a Thursday and leap years that start on a Wednesday have 53 weeks. Jan 1 may well be in week 53 of the previous year! Only defined for dates on or after 1600 Jan 01. You can find out how many ISO weeks there are per year with new BigDate( year, 12, 31).getISOWeekNumber();
        Returns:
        week number 1..53, 0 for null or invalid date.
      • getLocalDate

        public final Date getLocalDate()
        Get java.util.Date object corresponding to this BigDate. We consider this BigDate to have an implied time of 0:00 local time.
        Returns:
        Date or null Result is undefined if BigDate is outside the range handled by Date.
        See Also:
        getLocalTimeStamp()
      • getLocalTimeStamp

        public final long getLocalTimeStamp()
        Get milliseconds since 1970 Jan 01 00:00 GMT for this BigDate. Does not account for leap seconds primarily because we do not know them in advance. N.B. returns long, not int as in many Unix implementations. This the long that a Sun Date constructor wants. We consider this BigDate to have an implied time of 0:00 local time.
        Returns:
        milliseconds since 1979 Jan 01 00:00 GMT, or NULL_TIMESTAMP. This is NOT a JDBC Timestamp! You can use this timestamp with java.util.Date.setTime, java.sql.TimeStamp.setTime or java.sql.Date.setTime or in the constructors. To interconvert, just cast.
        See Also:
        getLocalDate()
      • getMM

        public final int getMM()
        Get month of year for this BigDate.
        Returns:
        month 1 to 12, 0 for null date.
      • getProplepticJulianDay

        public final double getProplepticJulianDay()
        Returns:
        Julian day number of noon of the date BigDate represents. See notes on the Julian Propleptic calendar under the constructor.
      • getSeason

        public final int getSeason()
        Get season of year for this BigDate.
        Returns:
        0=spring (Mar, Apr, May) 1=summer (Jun, Jul, Aug) 2=fall (Sep, Oct, Dec) 3=winter Dec, Jan, Feb
      • getTimeStamp

        public final long getTimeStamp​(TimeZone timeZone)
        Get milliseconds since 1970 Jan 01 00:00 GMT for this BigDate, as at the start of day 0:00. Does not account for leap seconds primarily because we do not know them in advance. N.B. returns long, not int as in many Unix implementations. This the long that a Sun Date constructor wants.
        Parameters:
        timeZone - We consider this BigDate to have an implied time of 0:00 in this timeZone.
        Returns:
        milliseconds since 1979 Jan 01 00:00 GMT, or NULL_TIMESTAMP. This is NOT a JDBC Timestamp! You can use this timestamp with java.util.Date.setTime, java.sql.TimeStamp.setTime or java.sql.Date.setTime or in the constructors. To interconvert, just cast.
        See Also:
        getDate(java.util.TimeZone), getUTCTimeStamp(), getLocalTimeStamp()
      • getUTCDate

        public final Date getUTCDate()
        Get java.util.Date object corresponding to this BigDate. We consider this BigDate to have an implied time of 0:00 UTC (Greenwich GMT).
        Returns:
        Date or null Result is undefined if BigDate is outside the range handled by Date.
        See Also:
        getUTCTimeStamp()
      • getUTCTimeStamp

        public final long getUTCTimeStamp()
        Get milliseconds since 1970 Jan 01 00:00 GMT for this BigDate. Does not account for leap seconds primarily because we do not know them in advance. N.B. returns long, not int as in many Unix implementations. This the long that a Sun Date constructor wants. We consider this BigDate to have an implied time of 0:00 UTC (Greenwich GMT).
        Returns:
        milliseconds since 1970 Jan 01 00:00 GMT, or NULL_TIMESTAMP. This is NOT a JDBC Timestamp! You can use this timestamp with java.util.Date.setTime, java.sql.TimeStamp.setTime or java.sql.Date.setTime or in the constructors. To interconvert, just cast.
        See Also:
        getUTCDate()
      • getWeekNumber

        public final int getWeekNumber()
        Get week number 1 to 53 of the year this date falls in. This does NOT follow the rules of ISO standard IS-8601 section 5.5. Week 1 is the first week with any days in the current year. Weeks start on Sunday. Jan 1 and Dec 31 are always considered part of the current year. Only defined for dates on or after 1600 Jan 01.
        Returns:
        week number 1..53, 0 for null or invalid date.
        See Also:
        getISOWeekNumber()
      • getYYYY

        public final int getYYYY()
        Get year for this BigDate.
        Returns:
        year -999,999 to 999,999. 0 for null date. negative is BC, positive AD.
      • normalise

        protected final void normalise()
        Clean up an invalid date, leaving the results internally.
        e.g. 1954 September 31 -> 1954 October 1.
        1954 October -1 -> 1954 September 29.
        1954 13 01 -> 1955 01 01. This lets you do year, month or day arithmetic. normalise does not recompute the ordinal.
      • set

        public final void set​(int ordinal)
        Set the ordinal field, and compute the equivalent internal Gregorian yyyy mm dd fields. alias setOrdinal.
        Parameters:
        ordinal - days since 1970 Jan 1.
      • set

        public final void set​(int yyyy,
                              int mm,
                              int dd)
        Set the yyyy mm dd Gregorian fields, and compute the internal ordinal equivalent. yyyy mm dd are checked for validity.
        Parameters:
        yyyy - -999,999 (BC) to +999,999 (AD)
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        dd - day 1 to 31
      • set

        public final void set​(int yyyy,
                              int mm,
                              int dd,
                              int how)
        Set the Gregorian fields, and compute the ordinal equivalent with the same modifiers CHECK, NORMALIZE, BYPASSCHECK as the constructor. BEWARE! In Java a lead 0 on an integer implies OCTAL.
        Parameters:
        yyyy - -999,999 (BC) to +999,999 (AD)
        mm - month 1 to 12 (not 0 to 11 as in Sun's Date)
        dd - day 1 to 31
        how - one of CHECK BYPASSCHECK NORMALIZE NORMALISE
      • setDateAtTime

        public void setDateAtTime​(long utcTimestamp,
                                  TimeZone timeZone)
        Sets the date that corresponding to a given utc timestamp at a given TimeZone.
        Parameters:
        utcTimestamp - milliseconds since 1970 in UTC time. E.g. Date.getTime
        timeZone - Timezone you want to know the date in at that time. TimeZone.getDefault() TimeZone.getU
      • setOrdinal

        public final void setOrdinal​(int ordinal)
        Set the ordinal field, and compute the equivalent internal Gregorian yyyy mm dd fields. alias set.
        Parameters:
        ordinal - days since 1970 Jan 1.
      • toDowMMDDYY

        public String toDowMMDDYY()
        Convert date to a human-readable String wed mm/dd/yy
        Returns:
        this BigDate as a String in form fri 12/31/03
      • toGregorian

        protected final void toGregorian()
        converts ordinal to YYYY MM DD, leaving results internally.
      • toOrdinal

        protected final void toOrdinal()
        Convert date in form YYYY MM DD into days since the epoch, leaving results internally.