|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--superwaba.ext.xplat.util.datergf.Date
Date()
is an implementation of Date which allows for date
manipulations and date arithmetics.
The philosophy of this class follows the "Date.cmd",
a date arithmetic function
written for the scripting language Rexx,
which is available as commercial and (opensourced) free interpreters
for practically every operating system in the world.
Date()
allows dates in the range of 0001-01-01
and 9999-12-31. By default
(can be changed with setGregorianChange(int year, int month, int day)
)
it switches from the Julian calendar to the Gregorian calendar in October of 1582 (October 4th of
1582 is followed by October 15th of 1582). It uses the ISO-values for indicating
the days and the ISO-rules to determine which week is the first week for a year.
Some of the available operations are:
This Java-version was created for the
Waba
(e.g. http://www.SuperWaba.org)
family of Java-compatible mobile systems (PDAs, Handies, etc.) (e.g.:
not employing threading, exceptions, and the datatypes long and double).
This class attempts to use as few resources as possible, yet
allow for comprehensive and fast date manipulations.
Date
is not modelled
after Java's classes Date, Calendar!
Therefore, in order for getting fast to the point
of this class, most method descriptions contain short examples.
Examples:
Date firstDate=new Date( 1, 1, 1), // yields: '0001-01-01' lastDate =new Date(9999,12,31); // yields: '9999-12-31' int days=lastDate.subtract(firstDate); // yields: 3652060 Date tmpDate=(Date)firstDate.copy();// yields: '0001-01-01' tmpDate.add(days); // yields: '9999-12-31' // get Labor Monday in 2001 tmpDate=new Date(2001,8,31); // yields: '2001-08-31', a Friday tmpDate.set(WEEKDAY, 1); // yields: '2001-09-03' // get Labor Monday in 2001 in one line tmpDate=(new Date(2001,8,31)).set(WEEKDAY,1); // yields: '2001-08-31', a Friday Date d=valueOf(ENCODED_AS_INTEGER, 20190521); // yields: '2019-05-21' d.set(WB, 0); // yields: '2019-05-19', if weekStart=7 (Sunday) int iso_day=d.get(DOW); // yields: 7 (ISO-number for Sunday) d.set(WB, 3); // yields: '2019-05-22', if weekStart=7 (Sunday) d.set(WE, 0); // yields: '2019-05-25', if weekStart=7 (Sunday) Date easter=Date.easter(d); // yields: '2019-04-21' int palm_days=d.get(EPOCH_PALM); // yields: 35430 int java_days=d.get(EPOCH_JAVA); // yields: 18041 // if run on "2010-09-22 17:49:01" under Waba, then d.update(); // yields: '2010-09-22' String day_name =getString(DN, d.get(DOW)); // yields: 'Saturday' String month_name=getString(MN, d.get(MONTH_FIELD)); // yields: 'May'
Temporary dev-infos: version date remark 0.91.0 2003-04-07 - rgf; changed equals() to match the signature of Object.equals(); added method hashCode(); documents explicitly that the interface Comparable is implemented in this class 0.9.2 2001-03-20 - removed all deprecated stuff from the 0.9.1 version - changed: is24hours -> is24Hour date_delimiter -> dateSeparator week_start -> weekStart date_order -> dateOrder 2001-03-21 - added Serializable (needs only one int to store the Date) taking care with supplied readObject(), writeObject() 2001-04-02 - introduced variant "JAVA" and "WABA" 2001-04-05 - included update() here
Field Summary | |
protected static byte |
dateOrder
Stores the desired date ordering ( DTC.YMD ,
DTC.MDY ,
DTC.DMY ).
|
static char |
dateSeparator
Stores the desired string to be used to delimit date fields in toString() .
|
protected int |
day
Stores the day, a value between 1 and 28, 29, 30, 31, depending on the month and year. |
protected static String[] |
dayNames
Stores the names of the days in an array of strings. |
protected static Date |
defaultEpochDate
Stores the Date to serve as the default epoch date. |
protected static int |
defaultEpochFlag
Stores one of the epoch flags: DTC.EPOCH_MJD ,
DTC.EPOCH_MACINTOSH ,
DTC.EPOCH_PALM ,
DTC.EPOCH_JAVA ,
DTC.EPOCH_DOS ,
DTC.EPOCH_WIN32 ,
DTC.EPOCH_USER . |
protected static Date[] |
epochDates
Stores the Dates of the epochs. |
protected int |
jdn
Stores the "jdn" ("Julian day number") value. |
protected int |
month
Stores the month, a value between 1 and 12. |
protected static String[] |
monthNames
Stores the names of the months in an array of strings. |
protected static Date |
stGC
Stores the date of the first day in the Gregorian calender. |
protected static int |
weekStart
Stores the day which starts the week. |
protected int |
year
Stores the year, a value between 1 and 9999. |
Constructor Summary | |
Date()
Creates a Date object with all fields set to 1. |
|
Date(int year,
int month,
int day)
Creates a Date from the three integers, representing year, month and day. |
Method Summary | |
Date |
add(int numOfDays)
Adds the number of days to this Date. |
Date |
assign(Date otherDate)
Assigns all Date fields of otherDate to this Date. |
protected void |
cD()
Checks the date. |
int |
compareTo(Object otherDate)
Returns -1, if this time is earlier (smaller) than the argument, returns 0, if both are equal, returns +1, if this time is later (greater) than the argument. |
Object |
copy()
Returns a newly created Date object with all fields set to this Date object. |
static int |
date2jdn(Date aDate)
Determines into which calendar a date falls into and calls the appropriate method to calculate the respective Julian day number of the Julian period. |
static int |
date2jdn(int year,
int month,
int day,
int flag)
Calculates the Julian day number of the Julian period from a date which belongs to the Julian or Gregorian calendar, depending on the flag argument.
|
static int |
daysInMonth(Date date)
Determines the number of days for the date's month. |
static int |
dow_ord(Date tmpDate)
Calculates the ordinal value of the day of week (DOW), which is relative to weekStart . |
static int |
dow(Date tmpDate)
Calculates the day of week (DOW). |
static Date |
easter(Date date)
Calculate Easter Sunday for the year of the date. |
static Date |
easter(int year,
int flag)
Calculate the Julian (Orthodox) or Gregorian (Western) Easter Sunday for the given year. |
boolean |
equals(Object otherDate)
Returns true if Dates are equal (both have the same value in the fields year
month
day ). |
static Date |
fromJulianDate(int julianDate)
Renders a Julian date into a Date. |
protected static Date |
gED(int epoch)
Returns the Date of the desired epoch. |
int |
get(int flag)
Allows to retrieve information about this Date. |
static Date |
getDefaultEpochDate()
Returns a copy of the presently defined epoch Date. |
static Date |
getGregorianChange()
Returns a copy of the Date object which is set to the first date of the Gregorian calendar. |
static int |
getStatic(int flag)
Allows to query the static fields weekStart and dateOrder .
|
static String |
getString(int flag,
int value)
Returns the name of the day or of the month according to flag .
|
int |
hashCode()
Returns a hashcode value for the date object. |
static boolean |
isLeapYear(Date date)
Determines whether the given Date is a leap year. |
static int |
isoWeek(Date date)
Determines into which week of the year the given Date falls into using ISO rules. |
static Date |
jdn2date(int jdn,
Date aDate)
Determines into which calendar a Julian day number of the Julian period falls into (Julian calendar or Gregorian calendar) and calls the appropriate method to set the date accordingly. |
static Date |
jdn2date(int jdn,
Date aDate,
int flag)
Sets the date belonging to the Julian calendar or Graegorian calendar according to the given Julian day number of the Julian period. |
protected static String |
ri(int value,
int len)
Convert the primitive Java int tmp to a String and right adjust value with a leading 0 to two places, if necessary. |
Date |
set(int flag,
int number)
Allows to set this Date object to a specific date. |
Date |
set(int year,
int month,
int day)
Set all three Date fields at once. |
static Date |
setDefaultEpochDate(int value)
Sets the Date which presently serves as the epoch. |
static Date |
setGivenWeekday(int weekdays,
Date date)
From a given Date calculate the previous or next date, which falls on one of the given weekdays. |
static Date |
setGregorianChange(int year,
int month,
int day)
Allows to set the date on which the usage of the Gregorian calendar starts. |
static int |
setStatic(int flag,
int number)
Allows to set the static fields weekStart and dateOrder .
|
static void |
setString(int flag,
String[] value)
Alllows to set the names of the month or of the days according to flag .
|
int |
subtract(Date other)
Calculates the differences (in number of days) between two Dates. |
static int |
toJulianDate(Date date)
Renders the Date into a Julian date. |
String |
toString()
Returns time formatted into a string according to the fields dateSeparator ,
dateOrder . |
Date |
update()
This method sets the Date object to the actual local date of the system. |
static Date |
valueOf(int flag,
int daysToAdd)
Creates a Date object by adding days to the given Date (which may be an epoch date indicated by the appropriate constant). |
static Date |
valueOf(String value)
Create a Date object from a string containing a Date encoded according to the present setting of dateOrder .
|
Methods inherited from class java.lang.Object |
getClass,
notify,
wait,
wait |
Field Detail |
protected static int weekStart
DTC.MONDAY
,
DTC.TUESDAY
,
DTC.WEDNESDAY
,
DTC.THURSDAY
,
DTC.FRIDAY
,
DTC.SATURDAY
,
DTC.SUNDAY
.public static char dateSeparator
toString()
.
Will get set on class load from preferences.
The default value is: '-'
.protected static byte dateOrder
DTC.YMD
,
DTC.MDY
,
DTC.DMY
).
Ordering will be used to delimit date fields in
toString()
.
Will get set on class load from preferences.
The default value is: DTC.YMD
.protected static String[] monthNames
getString(int flag, int value)
, where flag
is set to DTC.MN
and value
is either set
to the result of
get(int flag)
with flag
set to
DTC.M
, or to the month
of a
Date
or one of the following
constants:
to the month of a Date
or one of the following constants:
DTC.JANUARY
,
DTC.FEBRUARY
,
DTC.MARCH
,
DTC.APRIL
,
DTC.MAY
,
DTC.JUNE
,
DTC.JULY
,
DTC.AUGUST
,
DTC.SEPTEMBER
,
DTC.SEPTEMBER
,
DTC.OCTOBER
,
DTC.NOVEMBER
,
DTC.DECEMBER
.
One may change this string e.g. for localization.protected static String[] dayNames
getString(int flag, int value)
with flag
set to DTC.DN
and value
is either set
to the result of
get(int flag)
with flag
set to
DTC.DOW
, or to the
result of calling the static method
dow(Date tmpDate)
or
one of the following constants:
DTC.MONDAY
,
DTC.TUESDAY
,
DTC.WEDNESDAY
,
DTC.THURSDAY
,
DTC.FRIDAY
,
DTC.SATURDAY
,
DTC.SUNDAY
.protected static Date defaultEpochDate
getDefaultEpochDate()
protected static int defaultEpochFlag
DTC.EPOCH_MJD
,
DTC.EPOCH_MACINTOSH
,
DTC.EPOCH_PALM
,
DTC.EPOCH_JAVA
,
DTC.EPOCH_DOS
,
DTC.EPOCH_WIN32
,
DTC.EPOCH_USER
.protected static final Date[] epochDates
gED(int flag)
.protected static Date stGC
protected transient int year
jdn
to DTC.NAD
and call cD()
which checks the resulting Date and sets
jdn
to its appropriate value.protected transient int month
jdn
to DTC.NAD
and call cD()
which checks the resulting Date and sets
jdn
to its appropriate value.protected transient int day
jdn
to DTC.NAD
and call cD()
which checks the resulting Date and sets
jdn
to its appropriate value.protected transient int jdn
This is a unique value assigned to each day irrespectible of the calendar system one uses. Cf. "Frequently Asked Questions about Calendars" and read about 'Julian period', 'Julian day (number)', 'Julian calendar' and 'Gregorian calendar'.
Use the get(int flag)
method, to access this field, using the flag DTC.JDN
.
(If this field has a value of DTC.NAD
then the actual jdn
value will get calculated and returned.)
Constructor Detail |
public Date()
public Date(int year, int month, int day)
Please note: due to the underlying algorithms, it is not
an error to use '0' or a value larger than the maximum value
for month
or day
. In such a case the
date will be used which comes 'closest' to the indicated values. E.g.
'2004-03-00' will be translated to '2004-02-29', '2005-01-00' to '2004-12-31',
'2005-00-00' to '2004-11-30', '2005-12-40' to '2006-01-09',
'2005-13-40' to '2006-02-09', etc.
Method Detail |
public static Date valueOf(int flag, int daysToAdd)
Examples:
Date e=Date.valueOf(Date.EPOCH_PALM, 0), // yields: '1904-01-01' m=new Date(2001, 1, 1); // yields: '2001-01-01', the // new millenium int palm_days=m.subtract(e); // yields: 35430 Date d=Date.valueOf(Date.EPOCH_PALM, palm_days); // yields: '2001-01-01' e.add(palm_days); // yields: '2001-01-01'
flag
- one of the constants of epoch
(DTC.EPOCH_MACINTOSH
,
DTC.EPOCH_PALM
,
DTC.EPOCH_JAVA
,
DTC.EPOCH_DOS
,
DTC.EPOCH_WIN32
,
DTC.EPOCH_MJD
,
DTC.EPOCH_DEFAULT
),
or an explicit date serving as an epoch, formed according to the
DTC.ENCODED_AS_INTEGER
rule.daysToAdd
- days to add/subtract to/from epoch or integer encoded date,
indicated by the second parameteras.
If the second parameter flag
is DTC.ENCODED_AS_INTEGER
than this parameter is interpreted as a date encoded as an integer.public static Date valueOf(String value)
dateOrder
.
Extraction of digits is very lenient, i.e. everything but a digit is skipped, all digits (up to eight) are concatenated and then turned into a Date date.
If the length of the extracted string of digits is six characters, then it is assumed that the year is two digits long and '2000' is added to the year.
If the number of digits is not
exactly eight (the year consists of four digits) or not
exactly six (the year consists of two digits), null
is returned. Therefore the day and the month must be given with
two digits (i.e. leading 0, if necessary).
Examples (assuming
dateOrder
: DTC.YMD
):
Date a=valueOf("1989-05-21") , // yields: '1989-05-21' b=valueOf("19930922" ) , // yields: '1993-09-22' c=valueOf("1782.10.15") , // yields: '1782-10-15' d=valueOf("2010 02 28") , // yields: '2010-02-28' e=valueOf("030201" ) , // yields: '2003-02-01' f=valueOf("123" ) ; // yields: null
value
- a string containing a string representation of Date.null
, if
there are not exactly eight or six digits in the parsed
(after removing delimiters) string.public Date add(int numOfDays)
Examples:
Date newMillenium=new Date(2001,01,01); // yields: '2001-01-01' newMillenium.add(100000); // add 100.000 days, yields: '2274-10-17'
numOfDays
- number of days to add to this Date
.public int subtract(Date other)
Examples:
Date firstDate=new Date( 1, 1, 1), // yields: '0001-01-01' lastDate =new Date(9999,12,31); // yields: '9999-12-31' int days=lastDate.subtract(firstDate); // yields: 3652060
other
- Date object to subtract from this Date.public Date assign(Date otherDate)
otherDate
- date to assign from.protected void cD()
month
or
day
are beyond their appropriate limits.
(E.g. '2005-12-32' will be turned into '2006-01-01', or '2717-01-00'
into '2716-12-31'!)
This method is executed only, if jdn
is set to DTC.NAD
.
At the end of the method jdn
will be set to the value fully
representing the given Date.
public int compareTo(Object otherDate)
public Object copy()
public boolean equals(Object otherDate)
year
month
day
).public int hashCode()
jdn
field)public int get(int flag)
flag | returns |
DTC.YEAR_FIELD
| year
|
DTC.MONTH_FIELD
| month
|
DTC.DAY_FIELD
| day
|
DTC.WEEK_START
| DTC.WEEK_START
|
DTC.JDN
| jdn
|
DTC.DOW
| day of week (according to ISO) |
DTC.DOW_ORDINAL
| the number of day in the week, relative to
weekStart
|
DTC.JULIAN
| Julian date, e.g. the date 19590202 (February, 2nd) will return the Julian date 1959033 (33rd day in the year) |
DTC.WEEK
| the week number according to ISO |
DTC.DAYS_IN_MONTH
| number of days in this date's month |
DTC.HY
| 1, if date is in first half (semester) of the year, 2 else. |
DTC.Q
| the quarter of the date (1 through 4). |
DTC.EPOCH_MACINTOSH ,
DTC.EPOCH_PALM ,
DTC.EPOCH_JAVA ,
DTC.EPOCH_DOS ,
DTC.EPOCH_WIN32 ,
DTC.EPOCH_MJD ,
DTC.EPOCH_DEFAULT
| the number of days between this Date and the given epoch.
If using EPOCH_DEFAULT , then the default
epoch is used. The default epoch may be set with
setDefaultEpochDate(int value)
and queried/gotten with
getDefaultEpochDate() .
|
DTC.ENCODED_AS_INTEGER
| returns this Date encoded as an integer:
year*10000+month*100+day .
|
Examples:
Date d=new Date(2059, 5, 20); // yields: '2059-05-20' int this_date =d.get(DTC.ENCODED_AS_INTEGER), // yields: 20590520 quarter =d.get(DTC.Q), // yields: 2 semester =d.get(DTC.HY), // yields: 1 dow =d.get(DTC.DOW), // yields: 2 ws =d.get(DTC.WEEK_START), // yields: 7 dow_ord =d.get(DTC.DOW_ORDINAL), // yields: 3 dim =d.get(DTC.DAYS_IN_MONTH), // yields: 31 palm_days =d.get(DTC.EPOCH_PALM), // yields: 56753 java_days =d.get(DTC.EPOCH_JAVA); // yields: 32646
flag
- indicates the desired value.flag, -1
,
if unknown flag is used.public Date set(int flag, int number)
flag | comment |
The following flags use the parameter number
for setting the desired values.
| |
DTC.YEAR_FIELD
| set year to the value of parameter number.
|
DTC.MONTH_FIELD
| set month to the value of parameter number.
|
DTC.DAY_FIELD
| set day to the value of parameter number.
|
DTC.ENCODED_AS_INTEGER
| set year , month and
day to the Date value encoded as an
int in
parameter number.
|
DTC.WEEKDAY
| set date to one of the weekdays encoded in parameter
parameter number. This uses the
setGivenWeekday(int weekdays, Date date) to carry
out the operation.
|
DTC.WEEK_START
| set weekStart to the day as indicated by the
parameter number. If an invalid value is passed, the
present setting is not changed.
|
Examples:
Date d=Date.valueOf(20010101, 0); // yields: '2001-01-01' d.set(YEAR_FIELD, 2345); // yields: '2345-01-01' d.set(MONTH_FIELD, 12); // yields: '2345-12-01' d.set(DAY_FIELD, 15); // yields: '2345-12-15', a Saturday d.set(WEEKDAY, 1); // yields: '2345-12-17', the next Monday d.set(ENCODED_AS_INTEGER, 17280228); // yields: '1728-02-28'
flag | comment |
The following flags cause the Date object to be firstly
set to the desired date, then number of days are
added to (subtracted from, if negative) to it.
| |
DTC.HYB
| set the date to the beginning of its semester and add the value of parameter number to it. |
DTC.HYE
| set the date to the end of its semester and add the value of parameter number to it. |
DTC.MB
| set the date to the beginning of its month and add the value of parameter number to it. |
DTC.ME
| set the date to the end of its month and add the value of parameter number to it. |
DTC.QB
| set the date to the beginning of its quarter and add the value of parameter number to it. |
DTC.QE
| set the date to the end of its quarter and add the value of parameter number to it. |
DTC.WB
| set the date to the beginning of its week and
add the value of parameter number to it.
The beginning of a week is determined by
weekStart .
|
DTC.WE
| set the date to the end of its week and
add the value of parameter number to it.
The end of a week is always six days after the day of
weekStart .
|
DTC.YB
| set the date to the beginning of its year and add the value of parameter number to it. |
DTC.YE
| set the date to the end of its year and add the value of parameter number to it. |
Examples:
d.set(DTC.ENCODED_AS_INTEGER, 17280128); // yields: '1728-02-28' d.set(DTC.WB, 0); // yields: '1728-02-22', if weekStart=7 d.set(DTC.WB, 3); // yields: '1728-02-25', if weekStart=7 d.set(DTC.WE, 0); // yields: '1728-02-28', if weekStart=7 d.set(DTC.QB, 0); // yields: '1728-01-01' d.set(DTC.QE, 0); // yields: '1728-03-31' d.set(DTC.QE, -21); // yields: '1728-03-10 // i.e. three weeks before the end of the quarter
flag
- indicates type of set operationnumber
- either a value for a Date-field
(year
,
month
,
day
)
or may be a number indicating how many days to add/subtract
from the desired date.public static int getStatic(int flag)
weekStart
and dateOrder
.
flag | returns |
DTC.DATE_ORDER
| dateOrder
|
DTC.WEEK_START
| weekStart
|
flag
- indicates the desired value.flag, -1
,
if unknown flag is used.public static int setStatic(int flag, int number)
weekStart
and dateOrder
.
flag | sets and returns |
DTC.DATE_ORDER
| dateOrder
|
DTC.WEEK_START
| weekStart
|
flag
- indicates the desired value.flag, -1
,
if unknown flag is used. Illegal values are ignored, instead
the present set value for the indicated field is returned.public Date set(int year, int month, int day)
year
- the Date field year
.month
- the Date field month
.day
- the Date field day
.public String toString()
dateSeparator
,
dateOrder
.protected static String ri(int value, int len)
public static int dow(Date tmpDate)
tmpDate
- Date to work on.public static int dow_ord(Date tmpDate)
weekStart
. Hence, if weeks
start on Sundays, then Mondays will be the second day relative
to the start of week. If weeks start on Monday, then Monday
will be the first day of the week.tmpDate
- Date to work on.weekStart
.public static Date setGivenWeekday(int weekdays, Date date)
weekdays
.
Each decimal character represents a weekday, starting
with DTC.MONDAY
(=1) and ending with
DTC.SUNDAY
(=7). One needs to encode them into an integer, e.g.
'12345' represents the next weekdays from Monday to Friday,
whereas '67' represents the next weekdays Saturday and Sunday. Therefore to find
the next Monday or Friday, use '15'. If seeking
a previous date being one of the indicated weekdays, use negative numbers
(e.g. '-12345', '-67', '-15' etc.).
Examples:
// get Labor Day of 2001 (first Monday in September) Date d=new Date(2001, 8, 31); // yields: '2001-08-31' setGivenWeekday(1, d); // yields: '2001-09-03' // get the date the summer time ends in 2006 (last Sunday in October) d=new Date(2006, 11, 01); // yields: '2006-11-01' setGivenWeekday(-7, d); // yields: '2006-10-29' // get last working day of this quarter d.set(DTC.QE, 1); // yields: '2007-01-01', first day of next quarter setGivenWeekday(-12345, d); // yields: '2006-12-29', a Friday
weekdays
- an integer number indicating which days to match with.
If this number is negative, then the closest previous
weekday is searched, else the closest next one.date
- to be used.public static int date2jdn(Date aDate)
getGregorianChange()
into account.
Examples:
// assuming getGregorianChange(): '1582-10-15' Date d1=new Date(1582, 10, 4), // yields: '1582-10-04' (using Julian calendar) d2=new Date(1582, 10, 15), // yields: '1582-10-15' (using Gregorian calendar) d3=new Date(), d4=new Date(); int jdn1=Date.date2jdn(d1), // yields: 2299160 jdn2=Date.date2jdn(d2); // yields: 2299161 Date.jdn2date(jdn1, d3); // yields: '1582-10-04' (using Julian calendar) Date.jdn2date(jdn2, d4); // yields: '1582-10-15' (using Gregorian calendar)
aDate
- the Date for which to calculate the Julian day number.date2jdn(int year, int month, int day, int flag)
public static int date2jdn(int year, int month, int day, int flag)
flag
argument.
Refer to the excellent source on Calendars at Frequently Asked Questions about Calendars (did find it the first time on 2001-03-06!, ---rgf).
Example ("translating a Julian calendar date to a Gregorian calendar date"):
// get Julian day numer for '2010-01-01' in the Julian calendar int jdn=date2jdn(2010,1,1,JULIAN); // yields: 2455211 Date d=new Date(); Date.jdn2date(jdn, d, Date.JULIAN); // yields: '2010-01-01' (JULIAN) Date.jdn2date(jdn, d, Date.GREGORIAN); // yields: '2010-01-14' (GREGORIAN)
flag
- one of DTC.JULIAN
(default) or DTC.GREGORIAN
indicating which calendar is targeted.public static Date jdn2date(int jdn, Date aDate)
getGregorianChange()
into account.jdn
- the Julian day number of the Julian period.aDate
- the Date to be set accordingly.jdn2date(int jdn, Date aDate, int flag)
public static Date jdn2date(int jdn, Date aDate, int flag)
Refer to the excellent source on Calendars at Frequently Asked Questions about Calendars (did find it the first time on 2001-03-06!).
Example ("translating a Gregorian calendar date to a Julian calendar date"):
// get Julian day numer for '2010-01-01' in the Gregorian calendar int jdn=date2jdn(2010,1,1,DTC.GREGORIAN); // yields: 2455198 Date d=new Date(); Date.jdn2date(jdn, d, DTC.GREGORIAN); // yields: '2010-01-01' (GREGORIAN) Date.jdn2date(jdn, d, DTC.JULIAN); // yields: '2009-12-19' (JULIAN)
jdn
- the Julian day number of the Julian period.aDate
- the Date to be set accordingly.flag
- one of DTC.JULIAN
or DTC.GREGORIAN
indicating which calendar is targeted.public static boolean isLeapYear(Date date)
date
- the date to be checked on.public static int daysInMonth(Date date)
date
- the date to be used.public static int toJulianDate(Date date)
date
- the date to be rendered.public static Date fromJulianDate(int julianDate)
julianDate
- a date in the form: YYYYddd, where ddd indicates the day of the year.public static int isoWeek(Date date)
date
- the date for which the week of the year has to be determined.protected static Date gED(int epoch)
Caution: returns the original epoch Date object itself, which is stored in a static array for performance reasons (therefore this method is defined to be protected); do not change the value of that epoch object!
epoch
- one of
DTC.EPOCH_MJD
,
DTC.EPOCH_MACINTOSH
,
DTC.EPOCH_PALM
,
DTC.EPOCH_JAVA
,
DTC.EPOCH_DOS
,
DTC.EPOCH_WIN32
. Any other value
for flag will return the default epoch Date as set
by setDefaultEpochDate(int value)
.public static Date getDefaultEpochDate()
DTC.EPOCH_PALM
is used.public static Date setDefaultEpochDate(int value)
value
- must be
either an integer encoded as defined in DTC.ENCODED_AS_INTEGER
or one of
DTC.EPOCH_MACINTOSH
,
DTC.EPOCH_PALM
(default),
DTC.EPOCH_JAVA
,
DTC.EPOCH_DOS
,
DTC.EPOCH_WIN32
,
DTC.EPOCH_MJD
}.public static String getString(int flag, int value)
flag
.
Examples:
Date d =new Date(2001,1,1); // yields: '2001-01-01' String mon=getString(DTC.DN, d.get(DTC.DOW)); // yields: "Monday"
flag
- DTC.DN
or DTC.MN
value
- 1-based day
or month
, if value is smaller
than 1 then it defaults to 1public static void setString(int flag, String[] value)
flag
.
Examples:
String tagesnamen[]={"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" }; Date.setString(DTC..DN, tagesnamen); Date d =new Date(2001,1,1); // yields: '2001-01-01' String mon=getString(DTC.DN, d.get(DOW)); // yields: "Montag"
flag
- DTC.DN
or DTC.MN
value
- String[] of names, exactly 7 for DN
and
exactly 12 for MN
public static Date easter(Date date)
getGregorianChange()
in order to determine
whether Easter Sunday is to be created for the Julian calendar (Orthodox Easter Sunday)
or for the Gregorian calendar.
Note: In the very rare case of using a date which falls
into the year where the
change to the Gregorian calendar occurred, than be very careful which
easter is calculated! In such a case you may want to explicitly
determine which easter is to be calculated by invoking
easter(int year, int flag)
with
flag
set to either DTC.JULIAN
(i.e. orthodox easter) or
DTC.GREGORIAN
.
In case you are interested in those Christian (e.g. Roman Catholic)
holidays
depending on Easter Sunday, these are the most important ones
(giving the German name too, as well as the number of days before
or after Easter Sunday, to be directly used in
add(int numOfDays)
):
Day dependent on Easter Sunday | Number of days to add/subtract to/from Easter Sunday |
Shrove Tuesday (Mardi Gras) (Faschingsdienstag) | -47 |
Ash Wednesday (Aschermittwoch) | -46 (six weeks and four days before Easter Sunday) |
Saturday of Lazarus | -8 (one week before Easter Sunday) |
Palm Sunday (Palmsonntag) | -7 (one week before Easter Sunday) |
Maundy Thursday (Gründonnerstag) | -3 |
Good Friday (Karfreitag) | -2 |
Easter Sunday (Ostersonntag) | 0 |
Easter Monday (Ostermontag) | +1 |
Ascension Day (Christi Himmelfahrt) | +39 (five weeks and four days after Easter Sunday) |
Whitsunday (Pfingstsonntag) | +49 (seven weeks after Easter Sunday) |
Whitmonday (Pfingstmontag) | +50 (seven weeks and one day after Easter Sunday) |
Corpus Christi (Fronleichnam) | +60 (eight weeks and four days after Easter Sunday) |
Examples:
// assuming Gregorian change of most of the British Empire and // and USA, i.e. first Gregorian date is '1752-09-14': setGregorianChange(1752, 9, 14); // set Gregorian change date Date d1=new Date(1659, 11, 17), // yields: '1659-11-17' (a Julian calendar date) d2=new Date(2016, 2, 1), // yields: '2016-02-01' (a Gregorian calendar date) Date d3=easter(d1); // yields: '1659-04-03' (a Julian calendar date) d4=easter(d2); // yields: '2016-03-27' (a Gregorian calendar date)
date
- determines the year for which Easter Sunday is to be calculated.
If it is smaller (earlier) than getGregorianChange()
than the Julian calendar is used, the Gregorian calendar else.easter(int year, int flag)
public static Date easter(int year, int flag)
The returned date
represents the respective calendar, i.e. if flag
is DTC.GREGORIAN
, then the date returned belongs to
to the Gregorian calendar, otherwise to the Julian
calendar. Therefore you may directly use the jdn
to produce the according date in the other calendar system.
Refer to the excellent source on Calendars at Frequently Asked Questions about Calendars (did find it the first time on 2001-03-06!, ---rgf).
Example:
Date d1=new Date(2016, 9, 1); // yields: '2016-09-01' Date d2=easter(d1.get(DTC.YEAR_FIELD), DTC.JULIAN);// yields: '2016-04-18' // (a Julian calendar date) d2.jdn2date(d2.get(JDN), d2, DTC.GREGORIAN); // yields: '2016-05-01' // (a Gregorian calendar date)
year
- for which Easter Sunday is to be calculated.flag
- one of DTC.JULIAN
or DTC.GREGORIAN
indicating which calendar is targeted.public static Date getGregorianChange()
public static Date setGregorianChange(int year, int month, int day)
year
- the year of the first Gregorian date.month
- the month of the first Gregorian date.day
- the day of the first Gregorian date.public Date update()
Examples:
Date d =new Date(); // yields: '0001-01-01' // if run on "2010-09-22", then d.update(); // yields: '2010-09-22'
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |