|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--texsoft.java.util.XsDate
The XsDate
class represents a simple date in time.
It simply stores year, month and day, without many of the features of
and Date
. Calendar
An usefull feature of this class is that it implements the
interface to allow searching and
ordering.
Comparable
Constructor Summary | |
XsDate()
Creates new empty XsDate object. |
|
XsDate(java.util.GregorianCalendar cal)
Create a new XsDate object initialized with the given
GregorianCalendar value. |
|
XsDate(int y,
int m,
int d)
Create a new XsDate object initialized with the given values. |
|
XsDate(long t)
Create a new XsDate object from timestamp in milliseconds
since 1970-01-01 0:00:00. |
|
XsDate(java.lang.String s)
Create a new XsDate object initialized from the given
String value. |
Method Summary | |
void |
addDays(int amount)
Add the given number of days to the date value. |
int |
compareTo(java.lang.Object o)
Compares this XsDate object with the specified object for order. |
int |
differenceDays(XsDate other)
Calculate the difference in days between this date and other. |
static int |
differenceDays(XsDate from,
XsDate to)
Calculate the difference in days between from and to. |
static XsDate |
getCurrent()
Returns a new XsDate object set to the system date. |
int |
getDay()
Get the day of the date. |
int |
getDayOfWeek()
Returns the day of week, starting from Monday = 1. |
int |
getDayOfYear()
Returns the day of year, starting from 1. |
int |
getMonth()
Get the month of the date. |
int |
getWeekOfYear()
Returns the week of year, starting from 1. |
int |
getYear()
Get the year of the date. |
boolean |
isEmpty()
Returns true if the object stores an empty date. |
boolean |
isLeapYear()
Returns true if the date's year is a leap year. |
static void |
main(java.lang.String[] args)
Some simple code to test the class. |
void |
setDate(java.util.GregorianCalendar cal)
Set the date to the give GregorianCalendar value. |
void |
setDate(int y,
int m,
int d)
Set the date with the given year, month and day values. |
void |
setDate(long t)
Set the date to timestamp in milliseconds sice 1970-01-01 0:00:00. |
void |
setDate(java.lang.String s)
Set the date from the given String value. |
void |
setDay(int d)
Set the day of the date. |
void |
setMonth(int m)
Set the month of the date. |
void |
setYear(int y)
Set the year of the date. |
java.util.GregorianCalendar |
toGregorianCalendar()
Returns a GregorianCalendar object set to the date of this object. |
long |
toMilliseconds()
Returns date as timestamp in milliseconds since 1970-01-01 0:00:00. |
java.lang.String |
toString()
Returns a String rapresentation of the date
in the format YYYY-MM-DD. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public XsDate()
XsDate
object. An empty date has year, month and day set to 0.
public XsDate(int y, int m, int d)
XsDate
object initialized with the given values. If the resulting date is not valid, set the date to empty 0000-00-00.
y
- year.m
- month.d
- day.public XsDate(long t)
XsDate
object from timestamp in milliseconds
since 1970-01-01 0:00:00.
t
- timestamp value.public XsDate(java.util.GregorianCalendar cal)
XsDate
object initialized with the given
GregorianCalendar
value.
cal
- date in GregoriaCalendar format.public XsDate(java.lang.String s)
XsDate
object initialized from the given
String
value.
For the available format of the String
argument see
setDate(String)
.
If the resulting date is not valid, set the date to empty 0000-00-00.
s
- date value as String
in one of the recognized formats.Method Detail |
public void setDate(int y, int m, int d)
This method is called by all other methods that set or change any of the date fields. If the resulting date is not valid, set the date to empty 0000-00-00.
y
- year.m
- month.d
- day.public void setDate(long t)
t
- timestamp.public void setDate(java.util.GregorianCalendar cal)
GregorianCalendar
value.
cal
- date as GregorianCalendar
object.public void setDate(java.lang.String s)
String
value.
The String
argument can have a fix format or a format
that uses a separator.
The fixed format has the form: YYYYMMDD and must be exacly 8 decimal digits.
The separator format has the form: Y-M-D. The separator between year, month and day components is the first non-numerical character found scanning the string.
If the resulting date is not valid, set the date to empty 0000-00-00.
s
- date value as String
in one of the recognized formats.public boolean isEmpty()
true
if the object stores an empty date. An empty date has year, month and day set to zero.
true
if the object stores an empty date.public boolean isLeapYear()
true
if the date's year is a leap year.
true
is the date's year is a leap year.public java.lang.String toString()
String
rapresentation of the date
in the format YYYY-MM-DD.
toString
in class java.lang.Object
public java.util.GregorianCalendar toGregorianCalendar()
GregorianCalendar
object set to the date of this object.
GregorianCalendar
object set to the date of this object.public long toMilliseconds()
public static XsDate getCurrent()
XsDate
object set to the system date.
XsDate
object
set with the current date of the system
clock.public int getYear()
public void setYear(int y)
y
- new year value for the date.public int getMonth()
public void setMonth(int m)
No check is done on the month value. Caller should check for valid value.
m
- new month value for the date.public int getDay()
public void setDay(int d)
No check is done on the day value. Caller should check for valid value.
d
- new day value for the date.public int compareTo(java.lang.Object o) throws java.lang.ClassCastException
XsDate
object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Empty XsDate
object is less than any other date.
If the Object
argument is null
,
return a positive value.
compareTo
in interface java.lang.Comparable
o
- the Object
to be compared.
If compared to null
always return positive value.
java.lang.ClassCastException
- if the specified object's
type prevents it from being compared to this object.public int getDayOfWeek()
public int getDayOfYear()
public int getWeekOfYear()
public void addDays(int amount)
amount
- number of day to add, can be negative value.public int differenceDays(XsDate other)
other
- the date to be compared.
XsDate
object
and the given date.public static int differenceDays(XsDate from, XsDate to)
from
- starting date.to
- ending date.
public static void main(java.lang.String[] args)
args
- command line arguments.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |