public class SweDate
extends java.lang.Object
implements java.io.Serializable
This is a port of the SwissEphemeris package to Java. See Astrodienst Zürich for more infos and the original authors.
You will find the complete documentation for the original SwissEphemeris package at http://www.astro.ch/swisseph/sweph_g.htm. By far most of the information there is directly valid for this port to Java as well.
Modifier and Type | Field and Description |
---|---|
static int |
FRIDAY
Constant for weekdays.
|
static double |
JD0
The Julian day number of 1970 January 1.0.
|
static int |
MONDAY
Constant for weekdays.
|
static int |
SATURDAY
Constant for weekdays.
|
static boolean |
SE_GREG_CAL |
static boolean |
SE_JUL_CAL |
static boolean |
SE_KEEP_DATE |
static boolean |
SE_KEEP_JD |
static int |
SUNDAY
Constant for weekdays.
|
static int |
THURSDAY
Constant for weekdays.
|
static int |
TUESDAY
Constant for weekdays.
|
static int |
WEDNESDAY
Constant for weekdays.
|
Constructor and Description |
---|
SweDate()
This constructs a new SweDate with a default of the current date
and current time at GMT.
|
SweDate(double jd)
This constructs a new SweDate with the given Julian Day number.
|
SweDate(double jd,
boolean calType)
This constructs a new SweDate with the given Julian Day number.
|
SweDate(int year,
int month,
int day,
double hour)
This constructs a new SweDate with the given date and time.
|
SweDate(int year,
int month,
int day,
double hour,
boolean calType)
This constructs a new SweDate with the given date and time.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkDate()
Checks the date to see, if it is a valid date.
|
boolean |
checkDate(int year,
int month,
int day)
Checks the given date to see, if it is a valid date.
|
boolean |
checkDate(int year,
int month,
int day,
double hour)
Checks the given date to see, if it is a valid date.
|
boolean |
getCalendarType()
Queries the type of calendar in effect - Gregorian or Julian calendar.
|
static java.util.Date |
getDate(double jd)
This will return a java.util.Date object from a julian day number.
|
java.util.Date |
getDate(long offset)
This will return a java.util.Date object with the date of this
SweDate object.
|
int |
getDay()
Queries the day of this SweDate object.
|
int |
getDayOfWeekNr()
Queries the day of the week, i.e.
|
static int |
getDayOfWeekNr(double jd)
Queries the day of the week of the given Julian Day number (interpreted
in the gregorian calendar system!).
|
static int |
getDayOfWeekNr(int year,
int month,
int day)
Queries the day of the week of the given date that is interpreted as
being a date in the Gregorian or Julian calendar system depending on
the date, the switch from Julian to Gregorian calendar system occured.
|
static int |
getDayOfWeekNr(int year,
int month,
int day,
boolean calType)
Queries the day of the week of the given date that is interpreted as
being a date in the given calendar system.
|
double |
getDeltaT()
Queries the delta T value for the date of this object.
|
static double |
getDeltaT(double tjd)
Queries the delta T value for the given Julian Day number - this is a
static method.
|
static double |
getGlobalTidalAcc()
Returns the tidal acceleration used in calculations of delta T.
|
double |
getGregorianChange()
Returns the julian day number on which the Gregorian calendar system
comes to be in effect.
|
double |
getHour()
Queries the hour of the day of this SweDate object.
|
java.lang.String |
getInvalidUTCDateError(int iyear,
int imonth,
int iday,
int ihour,
int imin,
double dsec,
boolean gregflag)
Returns a String error message, if the year, month, day, hour, minute and
second fields do not describe a valid date.
|
double[] |
getJDfromUTC(int iyear,
int imonth,
int iday,
int ihour,
int imin,
double dsec,
boolean gregflag,
boolean checkValidInput)
Calculates the julian day numbers (TT (==ET) and UT1) from a given date.
|
double |
getJulDay()
Queries the Julian Day number of this object.
|
static double |
getJulDay(int year,
int month,
int day,
double hour)
Queries the Julian Day number of the given date in Gregorian calendar
system - this is a static method.
|
static double |
getJulDay(int year,
int month,
int day,
double hour,
boolean calType)
Queries the Julian Day number of the given date that is interpreted as
a date in the given calendar system - this is a static method.
|
java.time.LocalDateTime |
getLocalDateTime()
Returns a LocalDateTime object to be used with DateTimeFormatters.
|
static java.time.LocalDateTime |
getLocalDateTime(SweDate sd)
Returns a LocalDateTime object to be used with DateTimeFormatters.
|
SDate |
getLocalTimeFromUTC(int iyear,
int imonth,
int iday,
int ihour,
int imin,
double dsec,
double d_timezone)
Transform UTC to local time.
|
int |
getMonth()
Queries the month of this SweDate object.
|
SDate |
getUTCfromJDET(double tjd_et,
boolean gregflag)
Calculates the UTC date from ET Julian day number.
|
SDate |
getUTCfromJDUT1(double tjd_ut,
boolean gregflag)
Calculates the UTC date from UT1 (universal time) Julian day number.
|
SDate |
getUTCFromLocalTime(int iyear,
int imonth,
int iday,
int ihour,
int imin,
double dsec,
double d_timezone)
Transform local time to UTC.
|
int |
getYear()
Queries the year of this SweDate object.
|
boolean |
isValidUTCDate(int iyear,
int imonth,
int iday,
int ihour,
int imin,
double dsec,
boolean gregflag)
Determines, if the year, month, day, hour, minute and second fields
describe a valid date.
|
void |
makeValidDate()
Makes the date to be a valid date.
|
void |
setCalendarType(boolean newCalType,
boolean keepDate)
Sets the calendar type for this object.
|
boolean |
setDate(int newYear,
int newMonth,
int newDay,
double newHour)
Sets a new date for this object.
|
boolean |
setDate(int newYear,
int newMonth,
int newDay,
double newHour,
boolean check)
Sets a new date for this object.
|
boolean |
setDay(int newDay)
Sets the day-part of the date.
|
boolean |
setDay(int newDay,
boolean check)
Sets the day-part of the date.
|
static void |
setGlobalTidalAcc(double t_acc)
Sets the tidal acceleration used in calculations of delta T.
|
void |
setGregorianChange(double newJDCO)
Changes the date of the start of the Gregorian calendar system.
|
void |
setGregorianChange(int year,
int month,
int day)
Changes the date of the start of the Gregorian calendar system.
|
boolean |
setHour(double newHour)
Sets a new hour.
|
void |
setJulDay(double newJD)
Sets the new Julian Day for this object.
|
boolean |
setMonth(int newMonth)
Sets the month-part of the date.
|
boolean |
setMonth(int newMonth,
boolean check)
Sets the year-part of the date.
|
protected static void |
setSwissEphObject(SwissEph swiss)
This method is needed to have a consistent global SwissData object "swed",
whose contents may determine the tidal acceleration.
|
boolean |
setYear(int newYear)
Sets the year-part of the date.
|
boolean |
setYear(int newYear,
boolean check)
Sets the year-part of the date.
|
java.lang.String |
toString()
Returns the date, calendar type (gregorian / julian), julian day
number and the deltaT value of this object.
|
void |
updateCalendarType()
Update the calendar type according to the Gregorian calendar start
date and the date of this object.
|
public static final int SUNDAY
public static final int MONDAY
public static final int TUESDAY
public static final int WEDNESDAY
public static final int THURSDAY
public static final int FRIDAY
public static final int SATURDAY
public static final boolean SE_JUL_CAL
public static final boolean SE_GREG_CAL
public static final boolean SE_KEEP_DATE
public static final boolean SE_KEEP_JD
public static final double JD0
getDate(long)
,
Constant Field Valuespublic SweDate()
public SweDate(double jd)
jd
- Julian Day numberpublic SweDate(double jd, boolean calType)
jd
- Julian Day numbercalType
- calendar type (Gregorian or Julian calendar system)SE_GREG_CAL
,
SE_JUL_CAL
public SweDate(int year, int month, int day, double hour)
year
- The year of the datemonth
- The month of the dateday
- The day-number in a month of that datehour
- The hour of the daypublic SweDate(int year, int month, int day, double hour, boolean calType)
year
- The year of the datemonth
- The month of the dateday
- The day-number of the datehour
- The hour of the daycalType
- calendar type (Gregorian or Julian calendar system)SE_GREG_CAL
,
SE_JUL_CAL
public double getJulDay()
public static double getJulDay(int year, int month, int day, double hour)
year
- The year of the datemonth
- The month of the dateday
- The day-number of the datehour
- The hour of the daypublic static double getJulDay(int year, int month, int day, double hour, boolean calType)
year
- The year of the datemonth
- The month of the dateday
- The day-number of the datehour
- The hour of the daycalType
- calendar type (Gregorian or Julian calendar system)SE_GREG_CAL
,
SE_JUL_CAL
public int getDayOfWeekNr()
public static int getDayOfWeekNr(double jd)
public static int getDayOfWeekNr(int year, int month, int day)
public static int getDayOfWeekNr(int year, int month, int day, boolean calType)
year
- The year of the datemonth
- The month of the dateday
- The day-number of the datecalType
- calendar type (Gregorian or Julian calendar system)SE_GREG_CAL
,
SE_JUL_CAL
,
SUNDAY
,
MONDAY
,
TUESDAY
,
WEDNESDAY
,
THURSDAY
,
FRIDAY
,
SATURDAY
public boolean getCalendarType()
SE_GREG_CAL
,
SE_JUL_CAL
public int getYear()
public int getMonth()
public int getDay()
public double getHour()
public double getDeltaT()
public static double getDeltaT(double tjd)
tjd
- Julian Day numberSweConst.SE_TIDAL_DEFAULT
public java.util.Date getDate(long offset)
offset
- An offset in milliseconds to be added to the current
date and time.public static java.util.Date getDate(double jd)
jd
- The julian day number for which to create a Date object.public void setJulDay(double newJD)
newJD
- Julian Day numberpublic void setCalendarType(boolean newCalType, boolean keepDate)
newCalType
- Calendar type (Greogorian or Julian calendar)keepDate
- Determines, if the date or the julian day should
be fix in this operation.SE_GREG_CAL
,
SE_JUL_CAL
,
SE_KEEP_DATE
,
SE_KEEP_JD
public void updateCalendarType()
public boolean setDate(int newYear, int newMonth, int newDay, double newHour)
newYear
- the year-part of the new datenewMonth
- the month-part of the new date [1-12]newDay
- the day-part of the new date [1-31]newHour
- the hour of the new datepublic boolean setDate(int newYear, int newMonth, int newDay, double newHour, boolean check)
newYear
- the year-part of the new datenewMonth
- the month-part of the new date [1-12]newDay
- the day-part of the new date [1-31]newHour
- the hour of the new datecheck
- if true it returns if the date is valid and converts the
the date into a valid datepublic boolean setYear(int newYear)
newYear
- The new yearpublic boolean setYear(int newYear, boolean check)
newYear
- The new yearcheck
- check, if the resulting new date is a valid date and
adjust the values for day, month or year if necessarypublic boolean setMonth(int newMonth)
newMonth
- The new monthpublic boolean setMonth(int newMonth, boolean check)
newMonth
- The new yearcheck
- check, if the resulting new date is a valid date and
adjust the values for day, month or year if necessarysetYear(int, boolean)
public boolean setDay(int newDay)
newDay
- The new daypublic boolean setDay(int newDay, boolean check)
newDay
- The new daycheck
- check, if the resulting new date is a valid date and
adjust the values for day, month or year if necessarysetYear(int, boolean)
public boolean setHour(double newHour)
newHour
- The new hourpublic boolean checkDate()
public boolean checkDate(int year, int month, int day)
year
- the year, for which is to be checkedmonth
- the month, for which is to be checkedday
- the day, for which is to be checkedpublic boolean checkDate(int year, int month, int day, double hour)
year
- the year, for which is to be checkedmonth
- the month, for which is to be checkedday
- the day, for which is to be checkedhour
- the hour, for which is to be checkedpublic void makeValidDate()
public double getGregorianChange()
public void setGregorianChange(int year, int month, int day)
year
- The year (in Gregorian system) for the new start datemonth
- The month (in Gregorian system) for the new start date.
Adversely to java.util.Calendar, the month is to be given in the
range of 1 for January to 12 for December!day
- The day of the month (in Gregorian system, from 1 to 31)
for the new start datepublic void setGregorianChange(double newJDCO)
newJDCO
- The julian day number, on which the Gregorian calendar
came into effect.public static double getGlobalTidalAcc()
double swe_get_tid_acc()
in the original
C sources.public static void setGlobalTidalAcc(double t_acc)
void swe_set_tid_acc(double)
method in the original
C version.t_acc
- tidal accelerationSweConst.SE_TIDAL_DE403
,
SweConst.SE_TIDAL_DE404
,
SweConst.SE_TIDAL_DE405
,
SweConst.SE_TIDAL_DE406
,
SweConst.SE_TIDAL_DE421
,
SweConst.SE_TIDAL_DE430
,
SweConst.SE_TIDAL_DE431
,
SweConst.SE_TIDAL_DE200
,
SweConst.SE_TIDAL_26
,
SweConst.SE_TIDAL_AUTOMATIC
,
SweConst.SE_TIDAL_DEFAULT
protected static void setSwissEphObject(SwissEph swiss)
swiss
- The SwissEph object to be usedpublic java.lang.String toString()
toString
in class java.lang.Object
public SDate getUTCFromLocalTime(int iyear, int imonth, int iday, int ihour, int imin, double dsec, double d_timezone)
iyear
- Year of the input date (UTC)imonth
- Month of the input date (UTC, 1 to 12)iday
- Day of the input date (UTC, 1 to 31)ihour
- Hour of the input date (UTC, 0 to 23)imin
- Minute of the input date (UTC, 0 to 59)dsec
- Second of the input date (UTC, 0.0 to less than 61.0)d_timezone
- Timezone in hoursgetLocalTimeFromUTC(int, int, int, int, int, double, double)
public SDate getLocalTimeFromUTC(int iyear, int imonth, int iday, int ihour, int imin, double dsec, double d_timezone)
iyear
- Year of the input date (UTC)imonth
- Month of the input date (UTC, 1 to 12)iday
- Day of the input date (UTC, 1 to 31)ihour
- Hour of the input date (UTC, 0 to 23)imin
- Minute of the input date (UTC, 0 to 59)dsec
- Second of the input date (UTC, 0.0 to less than 61.0)d_timezone
- Timezone in hours. You can use -d_timezone
to reverse the conversion, but you may also use the
getUTCFromLocalTime() method for this.getUTCFromLocalTime(int, int, int, int, int, double, double)
public boolean isValidUTCDate(int iyear, int imonth, int iday, int ihour, int imin, double dsec, boolean gregflag)
iyear
- Year of the input date (UTC)imonth
- Month of the input date (UTC, 1 to 12)iday
- Day of the input date (UTC, 1 to 31)ihour
- Hour of the input date (UTC, 0 to 23)imin
- Minute of the input date (UTC, 0 to 59)dsec
- Second of the input date (UTC, 1.0 to less than 61.0)gregflag
- true == Gregorian calendar, false == Julian calendarpublic java.lang.String getInvalidUTCDateError(int iyear, int imonth, int iday, int ihour, int imin, double dsec, boolean gregflag)
iyear
- Year of the input date (UTC)imonth
- Month of the input date (UTC, 1 to 12)iday
- Day of the input date (UTC, 1 to 31)ihour
- Hour of the input date (UTC, 0 to 23)imin
- Minute of the input date (UTC, 0 to 59)dsec
- Second of the input date (UTC, 1.0 to less than 61.0)gregflag
- true == Gregorian calendar, false == Julian calendarpublic double[] getJDfromUTC(int iyear, int imonth, int iday, int ihour, int imin, double dsec, boolean gregflag, boolean checkValidInput) throws SwissephException
iyear
- Year of the input date (UTC)imonth
- Month of the input date (UTC, 1 to 12)iday
- Day of the input date (UTC, 1 to 31)ihour
- Hour of the input date (UTC, 0 to 23)imin
- Minute of the input date (UTC, 0 to 59)dsec
- Second of the input date (UTC, 1.0 to less than 61.0)gregflag
- true == Gregorian calendar, false == Julian calendarcheckValidInput
- if true, throws SwissephException, when any of month,
day, hour, minute or second are out of their valid ranges. If false, it
doesn't care about invalid values (e.g. month = 13 or second = 61, even
though there is no leap second on that date and time).Note:
- Before 1972, swe_utc_to_jd() treats its input time as UT1. Note: UTC was introduced in 1961. From 1961 - 1971, the length of the UTC second was regularly changed, so that UTC remained very close to UT1. - From 1972 on, input time is treated as UTC. - If delta_t - nleap - 32.184 > 1, the input time is treated as UT1. Note: Like this we avoid errors greater than 1 second in case that the leap seconds table (or the Swiss Ephemeris version) is not updated for a long time.
SwissephException
getUTCfromJDET(double, boolean)
,
getUTCfromJDUT1(double, boolean)
,
SE_GREG_CAL
,
SE_JUL_CAL
public SDate getUTCfromJDET(double tjd_et, boolean gregflag)
tjd_et
- Julian day number (ET) to be converted.gregflag
- true == Gregorian calendar, false == Julian calendar- Before 1 jan 1972 UTC, output UT1. Note: UTC was introduced in 1961. From 1961 - 1971, the length of the UTC second was regularly changed, so that UTC remained very close to UT1. - From 1972 on, output is UTC. - If delta_t - nleap - 32.184 > 1, the output is UT1. Note: Like this we avoid errors greater than 1 second in case that the leap seconds table (or the Swiss Ephemeris version) has not been updated for a long time.
getUTCfromJDUT1(double, boolean)
,
SDate
,
SE_GREG_CAL
,
SE_JUL_CAL
public SDate getUTCfromJDUT1(double tjd_ut, boolean gregflag)
tjd_ut
- Julian day number (UT1) to be converted.gregflag
- true == Gregorian calendar, false == Julian calendar- Before 1 jan 1972 UTC, output UT1. Note: UTC was introduced in 1961. From 1961 - 1971, the length of the UTC second was regularly changed, so that UTC remained very close to UT1. - From 1972 on, output is UTC. - If delta_t - nleap - 32.184 > 1, the output is UT1. Note: Like this we avoid errors greater than 1 second in case that the leap seconds table (or the Swiss Ephemeris version) has not been updated for a long time.
getUTCfromJDET(double, boolean)
,
SDate
,
SE_GREG_CAL
,
SE_JUL_CAL
public java.time.LocalDateTime getLocalDateTime()
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/mm/dd-hh:mm:ss-a (HH:mm:ss'h')"); System.out.println(new SweDate(2016, 5, 31, 0 + 9/60. + 53/3600.).getLocalDateTime().format(dtf));
public static java.time.LocalDateTime getLocalDateTime(SweDate sd)
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/mm/dd-hh:mm:ss-a (HH:mm:ss'h')"); SweDate sd = new SweDate(); System.out.println(SweDate.getLocalDateTime(sd).format(dtf));