Documentation of 'com.mhuss.AstroLib.DateOps' Java class
DateOps
com.mhuss.AstroLib

Class DateOps



  • public class DateOps
    extends java.lang.Object
    A class to perform calendrical conversions.

    Note that the Julian Day Number (JD), widely used in astronomical calculations, is different from and not directly related to the Julian Calendar discussed below.

    Based on code by Bill Gray (www.projectpluto.com)

    Bill Gray's Comments:
    General calendrical comments:

    This code supports conversions between JD and two calendrical systems: Julian and Gregorian. Comments pertaining to specific calendars are found near the code for those calendars.

    [mhuss: The original C code, which these comments are paraphrased from, supported other calendars - these may be supported here in the future, but for now we're pretty Gregorian.]

    For each calendar, there is a (cal)DateConversionData" class, used only within this code module. This class takes a particular year number, and computes the JD corresponding to "new years day" (first day of the first month) in that calendar in that year. It also figures out the number of days in each month of that year, returned in the array month_data[]. There can be up to 13 months, because the Hebrew calendar (and some others that may someday be added) can include an "intercalary month". If a month doesn't exist, then the month_data[] entry for it will be zero (thus, in the Gregorian and Julian and Islamic calendars, month_data[12] is always zero, since these calendars have only 12 months.)

    [mhuss: The code here only supports Gregorian and Julian, so the class is just called DateConversionData. When I get around to doing the rest, DateConversionData will be the interface or base class used by all.]

    The next level up is the getCalendarData() function, which can get the JD of New Years Day and the array of months for any given year for any (supported) calendar. Above this point, all calendars can be treated in a common way; one is shielded from the oddities of individual calendrical systems.

    Finally, at the top level, we reach the only functionality that is exported for the rest of the world to use: dmyToDay() and dayToDmy(). The first (and its variations) takes a day, month, year, and optionally, a calendar system. It calls getCalendarData() for the given year, adds in the days in the months intervening New Years Day and the desired month, adds in the day of the month, and returns the resulting Julian Day.

    dayToDmy() reverses this process. It finds an "approximate" year corresponding to an input JD, and calls getCalendarData() for that year. By adding all the monthData[] values for that year, it can also find the JD for the end of that year; if the input JD is outside that range, it may have to back up a year or add in a year. Once it finds the year where "JD of New Years Day < JD < JD of New Years Eve", it's a simple matter to track down which month and day of the month corresponds to the input JD.

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int GREGORIAN
      Pseudo-enum for calendar type
      static int JULIAN
      Pseudo-enum for calendar type
    • Constructor Summary

      Constructors 
      Constructor and Description
      DateOps() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static long calendarToDay(java.util.Calendar cal)
      Convert a Java Calendar to Julian day value in long form.
      static double calendarToDoubleDay(java.util.Calendar cal)
      Convert a Java Calendar to a Julian day value in double form.
      static long dmyToDay(AstroDate d)
      Converts an AstroDate to a Julian day in long form.
      static long dmyToDay(int day, int month, int year)
      Converts a GREGORIAN day/month/year to a Julian day in long form.
      static long dmyToDay(int day, int month, int year, int calendar)
      Converts a day/month/year to a Julian day in long form.
      static double dmyToDoubleDay(AstroDate d)
      Converts a day/month/year to a Julian day in double form.
      static long dstEnd(int year)
      Calculate the Julian day number for the date when Daylight time ends in a given year.
      static long dstStart(int year)
      Calculate the Julian day number for the date when Daylight time starts in a given year.
      static void main(java.lang.String[] args)
      (for unit testing only)
      static long nowToDay()
      Calculate the current Julian day value in long form.
      static double nowToDoubleDay()
      Calculate the current Julian day value in double form.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DateOps

        public DateOps()
    • Method Detail

      • dmyToDay

        public static long dmyToDay(int day,
                                    int month,
                                    int year,
                                    int calendar)
        Converts a day/month/year to a Julian day in long form.
        Parameters:
        day - Day of the month (1..31)
        month - Month of the Year (1..12)
        year - Year
        calendar - GREGORIAN or JULIAN
        Returns:
        The corresponding Julian day number
      • dmyToDay

        public static long dmyToDay(int day,
                                    int month,
                                    int year)
        Converts a GREGORIAN day/month/year to a Julian day in long form.
        Parameters:
        day - Day of the month (1..31)
        month - Month of the Year (1..12)
        year - Year
        Returns:
        The corresponding Julian day number
      • dmyToDay

        public static long dmyToDay(AstroDate d)
        Converts an AstroDate to a Julian day in long form.
        This function uses the GREGORIAN calendar.
        Parameters:
        d - AstroDate to convert
        Returns:
        The corresponding Julian day number
      • dmyToDoubleDay

        public static double dmyToDoubleDay(AstroDate d)
        Converts a day/month/year to a Julian day in double form.
        This function uses the GREGORIAN calendar.
        Parameters:
        d - AstroDate to convert
        Returns:
        The corresponding Julian day number
      • calendarToDay

        public static long calendarToDay(java.util.Calendar cal)
        Convert a Java Calendar to Julian day value in long form.
        Parameters:
        cal - java.util.Calendar to convert
        Returns:
        The corresponding Julian day
      • calendarToDoubleDay

        public static double calendarToDoubleDay(java.util.Calendar cal)
        Convert a Java Calendar to a Julian day value in double form.
        Parameters:
        cal - java.util.Calendar to convert
        Returns:
        The corresponding Julian day
      • nowToDoubleDay

        public static double nowToDoubleDay()
        Calculate the current Julian day value in double form.
        Returns:
        The corresponding Julian day
      • nowToDay

        public static long nowToDay()
        Calculate the current Julian day value in long form.
        Returns:
        The corresponding Julian day
      • dstStart

        public static long dstStart(int year)
        Calculate the Julian day number for the date when Daylight time starts in a given year.

        The chosen start day is the first Sunday in April, and therefore this function may not be applicable outside the U.S.

        Parameters:
        year - The year of interest
        Returns:
        The corresponding Julian day
      • dstEnd

        public static long dstEnd(int year)
        Calculate the Julian day number for the date when Daylight time ends in a given year.

        This chosen day is the last Sunday in October, and therefore this function may not be applicable outside the U.S.

        Parameters:
        year - The year of interest
        Returns:
        The corresponding Julian day
      • main

        public static void main(java.lang.String[] args)
        (for unit testing only)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.