Skip to content

Commit

Permalink
Merge branch 'length-of-day-ms'
Browse files Browse the repository at this point in the history
  • Loading branch information
caarmen committed Nov 25, 2017
2 parents 0caf496 + 0dab52c commit e8e73f5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ maven { url "https://dl.bintray.com/caarmen/maven/" }

Declare the dependency:
```
compile 'ca.rmen:lib-sunrise-sunset:1.1.0'
compile 'ca.rmen:lib-sunrise-sunset:1.1.1'
```
Maven:
------
Expand All @@ -40,15 +40,17 @@ Declare the dependency:
<dependency>
<groupId>ca.rmen</groupId>
<artifactId>lib-sunrise-sunset</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
```

Any other build system:
-------------------

Alternatively, you can just copy the single java file into your project:
[library/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java](library/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java)

Using the library
=================
To get the sunrise and sunset times for today in Paris, France:
Expand All @@ -73,6 +75,44 @@ System.out.println("Astronomical twilight stops at: " + astronomicalTwilight[0].
System.out.println("Astronomical twilight starts at: " + astronomicalTwilight[1].getTime());
```

Command-line interface
======================

A command-line tool is provided. You can download it from the [releases page](https://github.com/caarmen/SunriseSunset/releases)
or build it with `mvn clean package`, which will place it in `cli/target`.

Usage:

```
java -jar /path/to/sunrise-sunset-cli-1.1.1.jar <timezone> <yyyyMMdd> <latitude> <longitude>
```

Example usage:
```
java -jar /path/to/sunrise-sunset-cli-1.1.1.jar Europe/Paris 20171125 48.8 2.35
Current time at: 48.8,2.35:
2017-11-25 18:01:42 Central European Time
Current day period is NAUTICAL_TWILIGHT
Day is 31588000 milliseconds long
Lookup for date:
2017-11-25 12:00:00 Central European Time
Sunrise, Sunset:
2017-11-25 08:15:53 Central European Time
2017-11-25 17:02:21 Central European Time
Civil twilight:
2017-11-25 07:40:16 Central European Time
2017-11-25 17:37:58 Central European Time
Nautical twilight:
2017-11-25 07:01:06 Central European Time
2017-11-25 18:17:08 Central European Time
Astronomical twilight:
2017-11-25 06:23:26 Central European Time
2017-11-25 18:54:48 Central European Time
Solar noon:
2017-11-25 12:39:07 Central European Time
```


Documentation
=============
Javadoc is here: http://caarmen.github.io/SunriseSunset/ca/rmen/sunrisesunset/SunriseSunset.html
4 changes: 2 additions & 2 deletions cli/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sunrise Sunset Calculator.
Copyright (C) 2013-2015 Carmen Alvarez
Copyright (C) 2013-2017 Carmen Alvarez
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -27,7 +27,7 @@
<parent>
<groupId>ca.rmen</groupId>
<artifactId>sunrise-sunset</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>

<artifactId>sunrise-sunset-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void main(String[] args) throws Throwable {

System.out.println("Current day period is " + SunriseSunset.getDayPeriod(now, latitude, longitude));
long dayLength = SunriseSunset.getDayLength(now, latitude, longitude);
System.out.println("Day is " + dayLength + " seconds long");
System.out.println("Day is " + dayLength + " milliseconds long");

System.out.println("Lookup for date:");
printCalendar(tz, day);
Expand Down
6 changes: 3 additions & 3 deletions library/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sunrise Sunset Calculator.
Copyright (C) 2013-2015 Carmen Alvarez
Copyright (C) 2013-2017 Carmen Alvarez
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -27,12 +27,12 @@
<parent>
<groupId>ca.rmen</groupId>
<artifactId>sunrise-sunset</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>

<artifactId>lib-sunrise-sunset</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<version>1.1.1</version>
<name>lib-sunrise-sunset</name>
<url>http://rmen.ca</url>

Expand Down
16 changes: 8 additions & 8 deletions library/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public enum DayPeriod {
private static final int JULIAN_DATE_2000_01_01 = 2451545;
private static final double CONST_0009 = 0.0009;
private static final double CONST_360 = 360;
private static final long SECONDS_IN_DAY = 60 * 60 * 24;
private static final long MILLISECONDS_IN_DAY = 60 * 60 * 24 * 1000;

/**
* Intermediate variables used in the sunrise equation
Expand Down Expand Up @@ -617,8 +617,8 @@ public static boolean isTwilight(double latitude, double longitude) {
* @param latitude the latitude of the location in degrees.
* @param longitude the longitude of the location in degrees (West is negative)
* @param calendar the given datetime to check for twilight
* @return true if at the given location and calendar, it is civil, nautical, or astronomical twilight.
*/
* @return true if at the given location and calendar, it is civil, nautical, or astronomical twilight.
*/
public static boolean isTwilight(Calendar calendar, double latitude, double longitude) {
return isCivilTwilight(calendar, latitude, longitude)
|| isNauticalTwilight(calendar, latitude, longitude)
Expand All @@ -639,27 +639,27 @@ public static DayPeriod getDayPeriod(Calendar calendar, double latitude, double
* @param calendar the datetime for which to determine the day length
* @param latitude the latitude of the location in degrees.
* @param longitude the longitude of the location in degrees (West is negative)
* @return the number of milliseconds between sunrise and sunset.
*/
* @return the number of milliseconds between sunrise and sunset.
*/
public static long getDayLength(Calendar calendar, double latitude, double longitude) {
Calendar[] sunriseSunset = getSunriseSunset(calendar, latitude, longitude);
if (sunriseSunset == null) {
int month = calendar.get(Calendar.MONTH); // Reminder: January = 0
if (latitude > 0) {
if (month >= 3 && month <= 10) {
return SECONDS_IN_DAY; // Always day at the north pole in June
return MILLISECONDS_IN_DAY; // Always day at the north pole in June
} else {
return 0; // Always night at the north pole in December
}
} else {
if (month >= 3 && month <= 10) {
return 0; // Always night at the south pole in June
} else {
return SECONDS_IN_DAY; // Always day at the south pole in December
return MILLISECONDS_IN_DAY; // Always day at the south pole in December
}
}
}
return (sunriseSunset[1].getTimeInMillis() - sunriseSunset[0].getTimeInMillis()) / 1000;
return sunriseSunset[1].getTimeInMillis() - sunriseSunset[0].getTimeInMillis();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testAntarctica() {
SunriseSunsetTestUtils.testGetDayPeriod("Antarctica/McMurdo", "20151221 12:00", -77.8456, 166.6693, SunriseSunset.DayPeriod.DAY);
SunriseSunsetTestUtils.testGetDayPeriod("Antarctica/McMurdo", "20151221 18:00", -77.8456, 166.6693, SunriseSunset.DayPeriod.DAY);
SunriseSunsetTestUtils.testGetDayPeriod("Antarctica/McMurdo", "20151221 23:00", -77.8456, 166.6693, SunriseSunset.DayPeriod.DAY);
SunriseSunsetTestUtils.testDayLength("Antarctica/McMurdo", "20151221", -77.8456, 166.6693, 86400);
SunriseSunsetTestUtils.testDayLength("Antarctica/McMurdo", "20151221", -77.8456, 166.6693, 86400000);

}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sunrise Sunset Calculator.
Copyright (C) 2013-2015 Carmen Alvarez
Copyright (C) 2013-2017 Carmen Alvarez
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -27,7 +27,7 @@
<groupId>ca.rmen</groupId>
<artifactId>sunrise-sunset</artifactId>
<packaging>pom</packaging>
<version>1.1.0</version>
<version>1.1.1</version>
<name>sunrise-sunset</name>
<description>Provides methods to determine the sunrise, sunset, civil twilight,nautical twilight, and astronomical twilight times of a given location, or if it is currently day or night at a given location.</description>
<url>http://github.com/caarmen/SunriseSunset</url>
Expand Down
4 changes: 2 additions & 2 deletions publish.pom
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sunrise Sunset Calculator.
Copyright (C) 2013-2016 Carmen Alvarez
Copyright (C) 2013-2017 Carmen Alvarez
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -24,7 +24,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.rmen</groupId>
<artifactId>lib-sunrise-sunset</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>

<name>sunrise-sunset</name>
Expand Down

0 comments on commit e8e73f5

Please sign in to comment.