Class TimeFormat


  • @Equality
    public abstract class TimeFormat
    extends java.lang.Object
    Formats numeric values to strings to provide axis ticks and user-viewable coordinate readouts.
    Since:
    12 Jul 2013
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected TimeFormat​(java.lang.String name, java.lang.String description)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static double decimalYearToUnixSeconds​(double decYear)
      Converts decimal years to unix seconds.
      abstract java.lang.String formatTime​(double unixSec, double secPrecision)
      Formats a time value to a given precision.
      java.lang.String getFormatDescription()
      Returns a short description of this format.
      java.lang.String getFormatName()
      Returns the name of this format.
      static TimeFormat[] getKnownFormats()
      Returns a list of all the known implementations of this class.
      abstract Ticker getTicker()
      Returns an object for generating ticks to label the time axis.
      abstract double parseTime​(java.lang.String timeStr)
      Turns a formatted time string into the equivalent value in unix seconds.
      java.lang.String toString()  
      static double unixSecondsToDecimalYear​(double unixSec)
      Converts unix seconds to decimal year.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ISO8601

        public static final TimeFormat ISO8601
        Time format for ISO-8601 dates.
      • DECIMAL_YEAR

        public static final TimeFormat DECIMAL_YEAR
        Time format for year decimal year.
      • MJD

        public static final TimeFormat MJD
        Time format for Modified Julian Date.
      • UNIX_SECONDS

        public static final TimeFormat UNIX_SECONDS
        Time format for seconds since the Unix epoch.
    • Constructor Detail

      • TimeFormat

        protected TimeFormat​(java.lang.String name,
                             java.lang.String description)
        Constructor.
        Parameters:
        name - format name
        description - short description
    • Method Detail

      • formatTime

        public abstract java.lang.String formatTime​(double unixSec,
                                                    double secPrecision)
        Formats a time value to a given precision.
        Parameters:
        unixSec - time value in unix seconds
        secPrecision - precision of formatted string in seconds
        Returns:
        formatted time value
      • parseTime

        public abstract double parseTime​(java.lang.String timeStr)
        Turns a formatted time string into the equivalent value in unix seconds. This is the inverse of formatTime.
        Parameters:
        timeStr - formatted time value
        Returns:
        time in unix seconds
        Throws:
        java.lang.NumberFormatException - if timeStr cannot be parsed to a time in this format
      • getTicker

        public abstract Ticker getTicker()
        Returns an object for generating ticks to label the time axis.
        Returns:
        tick calculator
      • getFormatName

        public java.lang.String getFormatName()
        Returns the name of this format.
        Returns:
        format name
      • getFormatDescription

        public java.lang.String getFormatDescription()
        Returns a short description of this format.
        Returns:
        format description
      • toString

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

        public static TimeFormat[] getKnownFormats()
        Returns a list of all the known implementations of this class.
        Returns:
        known time formats
      • unixSecondsToDecimalYear

        public static double unixSecondsToDecimalYear​(double unixSec)
        Converts unix seconds to decimal year.
        Parameters:
        unixSec - seconds since the Unix epoch
        Returns:
        years since 0 AD
      • decimalYearToUnixSeconds

        public static double decimalYearToUnixSeconds​(double decYear)
        Converts decimal years to unix seconds.
        Parameters:
        decYear - years since 0 AD
        Returns:
        seconds since the Unix epoch