Class EpochRelativeTime

java.lang.Object
gov.nasa.jpl.time.Time
gov.nasa.jpl.time.EpochRelativeTime
All Implemented Interfaces:
ConvertableFromString, Comparable<Time>

public class EpochRelativeTime extends Time
This class represents epoch-relative times and inherits from the Time class in the same package in order to inter-operate with it as smoothly as possible. In addition to the number of tics from the absolute base class, this gets two new fields: a string epoch name and a Duration offset from that epoch. The toString() method is overwritten to preserve those quantities in file outputs, but all other output methods are not, since one needs an absolute times to do comparisons or geometric calculations.
  • Field Details

    • EPOCH_RELATIVE_TIME_REGEX

      public static String EPOCH_RELATIVE_TIME_REGEX
    • EPOCH_RELATIVE_PATTERN

      public static final Pattern EPOCH_RELATIVE_PATTERN
  • Constructor Details

    • EpochRelativeTime

      public EpochRelativeTime()
      Empty constructor, for use by programs that have to create a blank instance then call valueOf()
    • EpochRelativeTime

      public EpochRelativeTime(String epochPlusOffset)
      Most likely standard constructor that takes a single string and mutates the called object to represent it. The epoch name must already be defined in the EpochRelativeTime class before the constructor is called.
      Parameters:
      epochPlusOffset - A string containing an epoch name plus an offset like 'LAUNCH+00:05:00' or 'TEST_EPOCH - 1T00:00:00.000'
    • EpochRelativeTime

      public EpochRelativeTime(String epochName, Duration offset)
      Constructor that takes an epoch string name and a Duration object
      Parameters:
      epochName - epoch name, must already be in epochs map at time of instantiation
      offset - Duration object
    • EpochRelativeTime

      public EpochRelativeTime(Time absoluteTime, String epochName)
      Constructor that takes an absolute time and an epoch string and creates an equivalent epoch-relative time relative to the input epoch-string - calculates the offset
      Parameters:
      absoluteTime - The output time will have the same tics (evaluated time) as this parameter
      epochName - The epoch name the output time will be relative to
  • Method Details

    • setEpochs

      public static void setEpochs(Map<String,Time> epochs)
      Sets a new epochs map for all new EpochRelativeTimes (does not change already existing ones)
      Parameters:
      epochs - Map that new EpochRelativeTimes will look up their string in
    • getEpochs

      public static Map<String,Time> getEpochs()
      Returns the map of epochs to times.
      Returns:
    • addEpoch

      public static void addEpoch(String epochName, Time toInsert)
      Adds a new epoch name, time pair to existing epoch map
      Parameters:
      epochName - Name of epoch, cannot contain spaces
      toInsert - Absolute time
    • removeEpoch

      public static void removeEpoch(String epochName)
      Removes epoch from map of times that new EpochRelativeTimes can look up string names in
      Parameters:
      epochName -
    • isEpochDefined

      public static boolean isEpochDefined(String epochName)
      Wraps .containsKey() for epoch map
      Parameters:
      epochName -
      Returns:
    • getAbsoluteOrRelativeTime

      public static Time getAbsoluteOrRelativeTime(String timeString)
      Returns an absolute time if the string can be interpreted as one, or an epoch-relative time if it cannot
      Parameters:
      timeString - the time string that should be turned into a Time object
      Returns:
      either an absolute or epoch-relative corresponding Time object
    • readEpochCVF

      public static void readEpochCVF(String epochFileName) throws IOException
      Reads all epochs defined in CVF and adds them to epoch map
      Throws:
      IOException
    • writeEpochCVF

      public static void writeEpochCVF(String epochFileName) throws IOException
      Writes out all epochs defined in memory to file with default header in time order
      Parameters:
      epochFileName - file name to write to
      Throws:
      IOException
    • writeEpochCVF

      public static void writeEpochCVF(String epochFileName, Collection<String> epochNamesToWriteOut) throws IOException
      Writes out epochs included in epochNamesToWriteOut to epochFileName with default header in time order
      Parameters:
      epochFileName -
      epochNamesToWriteOut -
      Throws:
      IOException
    • writeEpochCVF

      public static void writeEpochCVF(String epochFileName, Collection<String> epochNamesToWriteOut, String header) throws IOException
      Writes out epochs included in epochNamesToWriteOut to epochFileName with header provided in time order
      Parameters:
      epochFileName -
      epochNamesToWriteOut -
      header -
      Throws:
      IOException
    • writeEpochCVF

      public static void writeEpochCVF(String epochFileName, Collection<String> epochNamesToWriteOut, String header, boolean sortByTime) throws IOException
      Writes out epochs included in epochNamesToWriteOut to epochFileName with header provided sorted in time order if sortByTime is true, or alphanumeric by name if sortByTime is false
      Parameters:
      epochFileName -
      epochNamesToWriteOut -
      header -
      sortByTime -
      Throws:
      IOException
    • valueOf

      public void valueOf(String epochPlusOffset)
      Mutates the called object such that its tic count, epoch base, and offset are correct according to the input String Epoch name must already be defined before this method is called. This is the main way that epoch relative times are read in from files or input fields.
      Specified by:
      valueOf in interface ConvertableFromString
      Overrides:
      valueOf in class Time
      Parameters:
      epochPlusOffset -
    • toString

      public String toString()
      Overrides Time's toString and calls more detailed toString(int) with Duration's default output precision
      Overrides:
      toString in class Time
      Returns:
    • toString

      public String toString(int precision)
      Instead of writing out some conversion of the tic value like for absolute time, writes out epoch base and offset in a way that can be read back in as relative later
      Parameters:
      precision - Number of decimal places that are desired to be written
      Returns:
    • add

      public EpochRelativeTime add(Duration d)
      Adding a duration to an epoch-relative time creates another epoch-relative time with the same base but summed durations
      Overrides:
      add in class Time
      Parameters:
      d -
      Returns:
    • plus

      public EpochRelativeTime plus(Duration d)
      Wraps add()
      Overrides:
      plus in class Time
      Parameters:
      d -
      Returns:
    • subtract

      public EpochRelativeTime subtract(Duration d)
      Subtracting a duration from an epoch-relative time creates another epoch-relative time with the same base but subtracted durations
      Overrides:
      subtract in class Time
      Parameters:
      d -
      Returns:
    • minus

      public EpochRelativeTime minus(Duration d)
      Wraps subtract()
      Overrides:
      minus in class Time
      Parameters:
      d -
      Returns: