Skip to content

Commit e8e73f5

Browse files
committed
Merge branch 'length-of-day-ms'
2 parents 0caf496 + 0dab52c commit e8e73f5

File tree

8 files changed

+61
-21
lines changed

8 files changed

+61
-21
lines changed

README.md

+42-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ maven { url "https://dl.bintray.com/caarmen/maven/" }
2424

2525
Declare the dependency:
2626
```
27-
compile 'ca.rmen:lib-sunrise-sunset:1.1.0'
27+
compile 'ca.rmen:lib-sunrise-sunset:1.1.1'
2828
```
2929
Maven:
3030
------
@@ -40,15 +40,17 @@ Declare the dependency:
4040
<dependency>
4141
<groupId>ca.rmen</groupId>
4242
<artifactId>lib-sunrise-sunset</artifactId>
43-
<version>1.1.0</version>
43+
<version>1.1.1</version>
4444
<scope>compile</scope>
4545
</dependency>
4646
```
4747

4848
Any other build system:
4949
-------------------
50+
5051
Alternatively, you can just copy the single java file into your project:
5152
[library/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java](library/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java)
53+
5254
Using the library
5355
=================
5456
To get the sunrise and sunset times for today in Paris, France:
@@ -73,6 +75,44 @@ System.out.println("Astronomical twilight stops at: " + astronomicalTwilight[0].
7375
System.out.println("Astronomical twilight starts at: " + astronomicalTwilight[1].getTime());
7476
```
7577

78+
Command-line interface
79+
======================
80+
81+
A command-line tool is provided. You can download it from the [releases page](https://github.com/caarmen/SunriseSunset/releases)
82+
or build it with `mvn clean package`, which will place it in `cli/target`.
83+
84+
Usage:
85+
86+
```
87+
java -jar /path/to/sunrise-sunset-cli-1.1.1.jar <timezone> <yyyyMMdd> <latitude> <longitude>
88+
```
89+
90+
Example usage:
91+
```
92+
java -jar /path/to/sunrise-sunset-cli-1.1.1.jar Europe/Paris 20171125 48.8 2.35
93+
Current time at: 48.8,2.35:
94+
2017-11-25 18:01:42 Central European Time
95+
Current day period is NAUTICAL_TWILIGHT
96+
Day is 31588000 milliseconds long
97+
Lookup for date:
98+
2017-11-25 12:00:00 Central European Time
99+
Sunrise, Sunset:
100+
2017-11-25 08:15:53 Central European Time
101+
2017-11-25 17:02:21 Central European Time
102+
Civil twilight:
103+
2017-11-25 07:40:16 Central European Time
104+
2017-11-25 17:37:58 Central European Time
105+
Nautical twilight:
106+
2017-11-25 07:01:06 Central European Time
107+
2017-11-25 18:17:08 Central European Time
108+
Astronomical twilight:
109+
2017-11-25 06:23:26 Central European Time
110+
2017-11-25 18:54:48 Central European Time
111+
Solar noon:
112+
2017-11-25 12:39:07 Central European Time
113+
```
114+
115+
76116
Documentation
77117
=============
78118
Javadoc is here: http://caarmen.github.io/SunriseSunset/ca/rmen/sunrisesunset/SunriseSunset.html

cli/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Sunrise Sunset Calculator.
4-
Copyright (C) 2013-2015 Carmen Alvarez
4+
Copyright (C) 2013-2017 Carmen Alvarez
55
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,7 @@
2727
<parent>
2828
<groupId>ca.rmen</groupId>
2929
<artifactId>sunrise-sunset</artifactId>
30-
<version>1.1.0</version>
30+
<version>1.1.1</version>
3131
</parent>
3232

3333
<artifactId>sunrise-sunset-cli</artifactId>

cli/src/main/java/ca/rmen/sunrisesunset/cli/SunriseSunsetCLI.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void main(String[] args) throws Throwable {
6060

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

6565
System.out.println("Lookup for date:");
6666
printCalendar(tz, day);

library/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Sunrise Sunset Calculator.
4-
Copyright (C) 2013-2015 Carmen Alvarez
4+
Copyright (C) 2013-2017 Carmen Alvarez
55
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
@@ -27,12 +27,12 @@
2727
<parent>
2828
<groupId>ca.rmen</groupId>
2929
<artifactId>sunrise-sunset</artifactId>
30-
<version>1.1.0</version>
30+
<version>1.1.1</version>
3131
</parent>
3232

3333
<artifactId>lib-sunrise-sunset</artifactId>
3434
<packaging>jar</packaging>
35-
<version>1.1.0</version>
35+
<version>1.1.1</version>
3636
<name>lib-sunrise-sunset</name>
3737
<url>http://rmen.ca</url>
3838

library/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public enum DayPeriod {
6767
private static final int JULIAN_DATE_2000_01_01 = 2451545;
6868
private static final double CONST_0009 = 0.0009;
6969
private static final double CONST_360 = 360;
70-
private static final long SECONDS_IN_DAY = 60 * 60 * 24;
70+
private static final long MILLISECONDS_IN_DAY = 60 * 60 * 24 * 1000;
7171

7272
/**
7373
* Intermediate variables used in the sunrise equation
@@ -617,8 +617,8 @@ public static boolean isTwilight(double latitude, double longitude) {
617617
* @param latitude the latitude of the location in degrees.
618618
* @param longitude the longitude of the location in degrees (West is negative)
619619
* @param calendar the given datetime to check for twilight
620-
* @return true if at the given location and calendar, it is civil, nautical, or astronomical twilight.
621-
*/
620+
* @return true if at the given location and calendar, it is civil, nautical, or astronomical twilight.
621+
*/
622622
public static boolean isTwilight(Calendar calendar, double latitude, double longitude) {
623623
return isCivilTwilight(calendar, latitude, longitude)
624624
|| isNauticalTwilight(calendar, latitude, longitude)
@@ -639,27 +639,27 @@ public static DayPeriod getDayPeriod(Calendar calendar, double latitude, double
639639
* @param calendar the datetime for which to determine the day length
640640
* @param latitude the latitude of the location in degrees.
641641
* @param longitude the longitude of the location in degrees (West is negative)
642-
* @return the number of milliseconds between sunrise and sunset.
643-
*/
642+
* @return the number of milliseconds between sunrise and sunset.
643+
*/
644644
public static long getDayLength(Calendar calendar, double latitude, double longitude) {
645645
Calendar[] sunriseSunset = getSunriseSunset(calendar, latitude, longitude);
646646
if (sunriseSunset == null) {
647647
int month = calendar.get(Calendar.MONTH); // Reminder: January = 0
648648
if (latitude > 0) {
649649
if (month >= 3 && month <= 10) {
650-
return SECONDS_IN_DAY; // Always day at the north pole in June
650+
return MILLISECONDS_IN_DAY; // Always day at the north pole in June
651651
} else {
652652
return 0; // Always night at the north pole in December
653653
}
654654
} else {
655655
if (month >= 3 && month <= 10) {
656656
return 0; // Always night at the south pole in June
657657
} else {
658-
return SECONDS_IN_DAY; // Always day at the south pole in December
658+
return MILLISECONDS_IN_DAY; // Always day at the south pole in December
659659
}
660660
}
661661
}
662-
return (sunriseSunset[1].getTimeInMillis() - sunriseSunset[0].getTimeInMillis()) / 1000;
662+
return sunriseSunset[1].getTimeInMillis() - sunriseSunset[0].getTimeInMillis();
663663
}
664664

665665
}

library/src/test/java/ca/rmen/sunrisesunset/test/SunriseSunsetSpecificLocationsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void testAntarctica() {
9494
SunriseSunsetTestUtils.testGetDayPeriod("Antarctica/McMurdo", "20151221 12:00", -77.8456, 166.6693, SunriseSunset.DayPeriod.DAY);
9595
SunriseSunsetTestUtils.testGetDayPeriod("Antarctica/McMurdo", "20151221 18:00", -77.8456, 166.6693, SunriseSunset.DayPeriod.DAY);
9696
SunriseSunsetTestUtils.testGetDayPeriod("Antarctica/McMurdo", "20151221 23:00", -77.8456, 166.6693, SunriseSunset.DayPeriod.DAY);
97-
SunriseSunsetTestUtils.testDayLength("Antarctica/McMurdo", "20151221", -77.8456, 166.6693, 86400);
97+
SunriseSunsetTestUtils.testDayLength("Antarctica/McMurdo", "20151221", -77.8456, 166.6693, 86400000);
9898

9999
}
100100

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Sunrise Sunset Calculator.
4-
Copyright (C) 2013-2015 Carmen Alvarez
4+
Copyright (C) 2013-2017 Carmen Alvarez
55
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,7 @@
2727
<groupId>ca.rmen</groupId>
2828
<artifactId>sunrise-sunset</artifactId>
2929
<packaging>pom</packaging>
30-
<version>1.1.0</version>
30+
<version>1.1.1</version>
3131
<name>sunrise-sunset</name>
3232
<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>
3333
<url>http://github.com/caarmen/SunriseSunset</url>

publish.pom

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Sunrise Sunset Calculator.
4-
Copyright (C) 2013-2016 Carmen Alvarez
4+
Copyright (C) 2013-2017 Carmen Alvarez
55
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
@@ -24,7 +24,7 @@
2424
<modelVersion>4.0.0</modelVersion>
2525
<groupId>ca.rmen</groupId>
2626
<artifactId>lib-sunrise-sunset</artifactId>
27-
<version>1.1.0</version>
27+
<version>1.1.1</version>
2828
<packaging>jar</packaging>
2929

3030
<name>sunrise-sunset</name>

0 commit comments

Comments
 (0)