JEphem site
jephem API
Build classes

tig
Class Dates

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

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

Class containing utility static methods for date manipulation.
Dates are represented as an array of integers.
The internationalization of this class is hard coded (French and English are supported).
This class handles :

  • Date - julian day conversions (dateToJd(), jdToDate()).
  • Conversion between a String and a date (parseDate(), parseHour()).
  • Date formatting for display (formatDate(), formatHour()).

  • Field Summary
     
    Fields inherited from interface tig.GeneralConstants
    BLANK, FS, LS, NO_SPECIF, SPACE
     
    Constructor Summary
    Dates()
               
     
    Method Summary
    static double calcDecDay(int d, int h, int m, int s)
              Returns the decimal part of the day.
    static double dateToJd(int[] date)
              Convenient method equivalent to dateToJd(int, int, int, int, int, int).
    static double dateToJd(int year, int month, int day, int hour, int minut, int sec)
              Calculates the number of julian days elapsed since jan 0.5 4712 BC, from a date and an hour.
    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)
              Facility method, calling parseDate() and formatDate(int[], String).
    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)
              Facility method, calling parseHour() and formatHour(int[], String).
    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)
              Facility method, calling parseHourDate() and formatHourDate(int[], String).
    static boolean isLeapYear(int y)
              Tests if y corresponds to a leap year.
    static int[] jdToDate(double jd)
              Computes the date and hour corresponding to a julian day (nb of days elapsed since jan 0.5 4712 BC).
    static int[] now()
              Returns an array containing date fields (in this order : year, month, day, hour, minuts, seconds) initialized to the current date.
    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

    Dates

    public Dates()
    Method Detail

    dateToJd

    public static double dateToJd(int[] date)
    Convenient method equivalent to dateToJd(int, int, int, int, int, int).


    dateToJd

    public static double dateToJd(int year,
                                  int month,
                                  int day,
                                  int hour,
                                  int minut,
                                  int sec)
    Calculates the number of julian days elapsed since jan 0.5 4712 BC, from a date and an hour.


    jdToDate

    public static int[] jdToDate(double jd)
    Computes the date and hour corresponding to a julian day (nb of days elapsed since jan 0.5 4712 BC).
    From Jean Meeus' Astronomical Algorithms, 2nd edition, p 63.

    Parameters:
    jd - A positive number expressing the julian day.
    Returns:
    An array of six integers containing (in this order) : year, month, day, hour, minut, second.
    Throws:
    java.lang.RuntimeException - If parameter 'jd' < 0.

    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.

    now

    public static int[] now()
    Returns an array containing date fields (in this order : year, month, day, hour, minuts, seconds) initialized to the current date.


    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
    Facility method, calling parseHourDate() and formatHourDate(int[], String).

    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
    Facility method, calling parseDate() and formatDate(int[], String).

    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
    Facility method, calling parseHour() and formatHour(int[], String).

    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
    Build classes