Class Currently


  • public class Currently
    extends java.lang.Object
    Create a common interface to handle obtaining string timestamps. The difficult part is to allow for an ISO 8601 date formatting.
    Version:
    $Revision$
    Author:
    Jens-S. Vöckler, Yong Zhao
    See Also:
    Date, SimpleDateFormat
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] c_expression
      Store the regular expressions necessary to parse ISO timestamps.
      private static java.util.regex.Pattern[] c_pattern
      Stores compiled patterns at first use, quasi-Singleton.
      static java.lang.String DEFAULT_FORMAT
      Default time format, which is compact and has a timezone
      private java.text.SimpleDateFormat m_formatter
      This is used to format the time stamp.
    • Constructor Summary

      Constructors 
      Constructor Description
      Currently()
      Default ctor: Create a new instance with a default formatting string for timestamps.
      Currently​(java.lang.String formatString)
      Ctor: Create a new instance with a formatting string for time stamps.
      Currently​(java.text.SimpleDateFormat format)
      Ctor: Create a new instance with a formatting string for time stamps.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.text.SimpleDateFormat getDateFormat()
      Accessor: Obtains the default timestamp format for all queues.
      static java.lang.String iso8601​(boolean zuluTime)
      Ignores any internal date format, and tries to show a complete date/timp stamp of the current time in extended ISO 8601 format.
      static java.lang.String iso8601​(boolean zuluTime, boolean extendedFormat, boolean withMillis, java.util.Date now)
      Ignores any internal date format, and tries to show a complete date/timp stamp in extended ISO 8601 format.
      java.lang.String now()
      Obtains the current time as formatted string according to the format option.
      java.lang.String now​(java.util.Date then)
      Obtains the current time as formatted string according to the format option.
      static java.util.Date parse​(java.lang.String stamp)
      Parses one of the ISO 8601 that it produces.
      void setDateFormat​(java.lang.String format)
      Accessor: Sets the default timestamp format for all queues.
      void setDateFormat​(java.text.SimpleDateFormat format)
      Accessor: Sets the default timestamp format for all queues.
      • Methods inherited from class java.lang.Object

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

      • m_formatter

        private java.text.SimpleDateFormat m_formatter
        This is used to format the time stamp.
      • DEFAULT_FORMAT

        public static final java.lang.String DEFAULT_FORMAT
        Default time format, which is compact and has a timezone
        See Also:
        Constant Field Values
      • c_expression

        private static final java.lang.String[] c_expression
        Store the regular expressions necessary to parse ISO timestamps.
      • c_pattern

        private static java.util.regex.Pattern[] c_pattern
        Stores compiled patterns at first use, quasi-Singleton.
    • Constructor Detail

      • Currently

        public Currently()
        Default ctor: Create a new instance with a default formatting string for timestamps.
      • Currently

        public Currently​(java.lang.String formatString)
        Ctor: Create a new instance with a formatting string for time stamps.
        Parameters:
        formatString - complies to SimpleDateFormat.
      • Currently

        public Currently​(java.text.SimpleDateFormat format)
        Ctor: Create a new instance with a formatting string for time stamps.
        Parameters:
        format - is a description of the simple date format to use.
    • Method Detail

      • setDateFormat

        public void setDateFormat​(java.text.SimpleDateFormat format)
        Accessor: Sets the default timestamp format for all queues.
        Parameters:
        format - is the new timestamp prefix format.
        See Also:
        setDateFormat( SimpleDateFormat ), getDateFormat()
      • setDateFormat

        public void setDateFormat​(java.lang.String format)
        Accessor: Sets the default timestamp format for all queues.
        Parameters:
        format - is the new timestamp prefix format as a string.
        See Also:
        setDateFormat( String ), getDateFormat()
      • now

        public java.lang.String now()
        Obtains the current time as formatted string according to the format option.
        Returns:
        the current time as formatted string.
        See Also:
        now( Date )
      • now

        public java.lang.String now​(java.util.Date then)
        Obtains the current time as formatted string according to the format option.
        Parameters:
        then - is a timestamp expressed as Date.
        Returns:
        the current time as formatted string.
        See Also:
        now()
      • parse

        public static java.util.Date parse​(java.lang.String stamp)
        Parses one of the ISO 8601 that it produces. Note, it will not parse the full range of ISO timestamps.
        Parameters:
        stamp - is the textual timestamp representation.
        Returns:
        a time or null, if unparsable.
      • iso8601

        public static java.lang.String iso8601​(boolean zuluTime)
        Ignores any internal date format, and tries to show a complete date/timp stamp of the current time in extended ISO 8601 format. UTC time (Zulu time) or a local timezone will be used. A sample for UTC output is 2002-04-23T02:49:58Z A sample for local zone (CDT) is 2002-04-22T21:49:58-05:00
        Parameters:
        zuluTime - returns a UTC formatted stamp, if true. Otherwise the time will be formatted according to the local zone.
        Returns:
        an ISO 8601 formatted date and time representation for the current time in extended format without millisecond resolution
        See Also:
        iso8601( boolean, boolean, boolean, Date )
      • iso8601

        public static java.lang.String iso8601​(boolean zuluTime,
                                               boolean extendedFormat,
                                               boolean withMillis,
                                               java.util.Date now)
        Ignores any internal date format, and tries to show a complete date/timp stamp in extended ISO 8601 format. UTC time (Zulu time) or a local timezone will be used.

        zoneformatfractionexample
        localbasicintegral20020523T140427-0500
        UTCbasicintegral20020523190427Z
        localextd.integral2002-05-23T14:04:27-05:00
        UTCextd.integral2002-05-23T19:04:27Z
        localbasicmillis20020523T140427.166-0500
        UTCbasicmillis20020523190427.166Z
        localextd.millis2002-05-23T14:04:27.166-05:00
        UTCextd.millis2002-05-23T19:04:27.166Z

        Parameters:
        zuluTime - returns a UTC formatted stamp, if true. Otherwise the time will be formatted according to the local zone. Local time should be prefixed with the 'T'.
        extendedFormat - will use the extended ISO 8601 format which separates the different timestamp items. If false, the basic format will be used. In UTC and basic format, the 'T' separator will be omitted.
        withMillis - will put the millisecond extension into the timestamp. If false, the time will be without millisecond fraction. The separator is taken from DecimalFormatSymbols.getMinusSign(), which usually is a period or a comma.
        now - is a time stamp as Date.
        Returns:
        an ISO 8601 formatted date and time representation for the given point in time.