Class DateTime

java.lang.Object
net.aifusion.metamodel.DateTime

public class DateTime extends Object
Class to represent a CIM Datetime (Time stamps and intervals)
Author:
Sharad Singhal
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a TimeStamp using the current time
    DateTime(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 value
    Create a TimeStamp from the given calendar dataValue
    DateTime(Date date)
    Create a TimeStamp with the given date as its dataValue
  • Method Summary

    Modifier and Type
    Method
    Description
    add(DateTime interval)
    Add an interval to this time stamp or interval
    compareTo(DateTime otherDateTime)
    Compare two timestamps, or two intervals based on their precision
    divide(double factor)
    Divide this interval by a factor
    boolean
    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 interval
    long
    Get the resolution of this timeStamp (or interval)
    boolean
    isAfter(DateTime prescribedDate)
    check if this timestamp comes after the prescribed timestamp
    boolean
    isBefore(DateTime prescribedDate)
    Check if this timestamp is earlier than the prescribed timestamp
    boolean
    Check if this dateTime dataValue represents an interval
    multiply(double factor)
    Multiply this interval by a factor
    subtract(DateTime durationOrTime)
    Subtract an interval from this time stamp or interval, or a time stamp from this time stamp
    Returns a MOF representation of the DateTime
     

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DateTime

      public DateTime()
      Create a TimeStamp using the current time
    • DateTime

      public DateTime(Date date)
      Create a TimeStamp with the given date as its dataValue
      Parameters:
      date - - date to be used for this dateTime
    • DateTime

      public DateTime(Calendar c)
      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 microseconds
      maxValue - - maximum value of the duration or timestamp in microseconds
      isDuration - - true if this datetime represents a duration, false if this datetime is a timestamp
      Throws:
      ModelException - if minValue < 0, or if maxValue < minValue
    • DateTime

      public DateTime(String s)
      Create a DateTime object from the given string value
      Parameters:
      s - - string vlue containing either a TimeStamp specification or an interval (duration) specification

      The 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 minutes

      It 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 interval

      Values 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

      public Calendar 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

      public boolean isAfter(DateTime prescribedDate)
      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

      public boolean isBefore(DateTime prescribedDate)
      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

      public Integer compareTo(DateTime otherDateTime)
      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 and equals(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

      public DateTime add(DateTime interval)
      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

      public DateTime subtract(DateTime durationOrTime)
      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

      public DateTime multiply(double factor)
      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

      public DateTime divide(double factor)
      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

      public boolean equals(Object o)
      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). Use compareTo(DateTime) to check for equality of underlying values using interval arithmetic.
      Overrides:
      equals in class Object
      Returns:
      true if the given DateTime object is equal to this DateTime object, false otherwise
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toMOF

      public String toMOF()
      Returns a MOF representation of the DateTime
      Returns:
      String - quoted date dataValue to be used as MOF string