public class PartialTimestamp
extends java.util.Calendar
There are only two ways to resolve the time: getTime() and getTimeInMillis(). All other means of accessing field values will return unresolved values. If the PartialTimestamp class is unable to resolve a field because of other unset fields, it will simply leave the field unresolved. For example, if the DAY_OF_MONTH is set to 42, and the MONTH is unset, the DAY_OF_MONTH will remain as 42. If later the MONTH is set, the DAY_OF_MONTH may be resolved to an in-range value. ("May," because if the MONTH is FEBRUARY, the YEAR and CENTURY are also needed to be able to resolve the DAY_OF_MONTH.)
Whereever possible and sensible, the PartialTimestamp class mimics the functionality of the GregorianCalendar class.
Since the PartialTimestamp only supports dates within the epoch, the ERA field is always AD, and hence is not used. The DRMAA specification, requires that the year be handled as two separate fields, one for the first n-2 digits (century) and one for the last two digits. Because of the symantics of extending the Calendar class, the CENTURY field is just an alias for the ERA field, and the ERA contains the century data. When using the PartialTimestmap class, the ERA field should not be used.
When rolling a date field, if the PartialTimestamp doesn't have enough information to determine the field's valid value range, e.g. when rolling the DAY_OF_MONTH while MONTH is unset, an assumption will be made. The assumptions a PartialTimestamp instance may make are: a year is 365 days or 53 weeks, and a month is 31 days or 5 weeks.
The PartialTimestamp class adds the idea of field modifiers to the Calendar class. Field modifiers are accessed via the setModifier() and getModifier() methods. A modifier represents a number that will be added to the value of the field. This is useful because in a PartialTimestamp instance, it may necessary to add to an unset field, for example to indicate the concept of "tomorrow." If an add() method or out of range set() method attempts to modify an unset field, the resulting modifier will be stored as the modifier for that field. For example, if the MONTH is set to DECEMBER, and the YEAR is unset, and 1 is added to the MONTH, the result will be that the MONTH is set to JANUARY, the year is still unset, and the YEAR modifier is set to 1. If later the YEAR is set to 97, the modifier will be applied, resulting in a year of 98. To avoid unwanted modifiers, use the roll() method instead of the add() method.
The roll() method in the PartialTimestamp class is very simple. It does not take into account Daylight Savings Time or other complications, as does the roll() method of the GregorianCalendar.
Example:
public static void main (String[] args) { SessionFactory factory = SessionFactory.getFactory (); Session session = factory.getSession (); try { session.init (null); JobTemplate jt = session.createJobTemplate (); jt.setRemoteCommand ("sleeper.sh"); jt.setArgs (new String[] {"5"}); PartialTimestamp date = new PartialTimestamp (); // Run the job on the first of the month at 11:30 date.set (PartialTimestamp.DATE, 1); date.set (PartialTimestamp.HOUR_OF_DAY, 11); date.set (PartialTimestamp.MINUTE, 30); jt.setStartTime (date); String id = session.runJob (jt); session.deleteJobTemplate (jt); session.exit (); } catch (DrmaaException e) { System.out.println ("Error: " + e.getMessage ()); } }
Modifier and Type | Field and Description |
---|---|
static int |
CENTURY
CENTURY is a field required by the DRMAA timestamp.
|
static int |
UNSET
UNSET is the value assigned to fields which have not yet been set.
|
ALL_STYLES, AM, AM_PM, APRIL, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, FRIDAY, HOUR, HOUR_OF_DAY, JANUARY, JULY, JUNE, LONG, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SHORT, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET
Constructor and Description |
---|
PartialTimestamp()
Constructs a default PartialTimestamp instance using the current time
in the default time zone with the default locale.
|
PartialTimestamp(int hour,
int minute,
int second)
Constructs a PartialTimestamp instance with the given date
and time set for the default time zone with the default locale.
|
PartialTimestamp(int year,
int month,
int date,
int hour,
int minute)
Constructs a PartialTimestamp instance with the given date
and time set for the default time zone with the default locale.
|
PartialTimestamp(int year,
int month,
int date,
int hour,
int minute,
int second)
Constructs a PartialTimestamp instance with the given date
and time set for the default time zone with the default locale.
|
PartialTimestamp(java.util.Locale aLocale)
Constructs a PartialTimestamp instance based on the current time
in the default time zone with the given locale.
|
PartialTimestamp(java.util.TimeZone zone)
Constructs a PartialTimestamp instance based on the current time
in the given time zone with the default locale.
|
PartialTimestamp(java.util.TimeZone zone,
java.util.Locale aLocale)
Constructs a PartialTimestamp instance based on the current time
in the given time zone with the given locale.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int field,
int amount)
Adds the given value to the given field.
|
java.lang.Object |
clone()
Makes a complete copy of this object.
|
boolean |
equals(java.lang.Object obj)
Compares two PartialTimestamp objects.
|
int |
get(int field)
Get the value of the given field.
|
int |
getActualMaximum(int field)
Returns the actual maximum value for the field, based on the current field
values.
|
int |
getActualMinimum(int field)
Returns the actual minimum value for the field, based on the current field
values.
|
int |
getGreatestMinimum(int field)
Gets the greatest minimum value that the field may ever have.
|
int |
getLeastMaximum(int field)
Gets the least maximum value that the field may ever have.
|
int |
getMaximum(int field)
Gets the greatest maximum value that the field may ever have.
|
int |
getMinimum(int field)
Gets the least minimum value that the field may ever have.
|
int |
getModifier(int field)
Returns the value of the modifier for the given field.
|
void |
roll(int field,
boolean up)
This method naively rolls the value of the given field by 1, either up or down.
|
void |
roll(int field,
int amount)
This method naively rolls the value of the given field up by the given amount.
|
void |
set(int field,
int value)
Sets the value of the given field.
|
void |
setModifier(int field,
int value)
Sets the value of the modifier for the given field.
|
after, before, clear, clear, compareTo, getAvailableLocales, getDisplayName, getDisplayNames, getFirstDayOfWeek, getInstance, getInstance, getInstance, getInstance, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, getTimeZone, getWeeksInWeekYear, getWeekYear, hashCode, isLenient, isSet, isWeekDateSupported, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, setTimeZone, setWeekDate, toString
public static final int CENTURY
public static final int UNSET
public PartialTimestamp()
public PartialTimestamp(java.util.TimeZone zone)
zone
- the given time zone.public PartialTimestamp(java.util.Locale aLocale)
aLocale
- the given locale.public PartialTimestamp(java.util.TimeZone zone, java.util.Locale aLocale)
zone
- the given time zone.aLocale
- the given locale.public PartialTimestamp(int year, int month, int date, int hour, int minute)
year
- the value used to set the YEAR time field in the calendar.month
- the value used to set the MONTH time field in the calendar.
Month value is 0-based. e.g., 0 for January.date
- the value used to set the DATE time field in the calendar.hour
- the value used to set the HOUR_OF_DAY time field
in the calendar.minute
- the value used to set the MINUTE time field
in the calendar.public PartialTimestamp(int hour, int minute, int second)
hour
- the value used to set the HOUR_OF_DAY time field
in the calendar.minute
- the value used to set the MINUTE time field
in the calendar.second
- the value used to set the SECOND time field
in the calendar.public PartialTimestamp(int year, int month, int date, int hour, int minute, int second)
year
- the value used to set the YEAR time field in the calendar.month
- the value used to set the MONTH time field in the calendar.
Month value is 0-based. e.g., 0 for January.date
- the value used to set the DATE time field in the calendar.hour
- the value used to set the HOUR_OF_DAY time field
in the calendar.minute
- the value used to set the MINUTE time field
in the calendar.second
- the value used to set the SECOND time field
in the calendar.public int getModifier(int field)
field
- the field whose modifier will be returnedpublic void setModifier(int field, int value)
field
- the field whose modifier will be setvalue
- the value to which to set the field's modifierpublic void add(int field, int amount)
add
in class java.util.Calendar
field
- the field to which to add the amountamount
- the amount to addpublic void set(int field, int value)
set
in class java.util.Calendar
field
- the field to setvalue
- the value to which to set the fieldpublic int get(int field)
get
in class java.util.Calendar
field
- which field's value to getpublic int getGreatestMinimum(int field)
getGreatestMinimum
in class java.util.Calendar
field
- the field of interestpublic int getLeastMaximum(int field)
getLeastMaximum
in class java.util.Calendar
field
- the field of interestpublic int getMaximum(int field)
getMaximum
in class java.util.Calendar
field
- the field of interestpublic int getMinimum(int field)
getMinimum
in class java.util.Calendar
field
- the field of interestpublic void roll(int field, boolean up)
roll
in class java.util.Calendar
field
- the field to rollup
- whether to roll uppublic void roll(int field, int amount)
roll
in class java.util.Calendar
field
- the field to rollamount
- the amount to roll uppublic int getActualMinimum(int field)
getActualMinimum
in class java.util.Calendar
field
- the field of interestpublic int getActualMaximum(int field)
getActualMaximum
in class java.util.Calendar
field
- the field of interestpublic boolean equals(java.lang.Object obj)
equals
in class java.util.Calendar
obj
- the object against which to comparepublic java.lang.Object clone()
clone
in class java.util.Calendar
The contents of this file are licensed under the Sun Industry Standards Source License version 1.2.
Copyright 2008, Sun Microsystems, Inc.