com.metsci.glimpse.util.units.time.format
Class TimeStampFormatStandard

java.lang.Object
  extended by com.metsci.glimpse.util.units.time.format.TimeStampFormatStandard
All Implemented Interfaces:
TimeStampFormat, java.lang.Cloneable

public class TimeStampFormatStandard
extends java.lang.Object
implements TimeStampFormat

Formats and parses TimeStamps according to a specified format string, in the spirit of trusty old printf. This is similar to java.text.SimpleDateFormat, but with a few improvements:

A good basic example is TimeStampFormat.iso8601: Any characters not inside a format term -- such as the "T", "Z", dashes, and colons in the above example -- will simply show up in as literals in the output string. Just like printf. So if you want date and time separated by a space, and "UTC" instead of "Z": To make text fields all uppercase or all lowercase, use ^ or /: To abbreviate the text month, use 3: To change padding of numeric fields, use <, >, or !: Specify the number of decimal places used by %S with a digit: Other features that would be nice:

Rollover and the %S Field

The %S field is special: its precision affects when other fields (potentially all of them) roll over to the next value. For instance, if a time formatted with a %S gives the string "1999/12/31 23:59:59.999", then it will give "2000/01/01 00:00:00" when formatted with %0S. Note that the value of every field changed, solely because of a change in the precision of the %S field.

If a format string does not contain a %S field, other fields will behave as though there were a full-precision %S. For instance:

If, for some strange reason, a format string contains multiple %S fields, the precision of the rightmost one is used for figuring rollover.


Field Summary
 
Fields inherited from interface com.metsci.glimpse.util.units.time.format.TimeStampFormat
iso8601
 
Constructor Summary
TimeStampFormatStandard(java.lang.String format, java.lang.String timeZoneName)
           
TimeStampFormatStandard(java.lang.String format, java.util.TimeZone timeZone)
           
 
Method Summary
 java.lang.String format(java.math.BigDecimal posixSeconds)
           
 com.metsci.glimpse.util.units.time.format.TimeStampFormatStandard.Field newField(char code, java.lang.String flags)
           
 java.math.BigDecimal parse(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeStampFormatStandard

public TimeStampFormatStandard(java.lang.String format,
                               java.lang.String timeZoneName)

TimeStampFormatStandard

public TimeStampFormatStandard(java.lang.String format,
                               java.util.TimeZone timeZone)
Method Detail

newField

public com.metsci.glimpse.util.units.time.format.TimeStampFormatStandard.Field newField(char code,
                                                                                        java.lang.String flags)

parse

public java.math.BigDecimal parse(java.lang.String string)
Specified by:
parse in interface TimeStampFormat
Returns:
seconds since the epoch

format

public java.lang.String format(java.math.BigDecimal posixSeconds)
Specified by:
format in interface TimeStampFormat
Returns:
a date-time string, formatted according to this format


Copyright © 2012 Metron, Inc.. All Rights Reserved.