com.mhuss.AstroLib
Class AstroDate
- java.lang.Object
-
- com.mhuss.AstroLib.AstroDate
-
public class AstroDate extends java.lang.ObjectA support class for DateOps.This class stores a date/time value at a precision of one second. This date/time can be specified using either the Gregorian Calendar (by default) or the Julian Calendar.
It also supports conversions to and from the Julian Day number.
-
-
Constructor Summary
Constructors Constructor and Description AstroDate()Default constructor = epoch J2000 (noon on 1/1/2000)AstroDate(double jd)Julian Day constructor.AstroDate(int day, int month, int year)Day, Month, Year constructor (time defaults to 00:00:00 = midnight)AstroDate(int day, int month, int year, double dayFraction)Day, Month, Year + fraction of a day constructorAstroDate(int day, int month, int year, int seconds)Literal (member by member) constructorAstroDate(int day, int month, int year, int hour, int min, int sec)Explicit day, month, year, hour, minute, and second constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description intday()Get the day.inthour()Get the Hour.inthourRound()Get the rounded hour.doublejd()Convert this instance of AstroDate to a Julian Day.static doublejd(AstroDate ad)Convert an AstroDate to a Julian Day.static doublejd(AstroDate ad, boolean julian)Convert an AstroDate to a Julian Day.doublejd(boolean julian)Convert this instance of AstroDate to a Julian Day.static voidmain(java.lang.String[] args)(for unit testing only)intminute()Get the minute.intminuteRound()Get the rounded minute.intmonth()Get the month.intsecond()Get the second.java.util.GregorianCalendartoGCalendar()Convert this AstroDate instance to a GregorianCalendar.java.lang.StringtoMinString()Convert this AstroDate instance to a String, formatted to the minute.java.lang.StringtoMinStringTZ()Convert this AstroDate instance to a String formatted to the minute, with Time Zone indicator.java.lang.StringtoString()Convert this AstroDate instance to a String.java.lang.StringtoStringTZ()Convert this AstroDate instance to a String, with Time Zone indicator.intyear()Get the year.
-
-
-
Constructor Detail
-
AstroDate
public AstroDate()
Default constructor = epoch J2000 (noon on 1/1/2000)
-
AstroDate
public AstroDate(int day, int month, int year, int seconds)Literal (member by member) constructor- Parameters:
day- Day of the month (1...31)month- Month of the year (1..12)year- Yearseconds- Time in seconds past midnight. This must be in the range from 0 to Astro.SECONDS_PER_DAY-1.
-
AstroDate
public AstroDate(int day, int month, int year, int hour, int min, int sec)Explicit day, month, year, hour, minute, and second constructor- Parameters:
day- Day of the month (1...31)month- Month of the year (1..12)year- Yearhour- Hour of the day (0...23)min- Minute of the hour (0...59)sec- Second of the minute (0...59)
-
AstroDate
public AstroDate(int day, int month, int year)Day, Month, Year constructor (time defaults to 00:00:00 = midnight)- Parameters:
day- Day of the month (1...31)month- Month of the year (1..12)year- Year
-
AstroDate
public AstroDate(int day, int month, int year, double dayFraction)Day, Month, Year + fraction of a day constructor- Parameters:
day- Day of the monthmonth- Month of the yearyear- YeardayFraction- Fraction of the day
This must be greater than or equal to 0.0 and less than 1.0.
-
AstroDate
public AstroDate(double jd)
Julian Day constructor.- Parameters:
jd- Julian day number
-
-
Method Detail
-
jd
public static double jd(AstroDate ad, boolean julian)
Convert an AstroDate to a Julian Day.- Parameters:
ad- The date to convertjulian- true = Julian calendar, else Gregorian- Returns:
- The Julian Day that corresponds to the specified AstroDate
-
jd
public static double jd(AstroDate ad)
Convert an AstroDate to a Julian Day.
Assumes the AstroDate is specified using the Gregorian calendar.- Parameters:
ad- The date to convert- Returns:
- The Julian Day that corresponds to the specified AstroDate
-
jd
public double jd(boolean julian)
Convert this instance of AstroDate to a Julian Day.- Parameters:
julian- true = Julian calendar, else Gregorian- Returns:
- The Julian Day that corresponds to this AstroDate instance
-
jd
public double jd()
Convert this instance of AstroDate to a Julian Day.
Assumes the AstroDate is specified using the Gregorian calendar.- Returns:
- The Julian Day that corresponds to this AstroDate instance
-
year
public int year()
Get the year.- Returns:
- The year part of this instance of AstroDate
-
month
public int month()
Get the month.- Returns:
- The month part of this instance of AstroDate (1..12)
-
day
public int day()
Get the day.- Returns:
- The day part of this instance of AstroDate (1..31)
-
hour
public int hour()
Get the Hour.
This function truncates, and does not round up to nearest hour. For example, this function will return '1' at all times from 01:00:00 to 01:59:59 inclusive.- Returns:
- The hour of the day for this instance of AstroDate, not rounded
-
hourRound
public int hourRound()
Get the rounded hour.
Returns the hour of the day rounded to nearest hour. For example, this function will return '1' at times 01:00:00 to 01:29:59, and '2' at times 01:30:00 to 01:59:59.- Returns:
- The hour of the day for this instance of AstroDate, rounded to the nearest hour.
-
minute
public int minute()
Get the minute.
This function truncates, and does not round up to nearest minute. For example, this function will return 20 at all times from 1:20:00 to 1:20:59 inclusive.- Returns:
- The minute of the hour for this instance of AstroDate, not rounded.
-
minuteRound
public int minuteRound()
Get the rounded minute.
Returns the minute of the hour for this instance of AstroDate, rounded to nearest minute. For example, this function will return 20 at times 1:20:00 to 1:20:29, and 21 at times 1:20:30 to 1:20:59.- Returns:
- The minute of the hour for this instance of AstroDate, rounded to the nearest minute.
-
second
public int second()
Get the second.- Returns:
- The second of the minute for this instance of AstroDate.
-
toGCalendar
public java.util.GregorianCalendar toGCalendar()
Convert this AstroDate instance to a GregorianCalendar.- Returns:
- An instance of java.util.GregorianCalendar built using this instance of AstroDate.
-
toMinString
public java.lang.String toMinString()
Convert this AstroDate instance to a String, formatted to the minute. This function rounds the exact time to the nearest minute.The format of the returned string is YYYY-MM-DD hh:mm.
- Returns:
- A formatted date/time String
-
toMinStringTZ
public java.lang.String toMinStringTZ()
Convert this AstroDate instance to a String formatted to the minute, with Time Zone indicator.
Rounds the time to the nearest minute.The format of the returned string is YYYY-MM-DD hh:mm TZ, where TZ is a locale-specific timezone name (e.g., "EST").
- Returns:
- A formatted date/time String
-
toString
public java.lang.String toString()
Convert this AstroDate instance to a String.The format of the returned string is YYYY-MM-DD hh:mm:ss.
- Overrides:
toStringin classjava.lang.Object- Returns:
- A formatted date/time String
-
toStringTZ
public java.lang.String toStringTZ()
Convert this AstroDate instance to a String, with Time Zone indicator.The format of the returned string is YYYY-MM-DD hh:mm:ss TZ, where TZ is a locale-specific timezone name (e.g., "EST")
- Returns:
- A formatted date/time String
-
main
public static void main(java.lang.String[] args)
(for unit testing only)
-
-
DMelt 3.0 © DataMelt by jWork.ORG