org.epics.pvmanager
Class TimeStamp

java.lang.Object
  extended by org.epics.pvmanager.TimeStamp
All Implemented Interfaces:
java.lang.Comparable

public class TimeStamp
extends java.lang.Object
implements java.lang.Comparable

Represent a time stamp at nanosecond accuracy. The time is internally stored as two values: the UNIX timestamp (number of seconds since 1/1/1970) and the nanoseconds past that timestamp. The UNIX timestamp is stored as a signed long, which has the range of 292 billion years before and another 292 past the epoch.

Note that while TimeStamp are usually created according to system clocks which takes into account leap seconds, all the math operations on TimeStamps do not take leap seconds into account.

Author:
carcassi

Method Summary
 java.util.Date asDate()
          Converts the time stamp to a standard Date.
 int compareTo(java.lang.Object o)
          Defines the natural ordering for timestamp as forward in time.
 TimeDuration durationFrom(TimeStamp reference)
           
static TimeStamp epicsTime(long epicsSec, long nanoSec)
          Returns a new timestamp from EPICS time.
 boolean equals(java.lang.Object obj)
           
 long getEpicsSec()
          Epics time; seconds from midnight 1/1/1990.
 long getNanoSec()
          Nanoseconds within the given second.
 long getSec()
          Unix time; seconds from midnight 1/1/1970.
 int hashCode()
           
 TimeStamp minus(TimeDuration duration)
          Subtracts the given duration to this timestamp and returns the result.
static TimeStamp now()
          Returns a new timestamp for the current instant.
 TimeStamp plus(TimeDuration duration)
          Adds the given duration to this timestamp and returns the result.
static TimeStamp time(long unixSec, long nanoSec)
          Returns a new timestamp from UNIX time.
static TimeStamp timestampOf(java.util.Date date)
          Converts a Date to a timestamp.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getEpicsSec

public long getEpicsSec()
Epics time; seconds from midnight 1/1/1990.

Returns:
epics time

getSec

public long getSec()
Unix time; seconds from midnight 1/1/1970.

Returns:
unix time

getNanoSec

public long getNanoSec()
Nanoseconds within the given second.

Returns:
nanoseconds (0 < nanoSec < 999,999,999)

epicsTime

public static TimeStamp epicsTime(long epicsSec,
                                  long nanoSec)
Returns a new timestamp from EPICS time.

Parameters:
epicsSec - number of second in EPICS time
nanoSec - nanoseconds from the given second (must be 0 < nanoSec < 999,999,999)
Returns:
a new timestamp

time

public static TimeStamp time(long unixSec,
                             long nanoSec)
Returns a new timestamp from UNIX time.

Parameters:
unixSec - number of seconds in the UNIX epoch.
nanoSec - nanoseconds past the given seconds (must be 0 < nanoSec < 999,999,999)
Returns:
a new timestamp

timestampOf

public static TimeStamp timestampOf(java.util.Date date)
Converts a Date to a timestamp. Date is accurate to milliseconds, so the last 6 digits are always going to be zeros.

Parameters:
date - the date to convert
Returns:
a new timestamp

now

public static TimeStamp now()
Returns a new timestamp for the current instant. The timestamp is calculated using System.nanoTime(), so it has the accuracy given by that function.

Returns:
a new timestamp

asDate

public java.util.Date asDate()
Converts the time stamp to a standard Date. The conversion is done once, and it trims all precision below milliSec.

Returns:
a date

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Defines the natural ordering for timestamp as forward in time.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - another object
Returns:
comparison result

plus

public TimeStamp plus(TimeDuration duration)
Adds the given duration to this timestamp and returns the result.

Parameters:
duration - a time duration
Returns:
a new timestamp

minus

public TimeStamp minus(TimeDuration duration)
Subtracts the given duration to this timestamp and returns the result.

Parameters:
duration - a time duration
Returns:
a new timestamp

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

durationFrom

public TimeDuration durationFrom(TimeStamp reference)


Copyright © 2010. All Rights Reserved.