Class DateTime
- Author:
- Sharad Singhal
-
Constructor Summary
ConstructorDescriptionDateTime()
Create a TimeStamp using the current timeDateTime
(long duration) Create a duration (CIM Interval) with the given length, i.e., interval is [duration,duration+1)DateTime
(long minValue, long maxValue, boolean isDuration) Create a duration or TimeStamp with the given precision.Create a DateTime object from the given string valueCreate a TimeStamp from the given calendar dataValueCreate a TimeStamp with the given date as its dataValue -
Method Summary
Modifier and TypeMethodDescriptionAdd an interval to this time stamp or intervalCompare two timestamps, or two intervals based on their precisiondivide
(double factor) Divide this interval by a factorboolean
Check if this DateTime object is equal to another DateTime object
Note that this method compares the java objects by comparing that the underlying dateTime representations are identical, i.e., have identical bounds and precision.Get a calendar dataValue containing this time stamp dataValue.long
Get the lowerbound (in musec) for this date or intervallong
Get the resolution of this timeStamp (or interval)boolean
check if this timestamp comes after the prescribed timestampboolean
Check if this timestamp is earlier than the prescribed timestampboolean
Check if this dateTime dataValue represents an intervalmultiply
(double factor) Multiply this interval by a factorSubtract an interval from this time stamp or interval, or a time stamp from this time stamptoMOF()
Returns a MOF representation of the DateTimetoString()
-
Constructor Details
-
DateTime
public DateTime()Create a TimeStamp using the current time -
DateTime
Create a TimeStamp with the given date as its dataValue- Parameters:
date
- - date to be used for this dateTime
-
DateTime
Create a TimeStamp from the given calendar dataValue- Parameters:
c
- - calendar dataValue representing the dataValue
-
DateTime
public DateTime(long duration) Create a duration (CIM Interval) with the given length, i.e., interval is [duration,duration+1)- Parameters:
duration
- - duration in microseconds- Throws:
ModelException
- if duration is negative
-
DateTime
public DateTime(long minValue, long maxValue, boolean isDuration) Create a duration or TimeStamp with the given precision. It is assumed that the timestamp or duration lies within the closed interval [minValue,maxValue] microseconds- Parameters:
minValue
- - minimum value of the duration or timestamp in microsecondsmaxValue
- - maximum value of the duration or timestamp in microsecondsisDuration
- - true if this datetime represents a duration, false if this datetime is a timestamp- Throws:
ModelException
- if minValue < 0, or if maxValue < minValue
-
DateTime
Create a DateTime object from the given string value- Parameters:
s
- - string vlue containing either a TimeStamp specification or an interval (duration) specificationThe dateValue can be a timestamp represented in 25 characters formatted as
yyyyMMddhhmmss.mmmmmmsutc
where yyyy - years, MM - months (1-12), dd - day (1-31), hh - hours (0 - 23), mm - minutes (0 - 59), ss - seconds (0-59), mmmmmm - microseconds within the second (starting with 0)
s is a sign (+ or -) indicating offset from UTC with + meaning east of UTC, and - meaning west of UTC
utc is the offset from utc expressed in minutesIt can also be an interval represented as
ddddddddhhmmss.mmmmmm:000
here dddd... represents days, hh hours, mm minutes, ss seconds, and mmmmmm is microseconds within the Interval. The UTC offset is always 000, and : represents an intervalValues are left-padded, so that the string is always 25 characters long. If the resolution of the measurement is greater than one microsecond, the corresponding fields are represented by '*', starting from the lowest digit. The measurement granularity is always the entire field, except the microsecond field, where the granularity is single digits.
-
-
Method Details
-
isInterval
public boolean isInterval()Check if this dateTime dataValue represents an interval- Returns:
- - true if the dataValue is an interval, false if it is a timestamp
-
getCalendar
Get a calendar dataValue containing this time stamp dataValue. Note that the microsecond dataValue, if any, is truncated in the returned calendar- Returns:
- - calendar containing the timestamp dataValue
- Throws:
ModelException
- if this DateTime dataValue is an interval
-
isAfter
check if this timestamp comes after the prescribed timestamp- Parameters:
prescribedDate
- - timestamp for comparison- Returns:
- - true if the given timestamp is later than this timestamp. False if the given timestamp is before this timestamp, or if the difference in timestamps is smaller than the resolution of the timestamps
-
isBefore
Check if this timestamp is earlier than the prescribed timestamp- Parameters:
prescribedDate
- - timestamp for comparison- Returns:
- - true if the given timestamp is before than this timestamp. False if the given timestamp is after this timestamp, or if the difference in timestamps is smaller than the resolution of the timestamps
-
compareTo
Compare two timestamps, or two intervals based on their precision- Parameters:
otherDateTime
- - interval or timestamp to compare- Returns:
- - returns an integer {< 0, 0, or >0} if this dataValue is {<, = or >} the other dataValue. If
the answer cannot be determined given the precision in the values, a null dataValue is returned
Note: Since calendar values are precise only to 1 ms, compareTo() may return null, even if the calendar values are identical in the two dateTime values andequals(Object)
returns true. - Throws:
ModelException
- if an interval is compared to a timestamp or vice versa
-
getResolution
public long getResolution()Get the resolution of this timeStamp (or interval)- Returns:
- - resolution of the timestamp or interval in microseconds
-
getLowerBound
public long getLowerBound()Get the lowerbound (in musec) for this date or interval- Returns:
- - lower bound for this date or interval
-
add
Add an interval to this time stamp or interval- Parameters:
interval
- - interval to be added- Returns:
- - DateTime value with the interval added to this time stamp or interval
- Throws:
ModelException
- if a time stamp is added to a timestamp
-
subtract
Subtract an interval from this time stamp or interval, or a time stamp from this time stamp- Parameters:
durationOrTime
- - interval / timestamp to be subtracted- Returns:
- - DateTime value with the interval or time stamp representing the difference
- Throws:
ModelException
- if a time stamp is subtracted from a time stamp
-
multiply
Multiply this interval by a factor- Parameters:
factor
- - factor to use for multiplication- Returns:
- - DateTime with scaled interval in it
- Throws:
ModelException
- if this DateTime does not represent an interval- See Also:
-
divide
Divide this interval by a factor- Parameters:
factor
- - factor to use for division- Returns:
- - DateTime with scaled interval in it
- Throws:
ModelException
- if this DateTime does not represent an interval- See Also:
-
equals
Check if this DateTime object is equal to another DateTime object
Note that this method compares the java objects by comparing that the underlying dateTime representations are identical, i.e., have identical bounds and precision. However, for dateTime values with greater than 1 microsecond precision, this does not imply that the underlying dateTime values are equal (it may not be possible to decide equality for the given precision). UsecompareTo(DateTime)
to check for equality of underlying values using interval arithmetic. -
toString
-
toMOF
Returns a MOF representation of the DateTime- Returns:
- String - quoted date dataValue to be used as MOF string
-