JEphem site
jephem API

tig
Class Time

java.lang.Object
  |
  +--tig.Time
All Implemented Interfaces:
GeneralConstants

public abstract class Time
extends java.lang.Object
implements GeneralConstants

Class containing utility static methods for date manipulation.
The manipulation of dates is based on the use of 'julian days'.
The internationalization of this class is hard coded. The reason is that parseDate and formatHourDate methods are locale dependant and must be modified if new languages are added.
Internationalized error messages have been hard coded to keep this class independant from properties files.


Field Summary
 
Fields inherited from interface tig.GeneralConstants
BLANK, FS, LS, NO_SPECIF
 
Constructor Summary
Time()
           
 
Method Summary
static double calcDecDay(int d, int h, int m, int s)
          Returns the decimal part of the day.
static java.lang.String formatDate(int[] date, java.lang.String lang)
          Formats a date into a displayable String.
static java.lang.String formatDate(java.lang.String strDate, java.lang.String lang)
          Formats a date the same way formatDate(int[], String) does.
static java.lang.String formatHour(int[] hour, java.lang.String lang)
          Formats an hour into a displayable String.
static java.lang.String formatHour(java.lang.String strHour, java.lang.String lang)
          Formats a date the same way formatHour(int[], String) does.
static java.lang.String formatHourDate(int[] hourDate, java.lang.String lang)
          Formats a date and an hour into a displayable String.
static java.lang.String formatHourDate(java.lang.String strDate, java.lang.String strHour, java.lang.String lang)
          Formats a date the same way formatHourDate(int[], String) does.
static boolean isLeapYear(int y)
          Tests if y corresponds to a leap year.
static int[] parseDate(java.lang.String strDate, java.lang.String lang)
          Transforms a date representated as a String to an array of integers containing the year, month, day.
static int[] parseHour(java.lang.String strHour, java.lang.String lang)
          Transforms an hour representated as a String to an array of integers containing (in this order : hours, minutes, seconds.
static int[] parseHourDate(java.lang.String strDate, java.lang.String strHour, java.lang.String lang)
          Transforms a date and an hour representated as Strings to an array of integers containing (in this order : years, months, days, hours, minutes, seconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Time

public Time()
Method Detail

isLeapYear

public static boolean isLeapYear(int y)
Tests if y corresponds to a leap year.

Parameters:
y - positive number representing the year to test.
Returns:
true if y is positive and corresponds to a leap year.

formatHourDate

public static java.lang.String formatHourDate(int[] hourDate,
                                              java.lang.String lang)
Formats a date and an hour into a displayable String.

Parameters:
hourDate - An array containing integers representing : year, month, day, hour, minut, second.
lang - language code, as specified by ISO-639 norm (supported languages : "en" and "fr").
Returns:
if lang='fr', format is "JJ/MM/AAAA HH:MM:SS" ;
if lang='en', format is "MM/JJ/AAAA HH:MM:SS".
Throws:
java.lang.IllegalArgumentException - if :
  • the length of 'hourDate' is different from 6 ;
  • the language is different from "en" or "fr".

  • formatDate

    public static java.lang.String formatDate(int[] date,
                                              java.lang.String lang)
    Formats a date into a displayable String.

    Parameters:
    date - An array containing 3 integers representing : year, month, day.
    lang - language code, as specified by ISO-639 norm (supported languages : "en" and "fr").
    Returns:
    if lang='fr', format is "JJ/MM/AAAA" ;
    if lang='en', format is "MM/JJ/AAAA".
    Throws:
    java.lang.IllegalArgumentException - if :
  • the length of 'date' is different from 3 ;
  • the language is different from "en" or "fr".

  • formatHour

    public static java.lang.String formatHour(int[] hour,
                                              java.lang.String lang)
    Formats an hour into a displayable String.

    Parameters:
    hour - An array containing 3 integers representing : hour, minut, second.
    Returns:
    A String formatted "HH:MM:SS", for lang='fr' or 'en';
    Throws:
    java.lang.IllegalArgumentException - if :
  • the length of 'hour' is different from 3 ;
  • the language is different from "en" or "fr".

  • formatHourDate

    public static java.lang.String formatHourDate(java.lang.String strDate,
                                                  java.lang.String strHour,
                                                  java.lang.String lang)
                                           throws DateFormatException,
                                                  HourFormatException
    Formats a date the same way formatHourDate(int[], String) does.

    Throws:
    DateFormatException - if parameter 'strDate' is not correct.
    HourFormatException - if parameter 'strHour' is not correct.

    formatDate

    public static java.lang.String formatDate(java.lang.String strDate,
                                              java.lang.String lang)
                                       throws DateFormatException
    Formats a date the same way formatDate(int[], String) does.

    Throws:
    DateFormatException - if parameter 'strDate' is not correct.

    formatHour

    public static java.lang.String formatHour(java.lang.String strHour,
                                              java.lang.String lang)
                                       throws HourFormatException
    Formats a date the same way formatHour(int[], String) does.

    Throws:
    HourFormatException - if parameter 'strHour' is not correct.

    parseHourDate

    public static int[] parseHourDate(java.lang.String strDate,
                                      java.lang.String strHour,
                                      java.lang.String lang)
                               throws DateFormatException,
                                      HourFormatException,
                                      java.lang.IllegalArgumentException
    Transforms a date and an hour representated as Strings to an array of integers containing (in this order : years, months, days, hours, minutes, seconds.
    This method just calls parseHour(String, String) and parseDate(String, String). See their documentation for informations about parameter formats and exception thrown.

    DateFormatException
    HourFormatException
    java.lang.IllegalArgumentException

    parseDate

    public static int[] parseDate(java.lang.String strDate,
                                  java.lang.String lang)
                           throws DateFormatException,
                                  java.lang.IllegalArgumentException
    Transforms a date representated as a String to an array of integers containing the year, month, day.
    How to express the date in 'strDate' :
  • Years, months and days must be separated by any non-numeric separator.
  • Years, months and days can be expressed with any number of digits ; years can be preceeded by a minus sign (if you want to express a negative year, first put a separator, and then the '-').
  • For English ('lang' = "en"), the order in 'strDate' must be months, days, years.
  • For French ('lang' = "fr"), the order in 'strDate' must be days, months, years.


  • Example of valid inputs and results.
    French :
    strDateyearsmonthsdays
    18/07/1998 18 7 1998
    18.007:1998 18 7 1998
    9-10 2000 9 10 2000
    9 10 1 9 10 1
    9 10 -16 9 10 -16
    9-10--16 9 10 -16
    9-10-16 9 10 16

    English :
    strDateyearMonthDay
    07/18/1998 18 7 1998
    007:18.1998 18 7 1998
    9-10 2000 10 9 2000
    9 10 1 9 10 1
    9 10 -16 10 9 -16
    9-10--16 10 9 -16
    9-10-16 10 9 16

    Parameters:
    strDate - A String containing the date, as specified above.
    lang - language code, as specified by ISO-639 norm (supported languages : "en" and "fr").
    Returns:
    an array of integers in which are stored (in this order) years, months, days.
    Throws:
    java.lang.IllegalArgumentException - if parameter 'lang' is different from 'en' or 'fr'.
    DateFormatException - if parameter 'strDate' is not correctly formatted.

    parseHour

    public static int[] parseHour(java.lang.String strHour,
                                  java.lang.String lang)
                           throws HourFormatException,
                                  java.lang.IllegalArgumentException
    Transforms an hour representated as a String to an array of integers containing (in this order : hours, minutes, seconds.
    Parameter 'lang' has no effect.
    How to express the hour in 'strHour' :
  • Hours, minuts and seconds must be separated by any non-numeric character
  • Any non-numeric digit at the beginning or at the end of 'strHour" are skipped
  • If 'strHour' is empty, hours, minuts, seconds will be considered as equal to 0.
  • Seconds or {minutes and seconds} can be omitted, they will be considered as equal to 0.


  • Example of valid inputs and results.
    strHourhoursminutsseconds
    (empty string) 0 0 0
    12 12 0 0
    12h30m 12 30 0
    -12:30:40s 12 30 40
    000012h000030m00040 12 30 40

    Parameters:
    strHour - A String containing the hour, as specified above..
    lang - language code, as specified by ISO-639 norm (supported languages : 'en' and 'fr').
    Returns:
    an array of integers in which are stored (in this order) hours, minuts, seconds.
    Throws:
    HourFormatException - if parameter 'strHour' is not correctly formatted.
    java.lang.IllegalArgumentException - if parameter 'lang' is different from 'en' or 'fr'.

    calcDecDay

    public static double calcDecDay(int d,
                                    int h,
                                    int m,
                                    int s)
    Returns the decimal part of the day. The decimal part of the day expresses the fraction within the day.
    ex : 23.75 means 23rd, 18h00m00s.


    JEphem site
    jephem API