uk.ac.starlink.ttools.convert
Class Iso8601Converter

java.lang.Object
  extended by uk.ac.starlink.ttools.convert.Iso8601Converter
All Implemented Interfaces:
ValueConverter
Direct Known Subclasses:
Iso8601ToDecimalYear, Iso8601ToJulian

public abstract class Iso8601Converter
extends Object
implements ValueConverter

Converts between Strings in ISO-8601 format and some kind of numeric date.

Since:
29 Aug 2006
Author:
Mark Taylor

Nested Class Summary
protected static class Iso8601Converter.DateKit
          Helper class which contains all the items which are potentially expensive to produce but cannot be shared by different threads.
 
Constructor Summary
protected Iso8601Converter(ValueInfo isoInfo, ValueInfo numInfo)
          Constructor.
 
Method Summary
 Object convert(Object in)
          Performs a conversion from the input type to the output type.
protected static double dateToMjd(int year, int month, int day, int hour, int min, double sec)
          Converts a calendar date and time to Modified Julian Date.
protected abstract  double fromMjd(double mjd)
          Converts from Modified Julian Date to this converter's public date.
 ValueInfo getInputInfo()
          Returns metadata describing the values on the input end of the conversion.
protected static Iso8601Converter.DateKit getKit()
          Returns a date kit private to the calling thread.
 ValueInfo getOutputInfo()
          Returns metadata describing the values on the output end of the conversion.
static long mjdToUnixMillis(double mjd)
          Converts from modified Julian date to milliseconds since the Unix epoch (1970-01-01T00:00:00).
protected abstract  double toMjd(double number)
          Converts from this converter's public date value to Modified Julian Date.
 Object unconvert(Object out)
          Performs a reverse conversion, from the output type to the input type.
protected static double unixMillisToMjd(long unixMillis)
          Converts from milliseconds since the Unix epoch (1970-01-01T00:00:00) to a modified Julian date value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Iso8601Converter

protected Iso8601Converter(ValueInfo isoInfo,
                           ValueInfo numInfo)
Constructor.

Parameters:
isoInfo - input value metadata (describing ISO-8601 strings)
numInfo - output value metadata (describing numeric date)
Method Detail

getInputInfo

public ValueInfo getInputInfo()
Description copied from interface: ValueConverter
Returns metadata describing the values on the input end of the conversion.

Specified by:
getInputInfo in interface ValueConverter
Returns:
input info

getOutputInfo

public ValueInfo getOutputInfo()
Description copied from interface: ValueConverter
Returns metadata describing the values on the output end of the conversion.

Specified by:
getOutputInfo in interface ValueConverter
Returns:
output info

convert

public Object convert(Object in)
Description copied from interface: ValueConverter
Performs a conversion from the input type to the output type. In general if the conversion cannot be done, a null value should be returned rather than throwing an unchecked exception.

Specified by:
convert in interface ValueConverter
Parameters:
in - object of input type
Returns:
corresponding object of output type

unconvert

public Object unconvert(Object out)
Description copied from interface: ValueConverter
Performs a reverse conversion, from the output type to the input type. In general if the conversion cannot be done, a null value should be returned rather than throwing an unchecked exception.

Specified by:
unconvert in interface ValueConverter
Parameters:
out - object of output type
Returns:
corresponding object of input type

toMjd

protected abstract double toMjd(double number)
Converts from this converter's public date value to Modified Julian Date.

Parameters:
number - date value
Returns:
date as MJD

fromMjd

protected abstract double fromMjd(double mjd)
Converts from Modified Julian Date to this converter's public date.

Parameters:
mjd - date as MJD
Returns:
date value

dateToMjd

protected static double dateToMjd(int year,
                                  int month,
                                  int day,
                                  int hour,
                                  int min,
                                  double sec)
Converts a calendar date and time to Modified Julian Date.

Parameters:
year - year AD
month - index of month; January is 1, December is 12
day - day of month (the first day is 1)
hour - hour (0-23)
min - minute (0-59)
sec - second (0<=sec<60)
Returns:
modified Julian date corresponding to arguments

unixMillisToMjd

protected static double unixMillisToMjd(long unixMillis)
Converts from milliseconds since the Unix epoch (1970-01-01T00:00:00) to a modified Julian date value

Parameters:
unixMillis - milliseconds since the Unix epoch
Returns:
modified Julian date

mjdToUnixMillis

public static long mjdToUnixMillis(double mjd)
Converts from modified Julian date to milliseconds since the Unix epoch (1970-01-01T00:00:00).

Parameters:
mjd - modified Julian date
Returns:
milliseconds since the Unix epoch

getKit

protected static Iso8601Converter.DateKit getKit()
Returns a date kit private to the calling thread.

Returns:
date kit


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.