public class BigDate extends Object implements Cloneable, Serializable, Comparable<Object>
to compute various holidays,
to tell if a given day is a holiday.
,
Serialized Form| Modifier and Type | Field and 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 and Description |
|---|
BigDate()
Constructor for the null date.
|
BigDate(BigDate b)
Copy constructor
|
BigDate(Date utc,
TimeZone timeZone)
Constructor from Date, loses time information.
|
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(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.
|
| Modifier and Type | Method and 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.
|
public static final int BYPASSCHECK
public static final int CHECK
public static final int MAX_ORDINAL
public static final int MAX_YEAR
public static final int MIN_ORDINAL
public static final int MIN_YEAR
public static final int NORMALISE
public static final int NORMALIZE
NORMALISEpublic static final int NULL_ORDINAL
public static final long NULL_TIMESTAMP
public static final boolean isBritish
protected transient int dd
protected transient int mm
protected int ordinal
protected transient int yyyy
public BigDate()
localToday(),
UTCToday(),
today(java.util.TimeZone)public BigDate(double prolepticJulianDay)
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 0public BigDate(int ordinal)
ordinal - days since 1970 Jan 01.public BigDate(String yyyy_mm_dd)
yyyy_mm_dd - string of form "yyyy-mm-dd".public BigDate(BigDate b)
b - an existing BigDate object to use as a model for cloning
another.public BigDate(Date utc, TimeZone timeZone)
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")public BigDate(int yyyy,
int mm,
int dd)
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 31IllegalArgumentException - for invalid yyyy mm ddpublic BigDate(int yyyy,
int mm,
int dd,
int how)
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 31how - one of CHECK BYPASSCHECK NORMALIZE NORMALISEpublic static BigDate UTCToday()
localToday(),
today(java.util.TimeZone)public static int[] age(BigDate birthDate, BigDate asof)
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.localToday(),
today(java.util.TimeZone),
UTCToday()public static int calendarDayOfWeek(int ordinal)
ordinal - days since Jan 1, 1970 to test.isoDayOfWeek(int),
dayOfWeek(int),
getCalendarDayOfWeek()public static int dayOfWeek(int ordinal)
ordinal - days since Jan 1, 1970 to test.calendarDayOfWeek(int),
isoDayOfWeek(int),
getDayOfWeek()public static int daysInMonth(int mm,
boolean leap)
mm - month 1 to 12 (not 0 to 11 as in Sun's Date)leap - true if you are interested in a leap yearpublic static int daysInMonth(int mm,
int yyyy)
mm - month 1 to 12 (not 0 to 11 as in Sun's Date)yyyy - year of interest.protected static int daysInYearPriorToMonth(int mm,
boolean leap)
mm - month 1 to 12 (not 0 to 11 as in Sun's Date).leap - true if you are interested in a leap year.protected static int dddToMM(int ddd,
boolean leap)
ddd - day number in year Jan 01 = 1, 1 to 366.leap - true if year of interest is boolean.public static int flooredMulDiv(int multiplicand,
int multiplier,
int divisor)
multiplicand - one of two numbers to multiply togethermultiplier - one of two numbers to multiply togetherdivisor - number to divide bypublic static String getCopyright()
public static boolean isLeap(int yyyy)
yyyy - year to test.public static boolean isValid(String yyyy_mm_dd)
yyyy_mm_dd - string of form "yyyy-mm-dd".public static boolean isValid(int yyyy,
int mm,
int dd)
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 31public static int isoDayOfWeek(int ordinal)
ordinal - days since Jan 1, 1970 to test.dayOfWeek(int)protected static int jan01OfYear(int yyyy)
yyyy - year of interestpublic static BigDate localToday()
#see #UTCTodaypublic static int nthXXXDay(int which,
int dayOfWeek,
int yyyy,
int mm)
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)public static int ordinalOfnthXXXDay(int which,
int dayOfWeek,
int yyyy,
int mm)
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)public static int toOrdinal(int yyyy,
int mm,
int dd)
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 31public static BigDate today(TimeZone timeZone)
timeZone - in which we want to know the today's date.localToday(),
UTCToday()public final int getOrdinal()
getLocalTimeStamp(),
getUTCTimeStamp(),
getTimeStamp(java.util.TimeZone)public final boolean equals(Object d)
public final int hashCode()
public String toString()
public final int compareTo(Object anotherBigDate)
compareTo in interface Comparable<Object>anotherBigDate - date to compare againstpublic final void addDays(int days)
days - postive or negative, -1 gets day before this one.public final int getCalendarDayOfWeek()
getISODayOfWeek(),
getDayOfWeek(),
calendarDayOfWeek(int)public final int getDD()
public final int getDDD()
public final Date getDate(TimeZone timeZone)
timeZone - We consider this BigDate to have an implied time of 0:00 in
this timeZone.getLocalTimeStamp(),
getUTCTimeStamp(),
getTimeStamp(java.util.TimeZone),
getUTCDate(),
getLocalDate()public final int getDayOfWeek()
getCalendarDayOfWeek(),
getISODayOfWeek(),
dayOfWeek(int)public final int getISODayOfWeek()
getCalendarDayOfWeek(),
getDayOfWeek(),
isoDayOfWeek(int)public final int getISOWeekNumber()
public final Date getLocalDate()
getLocalTimeStamp()public final long getLocalTimeStamp()
getLocalDate()public final int getMM()
public final double getProplepticJulianDay()
public final int getSeason()
public final long getTimeStamp(TimeZone timeZone)
timeZone - We consider this BigDate to have an implied time of 0:00 in
this timeZone.getDate(java.util.TimeZone),
getUTCTimeStamp(),
getLocalTimeStamp()public final Date getUTCDate()
getUTCTimeStamp()public final long getUTCTimeStamp()
getUTCDate()public final int getWeekNumber()
getISOWeekNumber()public final int getYYYY()
protected final void normalise()
public final void set(int ordinal)
ordinal - days since 1970 Jan 1.public final void set(int yyyy,
int mm,
int dd)
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 31public final void set(int yyyy,
int mm,
int dd,
int how)
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 31how - one of CHECK BYPASSCHECK NORMALIZE NORMALISEpublic void setDateAtTime(long utcTimestamp,
TimeZone timeZone)
utcTimestamp - milliseconds since 1970 in UTC time. E.g. Date.getTimetimeZone - Timezone you want to know the date in at that time.
TimeZone.getDefault() TimeZone.getUpublic final void setOrdinal(int ordinal)
ordinal - days since 1970 Jan 1.public String toDowMMDDYY()
protected final void toGregorian()
protected final void toOrdinal()
Copyright © 2014. All rights reserved.