public class date extends BaseDataType
The Progress date is similar to the "Chronological Julian Day Number" (which has a base date of 01/01/4712 BC or 01/01/-4713 which is the 0 day) however it is 1 day off (its base date is 12/31/-4714 for day 0).
The following is the mapping of Progress language features to the corresponding feature in this class:
+ operator (date + integer days)plusDays(date,long)
+ operator (date + decimal days)plusDays(date,NumberType)
- operator (date - integer days)minusDays(date,long)
- operator (date - decimal days)minusDays(date,NumberType)
- operator (date - date)differenceNum(com.goldencode.p2j.util.date, com.goldencode.p2j.util.date)
= or EQ operatorCompareOps.isEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
<> or NE operatorCompareOps.isNotEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
> or GT operatorCompareOps.isGreaterThan(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
>= or GE operatorCompareOps.isGreaterThanOrEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
< or LT operatorCompareOps.isLessThan(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
<= or LE operatorCompareOps.isLessThanOrEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
day functionday(com.goldencode.p2j.util.date)
weekday functionweekday(com.goldencode.p2j.util.date)
month functionmonth(com.goldencode.p2j.util.date)
year functionyear(com.goldencode.p2j.util.date)
maximum functionCompareOps.maximum(BaseDataType[])
minimum functionCompareOps.minimum(BaseDataType[])
decimal function (to convert dates)decimalValue()
integer function (to convert dates)integerValue()
string function (default format)toString()
(user-defined format)toString(String)
(export format)toStringExport()
time functionsecondsSinceMidnight()
timezone function (no parameter)getDefaultTimeZoneOffset()
timezone function (character parameter)getOffsetForSpec(com.goldencode.p2j.util.character)
etime functionelapsed()
today functiontoday()
date function (integer parameter)date(NumberType)
date function (integer m, d, y)date(NumberType,NumberType,NumberType)
date function (string parameter)date(String)
date function (date subclass parameter)date(date)
date-format SESSION attributegetDateOrder()
orsetDateOrder(character)
timezone SESSION attributegetTimeZone()
orsetTimeZone(NumberType)
time-source SESSION attributegetTimeSource()
orsetTimeSource(character)
year-offset SESSION attributegetYearOffset()
orsetYearOffset(NumberType)
[literal]fromLiteral(String)
Date processing has been made compatible with Progress including the
implementation of controllable Y2K windowing (the start year defaults to
1950). The replacement for using the -yy startup parameter or the
session:year-offset attribute is to use the setWindowingYear(long)
.
2-digit to 4-digit year conversion can be accessed manually via the
windowingImpl(int)
.
The order of the date fields when reading from a string or when writing to a string defaults to 'mdy' format, but this can be changed using a directory setting. That is equivalent to the -d startup option or the session:date-format attribute in Progress. To set this value, one must store the order of the 3 date sub-components as a 3 character string with one character each for "D" (day), "M" (month) and "Y" (year). This value is context-specific to the current user's session. The default value is "MDY".
The value returned may have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/dateFormat
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/dateFormat
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/dateFormat
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/dateFormat
This class is very dependent upon the GregorianCalendar
and
Progress itself seems to have no concept of different types of calendars
(e.g. lunar...) so this is OK. The two GregorianCalendar
implementations (Progress and J2SE) appear to be quite compatible including
how they handle the missing days from 10-05-1582 through 10-14-1582. Both
implementations allow these dates to be instantiated and both generate
a date that is equivalent to 10-15-1582 through 10-24-1582 respectively.
This leads to apparent logical contradictions such as 10-14-1582 comparing
as greater than 10-15-1582.
The Progress date has no notion of a time of day and the Java
java.util.Date
is inherently built with this notion (and
the notion of a timezone). When being created from any J2SE generated
date source (e.g. an instance of the Date class or the default constructor
which accesses the current system time), this timezone specific data
must be taken into account and neutered in the resulting stored date.
Likewise, whenever using this data, no timezone is used unless one is
converting this instance into an instance of java.util.Date
,
in which case the timezone can be overridden as in
dateValue(TimeZone)
or in the date(Date,TimeZone)
constructor.
This class also features a built-in regression testing harness that is
invoked via main(java.lang.String[])
.
Modifier and Type | Class and Description |
---|---|
private static class |
date.ContextContainer
Simple container that stores and returns a context-local instance of
the global work area.
|
private static class |
date.GMTCalendar
Provides a thread local cache for a GMT calendar.
|
private static class |
date.NullCalendar
Provides a thread local cache for a default calendar.
|
private static class |
date.TestCase
Simple testcase wrapper to check Julian day number calculations.
|
private static class |
date.WorkArea
Stores global data relating to the state of the current context.
|
private static class |
date.ZoneCalendar
Provides a thread local cache for a timezone-specific calendar.
|
Modifier and Type | Field and Description |
---|---|
static byte |
DAY
Represents the day component of the string formatted date.
|
private static java.lang.String |
defaultFormat
The default format string.
|
private static date.GMTCalendar |
gmtGC
The GMT calendar cache (thread local).
|
static long |
INVALID_DATE
An invalid date (cannot exist in Progress 4GL).
|
protected static int |
INVALID_TZ
An invalid offset for SESSION:TIMEZONE.
|
private long |
julian
Stores the date for this instance in Progress 4GL format.
|
static long |
JULIAN_EPOCH_OFFSET
The number of days between the Progress base date (12/31/-4714) and the
Java epoch start (01/01/1970).
|
protected static int |
MAX_VALID_TZ
Maximum valid offset for SESSION:TIMEZONE.
|
static long |
MILLIS_PER_DAY
Number of milliseconds per day.
|
protected static int |
MIN_VALID_TZ
Minimum valid offset for SESSION:TIMEZONE.
|
static byte |
MONTH
Represents the month component of the string formatted date.
|
private static date.NullCalendar |
nullGC
The default calendar cache (thread local).
|
private static java.util.Map<java.lang.Integer,java.util.TimeZone> |
offset2tz
Cached mappings of tz offsets to their
TimeZone instance. |
static byte[] |
ORDER_MDY
MDY order of date components.
|
static byte[] |
ORDER_YMD
YMD order of date components.
|
private static java.lang.String |
TZ_ATTR_ERR1
Format specification for first TIMEZONE attribute error.
|
private static java.lang.String |
TZ_ATTR_ERR2
Format specification for second TIMEZONE attribute error.
|
private static java.util.Map<java.util.TimeZone,date.ZoneCalendar> |
tzcals
Cache of other timezone-specific calendar thread local caches.
|
private boolean |
unknown
Indicates if this instance is set to the unknown value.
|
private static date.ContextContainer |
work
Stores context-local state variables.
|
private date.WorkArea |
workArea
The working area where this instance was created.
|
static byte |
YEAR
Represents the year component of the string formatted date.
|
Constructor and Description |
---|
date()
Creates an instance that represents an unknown date.
|
date(BaseDataType value)
This is a special c'tor which should be used only when converting the
value returned by a function or method with polymorphic return type into the
expected type (i.e.
|
date(character d)
Parses a string with a format based on the Progress 4GL rules for
converting a string to a date.
|
date(date d)
Constructs an instance with the exact same state as the passed
instance.
|
date(java.util.Date d)
Creates an instance from a
java.util.Date instance. |
date(java.util.Date d,
java.util.TimeZone zone)
Creates an instance from a
java.util.Date instance. |
date(double month,
double day,
double year)
Creates an instance based on specific numeric input.
|
date(double month,
double day,
double year,
boolean forceFourDigits)
Creates an instance based on specific numeric input.
|
date(double month,
double day,
NumberType year)
Creates an instance based on specific numeric input.
|
date(double month,
NumberType day,
double year)
Creates an instance based on specific numeric input.
|
date(double month,
NumberType day,
NumberType year)
Creates an instance based on specific numeric input.
|
date(int dayNumber)
Creates an instance that represents the number of days (positive or
negative) from the Progress 4GL base date of 12/31/-4714.
|
date(long dayNumber)
Creates an instance that represents the number of days (positive or
negative) from the Progress 4GL base date of 12/31/-4714.
|
date(NumberType dayNumber)
Creates an instance that represents the number of days (positive or
negative) from the Progress 4GL base date of 12/31/-4714.
|
date(NumberType month,
double day,
double year)
Creates an instance based on specific numeric input.
|
date(NumberType month,
double day,
NumberType year)
Creates an instance based on specific numeric input.
|
date(NumberType month,
NumberType day,
double year)
Creates an instance based on specific numeric input.
|
date(NumberType month,
NumberType day,
NumberType year)
Creates an instance based on specific numeric input.
|
date(java.lang.String d)
Parses a string with a format based on the Progress 4GL rules for
converting a string to a date.
|
date(java.lang.String d,
java.lang.String format,
int windowingYear)
Converts a string to a date using a specified format and an optional windowing year.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
addSeparators(byte[] dateFormat,
java.lang.String input)
Add separators to a string (which has no separators) where the data
represents a date.
|
void |
assign(BaseDataType value)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
void |
assign(date value)
Sets the state (data and unknown value) of this instance based on the state of the passed
instance.
|
void |
assign(Undoable value)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
static long |
calendarToLocalMillis(java.util.GregorianCalendar gc)
Convert a UTC time into a timezone specific number of milliseconds
since the epoch (January 1, 1970).
|
static java.lang.String |
cleanFormattedDate(java.lang.String input)
Remove unnecessary characters and extra zero digits from input that represents
a valid date.
|
int |
compareTo(java.lang.Object obj)
Compares this instance with the specified instance and returns a -1
if this instance is less than the specified, 0 if the two instances
are equal and 1 if this instance is greater than the specified
instance.
|
private static java.util.Date |
createDate(int yy,
int mm,
int dd)
Simple 'factory' method to create instances of a specific date using the
GregorianCalendar and handling the 0-based month processing on behalf of the
caller (the caller uses a 1-based month index). |
static long |
dateToLocalMillis(java.util.Date d,
java.util.TimeZone zone)
Convert a UTC time into a timezone specific number of milliseconds
since the epoch (January 1, 1970).
|
java.util.Date |
dateValue()
Returns the current instance as an instance of the
Date
class which will accurately represent the UTC time that corresponds
to the current date in the timezone stored in this instance or
in the default timezone if the stored timezone is null . |
java.util.Date |
dateValue(java.util.TimeZone override)
Returns the current instance as an instance of the
Date
class which will accurately represent the UTC time that corresponds
to the current date in the timezone passed as a parameter or in the
default timezone if the passed timezone is null . |
static integer |
day(date dd)
Returns the current day of the month for the given
date . |
decimal |
decimalValue()
Returns the day number as an
integer . |
void |
decrement()
Decrements the Julian day number by 1.
|
void |
deepAssign(date value)
Sets the state (data and unknown value) and configuration (time-zone)
of this instance based on the state of the passed instance.
|
java.lang.String |
defaultFormatString()
Return the default display format string for this type.
|
static int |
difference(date op1,
date op2)
Returns the number of days difference between the the dates of two
instances.
|
static integer |
differenceNum(date op1,
date op2)
Returns the number of days difference between the dates of two instances.
|
double |
doubleValue()
Returns the day number as a
double . |
BaseDataType |
duplicate()
Does the same as standard
clone() method but returns an
instance of BaseDataType and doesn't throw the
CloneNotSupportedException . |
private static void |
editOrder(byte[] order,
int idx,
byte type,
char comp)
Helper to maintain the component order array.
|
static int64 |
elapsed()
Returns the number of milliseconds since the base milliseconds counter
was reset or since the process started (this is an approximation).
|
static int64 |
elapsed(boolean reset)
Returns the number of milliseconds since the base milliseconds counter was reset or since
the process started (this is an approximation).
|
static int64 |
elapsed(logical reset)
Returns the number of milliseconds since the base milliseconds counter was reset or since
the process started (this is an approximation).
|
boolean |
equals(java.lang.Object o)
An equality test which handles the most common cases with the least
amount of overhead.
|
private static int |
findNextSeparator(java.lang.StringBuilder input,
int start)
Returns the index position within the input string where the next separator
(following the starting position) can be found.
|
static date |
fromLiteral(java.lang.String str)
Parse a Progress date literal (format mm/dd/yyyy).
|
static void |
genBadCharInFormatError(int idx,
java.lang.String fmt)
Generate the error for the condition where any component of the
date is empty or invalid.
|
private java.lang.String |
genFailedString(java.lang.String fmt)
Generate the output string for the condition where any component of the
date cannot fit into the specified format string.
|
private static void |
genInvalidDateOrder()
Generate the error for the condition where the specification of the
date component order is not valid.
|
protected long |
getAbsoluteTimeOffset()
Returns the absolute time in milliseconds since Java 'Epoch' or 0
if this instance is
unknown . |
static byte[] |
getDateComponentOrder()
Gets the order of date components for conversion to/from strings.
|
(package private) static character |
getDateOrder()
Gets the order of date components for conversion to/from strings.
|
int |
getDay()
Returns the day of the month of the current instance from 1 to the
highest possible day of the corresponding month (maximum of 31)
independent of any timezone considerations.
|
integer |
getDayNum()
Returns the day of the month of the current instance from 1 to the
highest possible day of the corresponding month (maximum of 31)
independent of any timezone considerations.
|
static int |
getDefaultOffset()
Get the default timezone as specified in the SESSION:TIMEZONE offset or if not specified
there, the default JVM timezone's "offset" (raw + dst) converted from milliseconds to
minutes.
|
static java.util.TimeZone |
getDefaultTimeZone()
Get the default timezone as specified in the SESSION:TIMEZONE offset or
if not specified there, the default JVM timezone.
|
static integer |
getDefaultTimeZoneOffset()
Obtains the effective default timezone offset in minutes from UTC for
this user's context.
|
(package private) static integer |
getDisplayTimeZone()
Obtains the currently configured DISPLAY-TIMEZONE attribute for the current
user's context.
|
protected java.lang.String |
getIsoDate()
Obtains the text form of this date instance in ISO 8601 standard format.
|
int |
getMonth()
Returns the month of the current instance from 1 to 12 independent of
any timezone considerations.
|
integer |
getMonthNum()
Returns the month of the current instance from 1 to 12 independent of
any timezone considerations.
|
static integer |
getOffsetForSpec(character spec)
Obtains the timezone offset in minutes from UTC that corresponds to the
given timezone specification.
|
static integer |
getOffsetForSpec(java.lang.String spec)
Obtains the timezone offset in minutes from UTC that corresponds to the
given timezone specification.
|
(package private) static character |
getTimeSource()
Obtains the currently configured TIME-SOURCE attribute for the current
user's context.
|
(package private) static integer |
getTimeZone()
Accesses the SESSION:TIMEZONE used as the default offset in minutes from
UTC for this user's context.
|
int |
getWeekday()
Returns the day of the week of the current instance from 1 (Sunday) to
7 (Saturday) independent of any timezone considerations.
|
integer |
getWeekdayNum()
Returns the day of the week of the current instance from 1 (Sunday) to
7 (Saturday) independent of any timezone considerations.
|
static int |
getWindowingYear()
Accesses the beginning year of the 100 year period where 2 digit dates
implicitly correspond to 4 year dates.
|
private date.WorkArea |
getWorkArea()
Get the current context-local data structure.
|
int |
getYear()
Returns the year of the current instance with a negative value used
to represent the years in the BC era, independent of any timezone
considerations.
|
integer |
getYearNum()
Returns the year of the current instance with a negative value used
to represent the years in the BC era, independent of any timezone
considerations.
|
(package private) static integer |
getYearOffset()
Implementation of SESSION:YEAR-OFFSET attribute getter.
|
protected static java.util.GregorianCalendar |
getZoneCalendar(java.util.TimeZone zone)
Get the timezone-specific calendar out of the JVM-wide cache or if one
is not yet in the cache, create it and add it to the cache before
returning.
|
static java.util.TimeZone |
getZoneFromOffset(int offset)
Convert the offset to a timezone ID and return the resulting timezone
instance.
|
int |
hashCode()
Hash code implementation which is consistent with
BaseDataType.equals(java.lang.Object) . |
void |
increment()
Increments the Julian day number by 1.
|
private static integer |
initDisplayTimezone()
Returns the configured value in the directory for the display timezone
(
SESSION:DISPLAY-TIMEZONE ). |
protected static byte[] |
initFormat(java.lang.String fmt)
Determines the order of the 3 date sub-components by reading a 3
character string from the directory where there is one character each
for "D" (day), "M" (month) and "Y" (year).
|
private static java.lang.String |
initTimeSource()
Returns the system from which time values will be obtained.
|
private static integer |
initTimezoneOffset()
Returns the configured value in the directory for the default offset in
minutes from UTC (SESSION:TIMEZONE).
|
private static int |
initWindowingYear()
Returns the beginning year of the 100 year period where 2 digit dates
implicitly correspond to 4 year dates.
|
protected long |
instantiateDate(int year,
int month,
int day)
Convert the components of a date into a Julian day number that is
Progress compatible.
|
BaseDataType |
instantiateDefault()
Creates a new instance of the same type that represents the default initialized value.
|
protected void |
instantiateFromStringWorker(java.lang.String spec,
java.lang.String format,
int windowingYear)
Parses a string with a format based on the Progress 4GL rules for converting a string to a
date . |
BaseDataType |
instantiateUnknown()
Creates a new instance of the same type that represents the
unknown value . |
static date |
instantiateUnknownDate()
Deprecated.
|
integer |
integerValue()
Returns the day number as an
integer . |
int |
intValue()
Returns the day number as an
int . |
boolean |
inY2KWindow()
Determines if the current date lies inside the 100 year window where
a 2-digit date implicitly corresponds to a 4-digit date.
|
static character |
isoDate(date date)
Obtains the text form of the given date instance in ISO 8601 standard format.
|
boolean |
isUnknown()
Reports if this instance represents the
unknown value . |
static long |
julianDayToMillis(long jd)
Converts a Progress 4GL style Julian day into the number of
milliseconds since the Java epoch.
|
long |
longValue()
Returns the day number as a
long . |
static void |
main(java.lang.String[] args)
Command line interface which provides a test harness to regression
test this class.
|
static date |
maximum(date... list)
Returns the instance from the list which has the latest date.
|
date |
maximum(date d)
Returns the instance which has a later date.
|
static long |
millisToJulianDay(long millis)
Converts a number of milliseconds from the Java epoch into a Progress 4GL style Julian day.
|
static date |
minimum(date... list)
Returns the instance from the list which has the earliest date.
|
date |
minimum(date d)
Returns the instance which has an earlier date.
|
static date |
minusDays(date op1,
double op2)
Convenience method to subtract
days from the date which
is the left operand and return a new instance representing that date. |
static date |
minusDays(date op1,
long op2)
Convenience method to subtract
days from the date which
is the left operand and return a new instance representing that date. |
static date |
minusDays(date op1,
NumberType op2)
Convenience method to subtract
days from the date which
is the left operand and return a new instance representing that date. |
static integer |
month(date dd)
Returns the month of the year for the given
date . |
static java.util.GregorianCalendar |
neutralMillisToCalendar(long millis,
java.util.TimeZone zone)
Convert a time-neutral number of milliseconds since the epoch into a
UTC time as represented by the
GregorianCalendar class. |
static java.util.Date |
neutralMillisToDate(long millis,
java.util.TimeZone zone)
Convert a time-neutral number of milliseconds since the epoch into a
UTC time as represented by the
Date class. |
private static java.lang.String |
offsetToZoneId(int offset)
Convert the Progress-style timezone offset (in minutes) to a JVM-style
timezone ID that can be used to obtain a
TimeZone instance. |
private long |
parseWorker(java.lang.String input,
byte[] dateFormat,
int windowingYear)
Core worker that implements the default Progress 4GL string to date
conversion processing as documented by
date(java.lang.String) . |
static date |
plusDays(date op1,
double op2)
Adds
days to the date of the left operand and returns a
new instance representing that date. |
static date |
plusDays(date op1,
long op2)
Adds
days to the date of the left operand and returns a
new instance representing that date. |
static date |
plusDays(date op1,
NumberType op2)
Adds
days to the date of the left operand and returns a
new instance representing that date. |
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
static int64 |
secondsSinceMidnight()
Returns the number of seconds since midnight in the current JVM timezone.
|
static int64 |
secondsSinceMidnight(java.util.GregorianCalendar gc)
Returns the number of seconds since midnight in the given calendar.
|
static void |
setDateComponentOrder(byte[] dateFormat)
Sets the order of date components for conversion to/from strings.
|
(package private) static void |
setDateOrder(character dateFormat)
Sets the order of date components for conversion to/from strings.
|
static void |
setDateOrder(java.lang.String dateFormat)
Sets the order of date components for conversion to/from strings.
|
void |
setDayNumber(double day)
Sets the Julian day number (independently of the state of the unknown
value) as an integral number of days since the Progress 4GL base date
of 12/31/-4714.
|
void |
setDayNumber(long day)
Sets the Julian day number (independently of the state of the unknown
value) as an integral number of days since the Progress 4GL base date
of 12/31/-4714.
|
void |
setDayNumber(NumberType day)
Sets the Julian day number (independently of the state of the unknown
value) as an integral number of days since the Progress 4GL base date
of 12/31/-4714.
|
static void |
setDisplayTimeZone(long displayTimezone)
Sets the
DISPLAY-TIMEZONE attribute for the user's context. |
static void |
setDisplayTimeZone(NumberType displayTimezone)
Sets the
DISPLAY-TIMEZONE attribute for the user's context. |
static void |
setSessionTimeZone(long offset)
Sets the SESSION:TIMEZONE used as the default offset in minutes from
UTC for this user's context.
|
static void |
setTimeSource(character timeSource)
Sets the
TIME-SOURCE attribute for the user's context. |
static void |
setTimeSource(java.lang.String timeSource)
Sets the
TIME-SOURCE attribute for the user's context. |
static void |
setTimeZone(NumberType offset)
Sets the SESSION:TIMEZONE used as the default offset in minutes from
UTC for this user's context.
|
void |
setUnknown()
Sets the state of this instance's
unknown value flag to
true . |
static void |
setWindowingYear(long year)
Sets the beginning year of the 100 year period where 2 digit dates
implicitly correspond to 4 year dates.
|
(package private) static void |
setYearOffset(NumberType year)
Implementation of SESSION:YEAR-OFFSET attribute setter.
|
protected static int |
specToOffset(java.lang.String spec)
Obtains the timezone offset in minutes from UTC that corresponds to the
given timezone specification.
|
static date |
today()
Creates an instance that represents today's date using the local system clock time.
|
java.lang.String |
toString()
Creates a string representation of the instance data using the default
Progress 4GL format of '99/99/99' which is only useful for displaying
dates in the Y2K window since any other date will generally not be
displayable in such a format.
|
java.lang.String |
toString(java.lang.String fmt)
Create a string representation of this date using a Progress 4GL style
date format string such as 99/99/99 or 99-99-9999.
|
java.lang.String |
toStringExport()
Creates a string representation of the instance data using the Progress
4GL 'export' format.
|
java.lang.String |
toStringMessage()
Creates a string representation of the instance data in a form that is
compatible with the
MESSAGE language statement. |
java.lang.String |
toStringSQL()
Creates a SQL compatible string representation of the instance data
(the format is YYYY-MM-DD).
|
protected java.lang.String |
toYearString(int min,
int max,
boolean force)
Generate a string representation of the year based on the unusual
rules of the Progress 4GL.
|
private static int |
trimZeros(java.lang.StringBuilder sb,
int start)
Remove leading zeros from one segment of a string that represents a date.
|
static ErrorManager.ErrorEntry |
validate(int month,
int day,
int year,
boolean forceFourDigits)
Validate specified values and return error information if they don't
consist of correct date components.
|
static integer |
weekday(date dd)
Returns the current day of the week for the given
date . |
static int |
windowingImpl(int year)
Converts a 2 digit year to a 4 digit year, if needed.
|
private static int |
windowingImpl(int year,
int windowingYear)
Converts a 2 digit year to a 4 digit year, if needed.
|
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
static integer |
year(date dd)
Returns the year for the given
date . |
private void |
yymmddWorker(int yy,
int mm,
int dd)
Initializes an new instance based on explicit calendar components.
|
private void |
yymmddWorker(int yy,
int mm,
int dd,
boolean forceFourDigits)
Initializes an new instance based on explicit calendar components.
|
calcFormatLength, deepCopy, elementsOfType, formatLength, generateDefault, generateUnknown, getTypeName, incompatibleTypesOnConversion, initializeDefaultExtent, instantiateDefaultExtent, isUnknownValue, maximum, minimum, notUnknownValue, sameType
changed, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobal
public static final long JULIAN_EPOCH_OFFSET
public static final long INVALID_DATE
public static final byte DAY
public static final byte MONTH
public static final byte YEAR
public static final byte[] ORDER_MDY
public static final byte[] ORDER_YMD
public static final long MILLIS_PER_DAY
protected static final int MIN_VALID_TZ
protected static final int MAX_VALID_TZ
protected static final int INVALID_TZ
private static final date.ContextContainer work
private static final java.lang.String defaultFormat
private static final java.lang.String TZ_ATTR_ERR1
private static final java.lang.String TZ_ATTR_ERR2
private static date.NullCalendar nullGC
private static date.GMTCalendar gmtGC
private static java.util.Map<java.util.TimeZone,date.ZoneCalendar> tzcals
private static java.util.Map<java.lang.Integer,java.util.TimeZone> offset2tz
TimeZone
instance.private long julian
private boolean unknown
private date.WorkArea workArea
public date()
public date(BaseDataType value)
assign(BaseDataType)
).value
- The value to be used for this instance.public date(java.util.Date d)
java.util.Date
instance.
WARNING: this will only work if the calendar in which this date
was constructed is the GregorianCalendar
AND if the
timezone in which this object was created is the same as the current
default for this JVM instance. If this is not correct then you
must use the date(Date,TimeZone)
version.
d
- The Date
instance from which to pattern the instance.public date(java.util.Date d, java.util.TimeZone zone)
java.util.Date
instance.
If a timezone is specified, it is stored to be used when instantiating
java.util.Date
instances using this instance's data.
d
- The Date
instance from which to pattern the
instance or null
to obtain the current time.zone
- The timezone whose offset is to be used to calculate the
date or null
if the default JVM timezone is to be used.public date(java.lang.String d) throws ErrorConditionException
Date literals are generally matched in mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy formats, although the 3 types of separators ('-', '/' and '.') can even be mixed in the same string (e.g. (mm-dd/yyyy or mm.dd-yyyy). Both months and days can be specified in any number of digits (there must be at least 1 digit, but there can 5 digits as long as the resulting month or day is valid). The month must be an integer between 1 and 12 and the day must be between 1 and the number of days in the given month. All separators and the year digits are optional. If separators are missing, the first 2 digits are treated as the month, the next 2 digits as the day and the remaining digits as the year. If the first separator is used and there is a year, then the second separator must also be used. Likewise, there cannot be a day/year separator without first having a month/day separator.
If the year digits are missing, the current year will be used. There can be an optional negative sign preceding any year digits and one can specify a dd and yyyy separator without specifying any year digits at all. Any number of year digits are valid, though in Progress the year 0 is treated specially, as follows:
So y, yy, yyy, yyyy, yyyyy... and -y, -yy, -yyy, -yyyy... all are valid year specifications, except for the specific year zero issue noted above. The largest positive year value is 32767 and the largest negative year value is -32768. Note that leading zeros are ignored. Negative years can only be specified in a string that has separators.
Any positive year of 1 or 2 digits is interpreted based on the current
Y2K window which can be obtained using getWindowingYear()
.
Leading and trailing spaces are allowed around the mm/dd/yyyy data but no spaces may be inserted inside the date value. Any additional non-whitespace included in the string after the date AND after intervening whitespace, is ignored.
d
- The formatted string date to convert.ErrorConditionException
public date(java.lang.String d, java.lang.String format, int windowingYear) throws ErrorConditionException
d
- The formatted string date to convert.format
- The format string used for date conversion.windowingYear
- The start of the 100 year window used for conversion when year is in 2-digits.ErrorConditionException
date(String)
public date(date d)
date
subclass.d
- The instance from which to copy state.public date(character d) throws ErrorConditionException
Date literals are generally matched in mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy formats, although the 3 types of separators ('-', '/' and '.') can even be mixed in the same string (e.g. (mm-dd/yyyy or mm.dd-yyyy). Both months and days can be specified in any number of digits (there must be at least 1 digit, but there can 5 digits as long as the resulting month or day is valid). The month must be an integer between 1 and 12 and the day must be between 1 and the number of days in the given month. All separators and the year digits are optional. If separators are missing, the first 2 digits are treated as the month, the next 2 digits as the day and the remaining digits as the year. If the first separator is used and there is a year, then the second separator must also be used. Likewise, there cannot be a day/year separator without first having a month/day separator.
If the year digits are missing, the current year will be used. There can be an optional negative sign preceding any year digits and one can specify a dd and yyyy separator without specifying any year digits at all. Any number of year digits are valid, though in Progress the year 0 is treated specially, as follows:
So y, yy, yyy, yyyy, yyyyy... and -y, -yy, -yyy, -yyyy... all are valid year specifications, except for the specific year zero issue noted above. The largest positive year value is 32767 and the largest negative year value is -32768. Note that leading zeros are ignored. Negative years can only be specified in a string that has separators.
Any positive year of 1 or 2 digits is interpreted based on the current
Y2K window which can be obtained using getWindowingYear()
.
Leading and trailing spaces are allowed around the mm/dd/yyyy data but no spaces may be inserted inside the date value. Any additional non-whitespace included in the string after the date AND after intervening whitespace, is ignored.
If the parameter is unknown value
the resulting date is
the unknown value
.
d
- The formatted string date to convert.ErrorConditionException
public date(double month, double day, double year) throws ErrorConditionException
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(double month, double day, double year, boolean forceFourDigits) throws ErrorConditionException
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits and forceFourDigits
is true
. It will be used unchanged if
it is 3 or more digits.forceFourDigits
- If true then 2-digit years will be windowed into the right
century.ErrorConditionException
public date(NumberType month, NumberType day, double year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(double month, NumberType day, NumberType year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(NumberType month, double day, NumberType year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(double month, NumberType day, double year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(NumberType month, double day, double year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(double month, double day, NumberType year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(NumberType month, NumberType day, NumberType year) throws ErrorConditionException
If the parameters are unknown value
the resulting date is
the unknown value
.
month
- The month from 1 to 12.day
- The day of the specified month between 1 and the largest
possible date (31 or less).year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. The value will be windowed into the
right century if it is 2 digits. It will be used unchanged if
it is 3 or more digits.ErrorConditionException
public date(long dayNumber)
date -1000 is 04/05/-4716 date -1 is 12/30/-4714 date 0 is 12/31/-4714 date 1 is 01/01/-4713 date 1685264 is 12/31/-100 date 1685265 is 01/01/-099 date 1721424 is 12/31/-001 date 1721425 is 01/01/001 date 2299161 is 10/04/1582 date 2299162 is 10/15/1582 (note the gap in the Gregorian Calendar) date 2421684 is 03/30/1918 date 2421685 is 03/31/1918 (first DST in U.S.A.) date 2421686 is 04/01/1918 date 2433283 is 12/31/1949 date 2433284 is 01/01/50 (first date in default Y2K window - 1950) date 2440589 is 01/01/70 (beginning of Java epoch) date 2451545 is 12/31/99 date 2451546 is 01/01/00 date 2453475 is 04/13/05 date 2469808 is 12/31/49 (last date in default Y2K window - 2049) date 2469809 is 01/01/2050
dayNumber
- The number of days since 12/31/-4714.public date(int dayNumber)
date(long)
.dayNumber
- The number of days since 12/31/-4714.public date(NumberType dayNumber)
date(long)
.
If the parameter is unknown value
the resulting date is
the unknown value
.
dayNumber
- The number of days since 12/31/-4714.public static date today()
public static date fromLiteral(java.lang.String str)
str
- The string representation of the date literal.public static long dateToLocalMillis(java.util.Date d, java.util.TimeZone zone)
d
- The date object representing the UTC value to convert or
null
if the current UTC time should be used.zone
- The timezone object whose specific attributes should be used
in the conversion of the UTC value or null
if
JVM default timezone should be used.public static long calendarToLocalMillis(java.util.GregorianCalendar gc)
gc
- The GregorianCalendar
representing the UTC value to convert.public static java.util.Date neutralMillisToDate(long millis, java.util.TimeZone zone)
Date
class. If no timezone
is passed in, the default JVM timezone will be used.millis
- The time-neutral number of milliseconds since the epoch.zone
- The timezone object whose specific attributes should be used
in the conversion to the UTC value or null
if
JVM default timezone should be used.public static java.util.GregorianCalendar neutralMillisToCalendar(long millis, java.util.TimeZone zone)
GregorianCalendar
class.
If no timezone is passed in, the GMT timezone will be used which means
that all timezone processing is effectively disabled.millis
- The time-neutral number of milliseconds since the epoch.zone
- The timezone object whose specific attributes should be used
in the conversion to the UTC value or null
if
timezone processing should be disabled.public static long julianDayToMillis(long jd)
jd
- The Julian day (days since 12/31/-4714).public static long millisToJulianDay(long millis)
millis
- The number of milliseconds from the Java epoch which specifies a specific point
in time.millis
does not
represent a full day, the result is adjusted to correct result using Euclidian
remainder arithmetic.public static date maximum(date... list)
null
values.list
- The list of dates to check.unknown value
if any
entries in the list are unknown or null
if
an empty list is passed.public static date minimum(date... list)
null
values.list
- The list of dates to check.unknown value
if any
entries in the list are unknown or null
if
an empty list is passed.public static int getWindowingYear()
The value returned may have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/windowingYear
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/windowingYear
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/windowingYear
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/windowingYear
If no value is found via this lookup, then the Progress 4GL default of 1950 will be returned.
public static void setWindowingYear(long year)
The value set is specific to the current user's context.
year
- The first year of the 2-digit to 4-digit mapping window for Y2K purposes.static void setYearOffset(NumberType year)
getWindowingYear()
).year
- The new start year for the two-digit windowing range.static integer getYearOffset()
getWindowingYear()
).public static byte[] getDateComponentOrder()
The order of the 3 date sub-components as a 3 byte array using the
constants DAY
, MONTH
and YEAR
once each. The byte order from index 0 to index 2 represents the
left to right ordering of the components. So the leftmost date component
will be defined by the byte at index position 0.
The value accessed is specific to the current user's context.
public static void setDateComponentOrder(byte[] dateFormat)
The order of the 3 date sub-components as a 3 byte array using the
constants DAY
, MONTH
and YEAR
once each. The byte order from index 0 to index 2 represents the
left to right ordering of the components. So the leftmost date component
will be defined by the byte at index position 0.
The value set is specific to the current user's context.
dateFormat
- Defines the order of date components for conversion to/from
strings.static character getDateOrder()
The order of the 3 date sub-components is a 3 character string using "M", "D" and "Y" once each. The order from index 0 to index 2 represents the left to right ordering of the components. So the leftmost date component will be defined by the character at index position 0.
The value accessed is specific to the current user's context.
public static void setDateOrder(java.lang.String dateFormat)
The order of the 3 date sub-components as a 3 character string using "M", "D" and "Y" once each. The order from index 0 to index 2 represents the left to right ordering of the components. So the leftmost date component will be defined by the character at index position 0.
The value set is specific to the current user's context.
dateFormat
- Defines the order of date components for conversion to/from strings.static void setDateOrder(character dateFormat)
The order of the 3 date sub-components as a 3 character string using "M", "D" and "Y" once each. The order from index 0 to index 2 represents the left to right ordering of the components. So the leftmost date component will be defined by the character at index position 0.
The value set is specific to the current user's context.
dateFormat
- Defines the order of date components for conversion to/from strings.public static void setTimeZone(NumberType offset)
offset
- The new timezone offset which must be between -840 and 840
inclusive. The value may also be unknown
which
is the equivalent of resetting this attribute to the default.public static void setSessionTimeZone(long offset)
offset
- The new timezone offset which must be between -840 and 840 inclusive.public static void setTimeSource(java.lang.String timeSource)
TIME-SOURCE
attribute for the user's context.
This attribute is can be read and written but it is not honored for
date/time processing in P2J. The intention of the attribute is to define
the system from which time values will be obtained. In P2J, time values
are always obtained from the application server.timeSource
- The new value to set. If null
, then the empty
string will be used, which in the 4GL has the same affect as "local".public static void setTimeSource(character timeSource)
TIME-SOURCE
attribute for the user's context.
This attribute is can be read and written but it is not honored for
date/time processing in P2J. The intention of the attribute is to define
the system from which time values will be obtained. In P2J, time values
are always obtained from the application server.timeSource
- The new value to set. If null
, then the empty
string will be used, which in the 4GL has the same affect as
"local".public static void setDisplayTimeZone(long displayTimezone)
DISPLAY-TIMEZONE
attribute for the user's context.
This attribute is used for displaying DATETIME-TZ values that do not have
the timezone specified in the display format.displayTimezone
- The new value to set.public static void setDisplayTimeZone(NumberType displayTimezone)
DISPLAY-TIMEZONE
attribute for the user's context.
This attribute is used for displaying DATETIME-TZ values that do not have
the timezone specified in the display format.displayTimezone
- The new value to set.public static int windowingImpl(int year)
setWindowingYear(long)
.year
- The year which will be converted to a 4 digit year based on
the starting window year if and only if it is between 0 and
99 inclusive.private static int windowingImpl(int year, int windowingYear)
year
- The year which will be converted to a 4 digit year based on
the starting window year if and only if it is between 0 and
99 inclusive.windowingYear
- The window start year used for conversion.public static int64 secondsSinceMidnight()
public static int64 secondsSinceMidnight(java.util.GregorianCalendar gc)
gc
- The calendar to use for the calculation which includes the time
(in millis since epoch) and timezone. This may be set to any
time value (in the future or present) including the current time.public static int64 elapsed()
public static int64 elapsed(boolean reset)
reset
- true
to reset the base milliseconds counter to the current time.public static int64 elapsed(logical reset)
reset
- true
to reset the base milliseconds counter to the current time.public static date plusDays(date op1, long op2)
days
to the date of the left operand and returns a
new instance representing that date.op1
- The left operand.op2
- The right operand (the number of days to add to the day
number). Note that this can be a negative number to
effectively subtract instead of add.days
different from the
left operand or unknown value
if any input is
unknown value
.public static date plusDays(date op1, double op2)
days
to the date of the left operand and returns a
new instance representing that date.op1
- The left operand.op2
- The right operand (the number of days to add to the day
number). Note that this can be a negative number to
effectively subtract instead of add. As in Progress, the
value is rounded to the nearest integral value before usage.days
different from the
left operand or unknown value
if any input is
unknown value
.public static date plusDays(date op1, NumberType op2)
days
to the date of the left operand and returns a
new instance representing that date.op1
- The left operand.op2
- The right operand (the number of days to add to the day
number). Note that this can be a negative number to
effectively subtract instead of add.days
different from the
left operand or unknown value
if any input is
unknown value
.public static date minusDays(date op1, long op2)
days
from the date which
is the left operand and return a new instance representing that date.
This just uses plusDays(com.goldencode.p2j.util.date, long)
after negating the parameter's sign.op1
- The left operand.op2
- The right operand (the number of days to subtract from the
day number.days
different from the
left operand or unknown value
if any input is
unknown value
.public static date minusDays(date op1, double op2)
days
from the date which
is the left operand and return a new instance representing that date.
This just uses plusDays(com.goldencode.p2j.util.date, long)
after negating the parameter's sign.op1
- The left operand.op2
- The right operand (the number of days to subtract from the
day number. As in Progress, the value is rounded to the
nearest integral value before usage.days
different from the
left operand or unknown value
if any input is
unknown value
.public static date minusDays(date op1, NumberType op2)
days
from the date which
is the left operand and return a new instance representing that date.
This just uses minusDays(com.goldencode.p2j.util.date, long)
.op1
- The left operand.op2
- The right operand (the number of days to subtract from the
day number.days
different from the
left operand or unknown value
if any input is
unknown value
.public static int difference(date op1, date op2)
op1
- The left operand. Must NOT be unknown
.op2
- The right operand (instance to subtract from the left
operand). Must NOT be unknown
.public static integer differenceNum(date op1, date op2)
op1
- The left operand.op2
- The right operand (instance to subtract from the left
operand).unknown value
if
any input is unknown value
.public static integer weekday(date dd)
date
.dd
- The date to query.public static integer day(date dd)
date
.dd
- The date to query.public static integer month(date dd)
date
.dd
- The date to query.public static integer year(date dd)
date
.dd
- The date to query.@Deprecated public static date instantiateUnknownDate()
date
instance that represents the
unknown value
.
This method is deprecated. Use the default constructor instead.
unknown value
.public java.lang.String defaultFormatString()
defaultFormatString
in class BaseDataType
public boolean equals(java.lang.Object o)
This implementation is consistent with hashCode()
.
equals
in class BaseDataType
o
- The instance to compare against.true
if the objects compare equivalently; false
if they do not,
or if the parameter is not a BaseDataType
instance.BaseDataType.equals(java.lang.Object)
public int hashCode()
BaseDataType.equals(java.lang.Object)
.hashCode
in class BaseDataType
public BaseDataType duplicate()
clone()
method but returns an
instance of BaseDataType
and doesn't throw the
CloneNotSupportedException
.duplicate
in class BaseDataType
public BaseDataType instantiateUnknown()
unknown value
.instantiateUnknown
in class BaseDataType
unknown value
.public BaseDataType instantiateDefault()
instantiateDefault
in class BaseDataType
public boolean isUnknown()
unknown value
.isUnknown
in class BaseDataType
true
if this instance is set to the unknown value
.public void setUnknown()
unknown value
flag to
true
.
Warning: a separate call is needed to ensure that the data of this instance is set to the correct value.
setUnknown
in class BaseDataType
public void assign(BaseDataType value)
If the value is not of type date
, the following automatic type
conversion will occur:
This variant is meant to handle the cases of built-in functions and methods in the 4GL which have polymorphic return types (e.g. DYNAMIC-FUNCTION()). This should NOT be used for non-polymorphic assignments.
assign
in class BaseDataType
value
- The instance from which to copy state.public void assign(date value)
value
- The instance from which to copy state.public void assign(Undoable value)
value
- The instance from which to copy state.public void deepAssign(date value)
value
- The instance from which to copy state.public void increment()
public void decrement()
public void setDayNumber(long day)
unknown value
state
for this instance to false
.day
- The number of days since 12/31/-4714.public void setDayNumber(double day)
unknown value
state
for this instance to false
.day
- The number of days since 12/31/-4714.public void setDayNumber(NumberType day)
unknown value
state
for this instance to false
.day
- The number of days since 12/31/-4714.public date maximum(date d)
d
- The instance to compare against.public date minimum(date d)
d
- The instance to compare against.public int compareTo(java.lang.Object obj)
Comparable
interface.
The algorithm will fail to give meaningful results in the case where one tries to sort against other objects that do not represent compatible values.
obj
- The date instance to compare against.obj
.public int getMonth()
public integer getMonthNum()
unknown
if this instance is
unknown
.public int getDay()
unknown
if this instance is
unknown
.public integer getDayNum()
unknown
if this instance
is unknown
.public int getWeekday()
unknown
if this instance is
unknown
.public integer getWeekdayNum()
unknown
if this instance is
unknown
.public int getYear()
public integer getYearNum()
unknown
if this instance is unknown
.public java.util.Date dateValue()
Date
class which will accurately represent the UTC time that corresponds
to the current date in the timezone stored in this instance or
in the default timezone if the stored timezone is null
.
WARNING: since the J2SE Date
class
implicitly encodes locale-specific time information along with date
information, the Date
object returned by this method is
sensitive to the environment in which it is interpreted
downstream. It is imperative therefore, when using the returned
Date
in downstream code, that the timezone of such code
(e.g., a date formatter or Calendar
instance) matches the
timezone stored in this date
instance (if the stored
timezone is null
, the JVM's default timezone should be used
in downstream code). Otherwise, the discrepancy in timezones (including
any Daylight Savings offset) may cause downstream code to interpret the
date information in the returned object incorrectly, typically as one
day earlier than expected.
null
.public java.util.Date dateValue(java.util.TimeZone override)
Date
class which will accurately represent the UTC time that corresponds
to the current date in the timezone passed as a parameter or in the
default timezone if the passed timezone is null
.
WARNING: since the J2SE Date
class
implicitly encodes locale-specific time information along with date
information, the Date
object returned by this method is
sensitive to the environment in which it is interpreted
downstream. It is imperative therefore, when using the returned
Date
in downstream code, that the timezone of such code
(e.g., a date formatter or Calendar
instance) matches the
the override
parameter to this method (if
override
is null
, the JVM's default timezone
should be used in downstream code). Otherwise, the discrepancy in
timezones (including any Daylight Savings offset) may cause downstream
code to interpret the date information in the returned object
incorrectly, typically as one day earlier than expected.
override
- The timezone to use for interpreting this date or
null
if the default JVM timezone should be used.public double doubleValue()
double
.public decimal decimalValue()
integer
.public int intValue()
int
.public integer integerValue()
integer
.public long longValue()
long
.public boolean inY2KWindow()
true
if the year is within the range specified
beginning at the windowing year and ending 99 years later.
By default, the windowing year is 1950 so the ending year
is 2049. Any dates in this range can be specified as
2-digits.public java.lang.String toStringSQL()
The year component is treated differently since it can have a sign (negative indicates BC era) and if the date is within the Y2K window it is truncated to fit.
public java.lang.String toString()
The year component is treated differently since it can have a sign (negative indicates BC era) and if the date is within the Y2K window it is truncated to fit.
toString
in class java.lang.Object
java.lang.IllegalArgumentException
- If the format string passed is invalid.public java.lang.String toStringMessage()
MESSAGE
language statement. If the
instance represents the unknown value
, a '?' will be
returned.toStringMessage
in class BaseDataType
public java.lang.String toStringExport()
This implementation creates the given string based on the order of date components (e.g. MDY, YMD...) defined for this context.
toStringExport
in class BaseDataType
public java.lang.String toString(java.lang.String fmt) throws java.lang.IllegalArgumentException
There are 2 (and only 2) cases where separator characters are not needed: '999999' and '99999999'. Any other format string without separator characters will cause an error to occur.
The year component is treated differently since it can have a sign (negative indicates BC era) and if the date is within the Y2K window it is truncated to fit inside a 9 (if possible without losing data) or 99 format (but not a 999 format).
This implementation creates the given string based on the order of date components (e.g. MDY, YMD...) defined for this context.
toString
in class BaseDataType
fmt
- The Progress style format string to use or null
to use the default '99/99/99'.unknown
an empty string is returned.java.lang.IllegalArgumentException
- If the format string passed is invalid.public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
in
- The input source from which fields will be restored.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
out
- The output destination to which fields will be saved.java.io.IOException
- In case of I/O errors.protected void instantiateFromStringWorker(java.lang.String spec, java.lang.String format, int windowingYear)
date
.
If the spec
string is empty or equals '?', an unknown date object is instantiated.
spec
- The date to parse.format
- The date format used for parsing. If it is null the default is used.windowingYear
- The windowing year used for 2 digits years. If it is negative the default is used.protected long getAbsoluteTimeOffset()
unknown
.protected java.lang.String getIsoDate()
unknown
.public static ErrorManager.ErrorEntry validate(int month, int day, int year, boolean forceFourDigits)
month
- The month.day
- The day.year
- The year.forceFourDigits
- Flag for converting the year to 4 digits before processing.null
if components are valid and error information otherwise.public static character isoDate(date date)
date
- The date to format as text.unknown
.public static integer getOffsetForSpec(character spec)
public static integer getOffsetForSpec(java.lang.String spec)
public static integer getDefaultTimeZoneOffset()
public static int getDefaultOffset()
public static java.util.TimeZone getDefaultTimeZone()
public static java.util.TimeZone getZoneFromOffset(int offset)
offset
- The offset in minutes (positive or negative) from UTC.public static java.lang.String cleanFormattedDate(java.lang.String input)
input
- The text to cleanup.public static void genBadCharInFormatError(int idx, java.lang.String fmt)
idx
- The character position at which the problem was found.fmt
- The format string in which the bad character was found.protected static int specToOffset(java.lang.String spec)
The string cannot be empty and it must start with a sign character.
private static java.lang.String offsetToZoneId(int offset)
TimeZone
instance.offset
- The offset in minutes (positive or negative) from UTC. Must be
between -840 and 840 inclusive.protected static java.util.GregorianCalendar getZoneCalendar(java.util.TimeZone zone)
zone
- The timezone the calendar must support.static integer getTimeZone()
unknown
will be returned.static integer getDisplayTimeZone()
static character getTimeSource()
The default value is "local" which in Progress means that the client machine is the source (this is the same as the empty string ""). It is common to use a database name in the 4GL, which makes the application use the database server as the time source.
private java.lang.String genFailedString(java.lang.String fmt)
fmt
- The format string upon which to pattern the returned result.private void yymmddWorker(int yy, int mm, int dd) throws ErrorConditionException
unknown value
if the calculated
Julian date in invalid.yy
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The year
0 is invalid in Progress but in Java it is equivalent to the
1st year BC. All BC years are offset in J2SE by 1 from the
Progress equivalent. Thus, the value is fixed up to be
J2SE compatible.mm
- The month from 1 to 12 (Progress format) which is then
fixed up to be J2SE compatible before use (0-based).dd
- The day of the specified month between 1 and the largest
possible date (31 or less depending on the month and year).ErrorConditionException
- If the month or day of month are invalid.private void yymmddWorker(int yy, int mm, int dd, boolean forceFourDigits) throws ErrorConditionException
unknown value
if the calculated
Julian date in invalid.yy
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The year
0 is invalid in Progress but in Java it is equivalent to the
1st year BC. All BC years are offset in J2SE by 1 from the
Progress equivalent. Thus, the value is fixed up to be
J2SE compatible.mm
- The month from 1 to 12 (Progress format) which is then
fixed up to be J2SE compatible before use (0-based).dd
- The day of the specified month between 1 and the largest
possible date (31 or less depending on the month and year).forceFourDigits
- If true then 2-digit years will be windowed into the right
century.ErrorConditionException
- If the month or day of month are invalid.private date.WorkArea getWorkArea()
private static int findNextSeparator(java.lang.StringBuilder input, int start)
input
- The text to scan.start
- The starting index for the search. Only characters starting at or
following that index will be considered.private static int trimZeros(java.lang.StringBuilder sb, int start)
sb
- The buffer to edit.start
- The index from which to remove the zeros.private long parseWorker(java.lang.String input, byte[] dateFormat, int windowingYear) throws ErrorConditionException
date(java.lang.String)
.
This implementation parses the given string based on the order of date components (e.g. MDY, YMD...) defined by the second argument.
input
- The formatted string date to convert.dateFormat
- The format used for date conversion.windowingYear
- The year window used when year is represented with 2-digits.ErrorConditionException
private java.lang.String addSeparators(byte[] dateFormat, java.lang.String input)
The rules as they are known:
Input Length YMD Format MDY Format Notes ------------ ---------- ---------- --------------------------------- less than 3 n/a n/a "Invalid date format" error 85 3 MMD MMD 4 MMDD MMDD 5 YYMMD MMDDY 6 YYMMDD MMDDYY 7 YYMMDD MMDDYY the 7th character is dropped 8 YYYYMMDD MMDDYYYY more than 8 YYYYMMDD MMDDYYYY the 9th and following characters are dropped
This method adds '-' separators and only deals with '-' separators.
dateFormat
- Caller provided dateFormat. Must not be null
.input
- Text representation of a date with no separators. Must not
be null
.protected long instantiateDate(int year, int month, int day) throws ErrorConditionException
year
- The Progress 4GL year which may be a negative number which
represents the BC era or a positive AD era year. The value must
be between -32768 and 32767 and it cannot be 0 since the year
0 is invalid in Progress. In Java the year 0 is equivalent to
the 1st year BC (all BC years are offset in J2SE by 1 from the
Progress equivalent). Any valid values are fixed up to be
J2SE compatible.month
- The month from 1 to 12 (Progress format) which is then
fixed up to be J2SE compatible before use (0-based).day
- The day of the specified month between 1 and the largest
possible date (31 or less depending on the month and year).java.lang.IllegalArgumentException
- If the month or day of month are invalid.ErrorConditionException
protected java.lang.String toYearString(int min, int max, boolean force)
min
- Specifies the minimum number of output characters. The result
will be zero padded on the left as necessary. This value
cannot be greater than the 'max' parameter but can be set to
the same value. Must be greater than zero.max
- Specifies the maximum number of output characters. If the
result cannot fit into this number of characters, then
a null
string will be returned. As a special
case, years within the Y2K window will be truncated to
1 (if possible without losing data) or 2 characters if
max is set to these values respectively. All other values
must 'naturally' fit inside the maximum. Must be greater
than zero and larger than the 'min' parameter.force
- Determines whether values within the Y2K window will be
forced to 2 digits on output. This is only used for the
unusual 'export' format.null
if the result is
too large to fit.private static java.util.Date createDate(int yy, int mm, int dd)
GregorianCalendar
and handling the 0-based month processing on behalf of the
caller (the caller uses a 1-based month index).yy
- The year.mm
- The month from 1 - 12.dd
- The day of the month.protected static byte[] initFormat(java.lang.String fmt)
This string encoding of this order will be converted into a byte array
with 3 elements. Each element is one of the DAY
,
MONTH
or YEAR
constants of this class. Each
element may only appear once. The resulting array will be returned and
it defines the order of the components in a date when converted to/from
a string.
The value returned may have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/dateFormat
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/dateFormat
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/dateFormat
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/dateFormat
If no value is found via this lookup, then the Progress 4GL default of MDY will be returned.
fmt
- The explicit date format string to use or null
to read from the directory.private static int initWindowingYear()
The value returned may have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/windowingYear
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/windowingYear
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/windowingYear
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/windowingYear
If no value is found via this lookup, then the Progress 4GL default of 1950 will be returned.
private static integer initTimezoneOffset()
The value returned will have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/timezoneOffset
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/timezoneOffset
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/timezoneOffset
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/timezoneOffset
unknown
if not
set in the directory.private static integer initDisplayTimezone()
SESSION:DISPLAY-TIMEZONE
). This value is context-specific to
the current user's session and it's used to display datetime-tz values whose format
does not include the timezone specifiers.
The value returned will have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/displayTimezone
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/displayTimezone
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/displayTimezone
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/displayTimezone
unknown
if not set in the directory.private static java.lang.String initTimeSource()
The value returned may have been found via a search algorithm that is account (user or process) specific or group specific within the current server or a global default for all servers.
The implementation iteratively looks up the directory node under: /server/<serverID>/runtime/<account_or_group>/timeSource
If no user/process or group nodes are present, then this is checked: /server/<serverID>/runtime/default/timeSource
If no /server/<serverID>/runtime node exists, this is checked (it is the global default area for all servers): /server/default/runtime/<account_or_group>/timeSource
Finally, if no user/process or group nodes are present in the global default area, then this is checked: /server/default/runtime/default/timeSource
If no value is found via this lookup, then the Progress 4GL default of "local" will be returned.
private static void editOrder(byte[] order, int idx, byte type, char comp)
order
- The array which determines the order of date components.idx
- The index position to set.type
- The component to set at the index.comp
- The descriptive character specifying the component.private static void genInvalidDateOrder()
public static void main(java.lang.String[] args)
If parameters are passed, then an alternate mode is used which simply
displays the output of toString(String)
and
toStringExport()
.