|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.clazzes.util.datetime.UtcTimestamp
public class UtcTimestamp
A class to store UTC timestamps and timezone offset to database.
Field Summary | |
---|---|
static long |
MILLISECONDS_PER_DAY
|
static long |
MILLISECONDS_PER_HOUR
|
static long |
MILLISECONDS_PER_MINUTE
|
static long |
MILLISECONDS_PER_SECOND
|
Constructor Summary | |
---|---|
UtcTimestamp()
Construct a new UtcTimestamp for the current time in the utc timezone (tzOffset=0). |
|
UtcTimestamp(java.util.Calendar c)
Construct a new UtcTimestamp for the passed Calendar object. |
|
UtcTimestamp(long millis)
Construct a new UtcTimestamp for the passed milliseconds with a tzOffset=0. |
|
UtcTimestamp(long millis,
int tzOffset)
Construct a new UtcTimestamp for the passed milliseconds an timezone offset. |
|
UtcTimestamp(java.lang.String s)
Contruct an UtcTimestamp from an ISO8601-formatted string. |
|
UtcTimestamp(java.util.TimeZone timeZone)
Construct a new UtcTimestamp for the current time with a tzOffset for the given timezone at the current time. |
|
UtcTimestamp(java.util.TimeZone timeZone,
long millis)
Construct a new UtcTimestamp for the passed milliseconds with a tzOffset for the given timezone at the given instance in time. |
|
UtcTimestamp(UtcTimestamp a)
Copy constructor. |
Method Summary | |
---|---|
void |
add(int field,
int amount)
This method duplicates the funtionality of Calendar.add() in order
to make the transition from Calendar database objects to UtcTimestamp object
as easy as possible. |
void |
add(java.util.TimeZone timeZone,
int field,
int amount)
This method duplicates the funtionality of Calendar.add() considering
any change of the timezone offset of the given timezone. |
void |
addDays(long d)
|
void |
addHours(long h)
|
void |
addMilliSeconds(long ms)
|
void |
addMinutes(long m)
|
void |
addMonths(int m)
Add m month to the given timestamp. |
void |
addSeconds(long s)
|
void |
addYears(int y)
Add m month to the given timestamp. |
boolean |
after(UtcTimestamp other)
Test if this timestamp is after the passed second timestamp. |
boolean |
before(UtcTimestamp other)
Test if this timestamp is before the passed second timestamp. |
protected java.lang.Object |
clone()
|
UtcTimestamp |
cloneAdd(int field,
int amount)
Perform 'add' method to a clone of this. |
UtcTimestamp |
cloneAddDays(int amount)
|
UtcTimestamp |
cloneAddHours(int amount)
|
UtcTimestamp |
cloneAddMillis(int amount)
|
UtcTimestamp |
cloneAddMinutes(int amount)
|
UtcTimestamp |
cloneAddMonths(int amount)
|
UtcTimestamp |
cloneAddSeconds(int amount)
|
UtcTimestamp |
cloneAddYears(int amount)
|
UtcTimestamp |
cloneToFirstDayOfWeek(int firstDayOfWeek,
java.util.TimeZone timeZone)
Return a deep copy of this timestamp, which is moved to the first day of the week. |
int |
compareTo(UtcTimestamp o)
|
static int |
daysBetween(UtcTimestamp t1,
UtcTimestamp t2)
|
boolean |
equals(java.lang.Object o)
|
int |
getDay()
|
int |
getDayOfWeek()
|
int |
getDaysOfMonth()
|
static int |
getDaysOfMonth(int y,
int m)
|
int |
getHour()
|
int |
getMilliSecond()
|
int |
getMinute()
|
int |
getMonth()
|
int |
getSecond()
|
java.lang.Integer |
getTzOffset()
|
java.lang.Long |
getUtcMillis()
|
int |
getYear()
|
int |
hashCode()
|
boolean |
isLeapYear()
|
static boolean |
isLeapYear(int y)
|
static int |
monthsBetween(UtcTimestamp t1,
UtcTimestamp t2)
|
void |
moveToFirstDayOfWeek(int firstDayOfWeek,
java.util.TimeZone timeZone)
Move this timestamp to the first day of the week. |
static UtcTimestamp |
now()
|
static UtcTimestamp |
now(int tzOffset)
|
static UtcTimestamp |
now(java.util.TimeZone timeZone)
This method duplicates the functionality of UtcTimestamp(TimeZone)
for convenience reasons. |
void |
setDate(int year,
int month,
int day)
Set the day relative to the currently effective timezone. |
void |
setDateTime(int year,
int month,
int day,
int hour,
int minute,
int second,
int ms,
java.util.TimeZone timeZone)
Set the date, time and timezone offset the given instance in time in the given timezone considering daylight savings time. |
void |
setDateTime(int year,
int month,
int day,
int hour,
int minute,
int second,
java.util.TimeZone timeZone)
Set the date, time and timezone offset the given instance in time in the given timezone considering daylight savings time. |
void |
setDateTime(int year,
int month,
int day,
int millisOfDay,
java.util.TimeZone timeZone)
Set the date, time and timezone offset the given instance in time in the given timezone considering daylight savings time. |
void |
setFromCalendar(java.util.Calendar c)
Convert the passed Calendar object to UtcTimestamp. |
void |
setString(java.lang.String s)
Set an ISO8601 formatted timestamp to this object. |
void |
setTimeOfDay(int hour,
int minute,
int second)
|
void |
setTimeOfDay(int hour,
int minute,
int second,
int millis)
|
void |
setTzOffset(java.lang.Integer tzOffset)
|
void |
setUtcMillis(java.lang.Long utcMillis)
|
java.util.Calendar |
toCalendar()
Convert this UtcTimestamp to java.util.Calendar. |
java.lang.String |
toString()
|
java.lang.String |
toString(int format)
|
static int |
weeksBetween(UtcTimestamp t1,
UtcTimestamp t2,
int firstDayOfWeek)
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long MILLISECONDS_PER_SECOND
public static final long MILLISECONDS_PER_MINUTE
public static final long MILLISECONDS_PER_HOUR
public static final long MILLISECONDS_PER_DAY
Constructor Detail |
---|
public UtcTimestamp()
now()
.
now()
public UtcTimestamp(UtcTimestamp a)
a
- The timestamp to be copied.public UtcTimestamp(java.util.Calendar c)
c
- public UtcTimestamp(long millis)
millis
- public UtcTimestamp(java.util.TimeZone timeZone, long millis)
timeZone
- The Timezone for which to determine the timezone offset.millis
- The milliseconds since 1970-01-01 00:00:00 GMT.public UtcTimestamp(java.util.TimeZone timeZone)
timeZone
- The Timezone for which to determine the timezone offset.public UtcTimestamp(long millis, int tzOffset)
millis
- tzOffset
- in minutespublic UtcTimestamp(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
java.text.ParseException
- If the timestmap is not in the ISO8601 format.Method Detail |
---|
public static boolean isLeapYear(int y)
y
- The year in the range from 1759 to 9999.
public static int getDaysOfMonth(int y, int m)
y
- The year to consider.m
- The month to consider.
public static UtcTimestamp now()
UtcTimestamp()
public static UtcTimestamp now(int tzOffset)
tzOffset
- in minutes
public static UtcTimestamp now(java.util.TimeZone timeZone)
UtcTimestamp(TimeZone)
for convenience reasons.
tzOffset
- in minutes
public java.util.Calendar toCalendar()
public void setFromCalendar(java.util.Calendar c)
c
- public java.lang.Integer getTzOffset()
public void setTzOffset(java.lang.Integer tzOffset)
tzOffset
- The tzOffset to set.public java.lang.Long getUtcMillis()
public void setUtcMillis(java.lang.Long utcMillis)
utcMillis
- The utcMillis to set.public void setDate(int year, int month, int day)
year
- The year in the range from 1759 to 9999.month
- The month in the range from 1 to 12.day
- The month in the range from 1 to 31.public void setDateTime(int year, int month, int day, int millisOfDay, java.util.TimeZone timeZone)
year
- The year in the range from 1759 to 9999.month
- The month in the range from 1 to 12.day
- The month in the range from 1 to 31.millisOfDay
- The milliseconds since midnight of the given day.timeZone
- The timezone to consider.public void setDateTime(int year, int month, int day, int hour, int minute, int second, int ms, java.util.TimeZone timeZone)
year
- The year in the range from 1759 to 9999.month
- The month in the range from 1 to 12.day
- The month in the range from 1 to 31.hour
- The hour of the day in the range from 0 to 23.minute
- The minute of the hour in the range from 0 to 59.second
- The second of the minute in the range from 0 to 59.ms
- The millisecond of the second in the range from 0 to 999.timeZone
- The timezone to consider.public void setDateTime(int year, int month, int day, int hour, int minute, int second, java.util.TimeZone timeZone)
year
- The year in the range from 1759 to 9999.month
- The month in the range from 1 to 12.day
- The month in the range from 1 to 31.hour
- The hour of the day in the range from 0 to 23.minute
- The minute of the hour in the range from 0 to 59.second
- The second of the minute in the range from 0 to 59.timeZone
- The timezone to consider.public void setTimeOfDay(int hour, int minute, int second)
hour
- minute
- second
- public void setTimeOfDay(int hour, int minute, int second, int millis)
hour
- minute
- second
- millis
- public int getYear()
public int getMonth()
public int getDay()
public int getDayOfWeek()
Calendar.SUNDAY
,
Calendar.MONDAY
,
Calendar.TUESDAY
,
Calendar.WEDNESDAY
,
Calendar.THURSDAY
,
Calendar.FRIDAY
,
Calendar.SATURDAY
public int getDaysOfMonth()
public boolean isLeapYear()
public int getHour()
public int getMinute()
public int getSecond()
public int getMilliSecond()
public void addMilliSeconds(long ms)
ms
- The number of milliseconds to add.public void addSeconds(long s)
s
- The number of seconds to add.public void addMinutes(long m)
m
- The number of minutes to add.public void addHours(long h)
h
- The number of hours to add.public void addDays(long d)
d
- The number of days to add.public void addMonths(int m)
m
month to the given timestamp.
This method keeps the return timestamp on the last day in month, so
UtcTimestamp("2007-02-28").addMonths(3) == UtcTimestamp("2007-05-31")
m
- The number of month to add.public void addYears(int y)
m
month to the given timestamp.
This method keeps the return timestamp on the last day in month, so
UtcTimestamp("2007-02-28").addYear(-7) == UtcTimestamp("2000-02-29")
.
y
- The number of years to add.public void add(int field, int amount)
Calendar.add()
in order
to make the transition from Calendar database objects to UtcTimestamp object
as easy as possible.
field
- The field to increment, one of Calendar.YEAR
,
Calendar.MONTH
, Calendar.DAY_OF_YEAR
, Calendar.DAY_OF_MONTH
,
Calendar.HOUR
, Calendar.HOUR_OF_DAY
, Calendar.MINUTE
,
Calendar.SECOND
or Calendar.MILLISECOND
.amount
- The amount to increment the given field.Calendar.add(int, int)
public UtcTimestamp cloneAdd(int field, int amount)
field
- amount
-
public UtcTimestamp cloneAddYears(int amount)
public UtcTimestamp cloneAddMonths(int amount)
public UtcTimestamp cloneAddDays(int amount)
public UtcTimestamp cloneAddHours(int amount)
public UtcTimestamp cloneAddMinutes(int amount)
public UtcTimestamp cloneAddSeconds(int amount)
public UtcTimestamp cloneAddMillis(int amount)
public void add(java.util.TimeZone timeZone, int field, int amount)
Calendar.add()
considering
any change of the timezone offset of the given timezone. If the timeZone
argument
is null
, this method is equivalent to add(int, int)
.
timeZone
- The timezone to account for or null
.field
- The field to increment, one of Calendar.YEAR
,
Calendar.MONTH
, Calendar#DAY
, Calendar.DAY_OF_MONTH
,
Calendar.HOUR
, Calendar.HOUR_OF_DAY
, Calendar.MINUTE
,
Calendar.SECOND
or Calendar.MILLISECOND
.amount
- The amount to increment the given field.Calendar.add(int, int)
public UtcTimestamp cloneToFirstDayOfWeek(int firstDayOfWeek, java.util.TimeZone timeZone)
firstDayOfWeek
- The first day in the week as one of the constants
Calendar.SUNDAY
, ..., Calendar.SATURDAY
.timeZone
- The timezone used to correct the timestamp when
the timezone offset changes between this day and the first day in
the week.public void moveToFirstDayOfWeek(int firstDayOfWeek, java.util.TimeZone timeZone)
firstDayOfWeek
- The first day in the week as one of the constants
Calendar.SUNDAY
, ..., Calendar.SATURDAY
.timeZone
- The timezone used to correct the timestamp when
the timezone offset changes between this day and the first day in
the week.public static int daysBetween(UtcTimestamp t1, UtcTimestamp t2)
t1
- The first timestamp.t2
- The second timestamp.
public static int weeksBetween(UtcTimestamp t1, UtcTimestamp t2, int firstDayOfWeek)
t1
- The first timestamp.t2
- The second timestamp.firstDayOfWeek
- The first day of the week as one of the constants
Calendar.SUNDAY
, ..., Calendar.SATURDAY
..
public static int monthsBetween(UtcTimestamp t1, UtcTimestamp t2)
t1
- The first timestamp.t2
- The second timestamp.
public java.lang.String toString(int format)
format
- One of ISO8601Format.DATE_FORMAT
,
ISO8601Format.DATETIME_FORMAT
,
ISO8601Format.MILLISECOND_FORMAT
,
ISO8601Format.MILLISECOND_FORMAT_NO_TZ
,
or ISO8601Format.DATETIME_FORMAT_NO_TZ
.
public void setString(java.lang.String s) throws java.text.ParseException
java.text.ParseException
- If the given string is not formatted like ISO8601.public java.lang.String toString()
toString
in class java.lang.Object
toString(ISO8601Format.MILLISECOND_FORMAT)
.toString(int)
,
ISO8601Format.DATE_FORMAT
,
ISO8601Format.DATETIME_FORMAT
,
ISO8601Format.MILLISECOND_FORMAT
public int compareTo(UtcTimestamp o)
compareTo
in interface java.lang.Comparable<UtcTimestamp>
public boolean before(UtcTimestamp other)
other
- the second timestamp to test against.
public boolean after(UtcTimestamp other)
other
- the second timestamp to test against.
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
protected java.lang.Object clone()
clone
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |