-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dcdb77
commit 42650bd
Showing
5 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
True solar time = 11.6286 hours (11:37:42.979) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
demo/java/src/main/java/io/github/cosinekitty/astronomy/demo/SolarTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.cosinekitty.astronomy.demo; | ||
import io.github.cosinekitty.astronomy.*; | ||
|
||
public class SolarTime { | ||
/** | ||
* Display true solar time for a given geographic location at a given time. | ||
* | ||
* @param observer | ||
* The geographic location for which to calculate true solar time. | ||
* | ||
* @param time | ||
* The date and time for which to calculate true solar time. | ||
*/ | ||
public static int run(Observer observer, Time time) { | ||
double ha = Astronomy.hourAngle(Body.Sun, time, observer); | ||
double solarTimeHours = (ha + 12.0) % 24.0; | ||
int milli = (int) Math.round(solarTimeHours * 3.6e+6); | ||
int second = milli / 1000; | ||
milli %= 1000; | ||
int minute = second / 60; | ||
second %= 60; | ||
int hour = minute / 60; | ||
minute %= 60; | ||
hour %= 24; | ||
|
||
System.out.printf("True solar time = %7.4f hours (%02d:%02d:%02d.%03d)%n", solarTimeHours, hour, minute, second, milli); | ||
return 0; | ||
} | ||
} |