All Projects → caarmen → SunriseSunset

caarmen / SunriseSunset

Licence: LGPL-2.1 license
Java utility to calculate the time of sunrise and sunset for a given location.

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to SunriseSunset

Imageselector
图片选择器, 支持多图选择和图片预览
Stars: ✭ 62 (+47.62%)
Mutual labels:  lib
Weworkapi php
official lib of wework api
Stars: ✭ 225 (+435.71%)
Mutual labels:  lib
AltiumLibrary
Useful Altium pcb library (3D)
Stars: ✭ 33 (-21.43%)
Mutual labels:  lib
Yamaha Nodejs
A node module to control your yamaha receiver
Stars: ✭ 103 (+145.24%)
Mutual labels:  lib
Notion Js
🤯 Notion API
Stars: ✭ 136 (+223.81%)
Mutual labels:  lib
Mtproto Core
Telegram API JS (MTProto) client library for browser and nodejs
Stars: ✭ 242 (+476.19%)
Mutual labels:  lib
Xtd forms
Modern c++17 library to create native gui for Microsoft Windows, Apple macOS and Linux.
Stars: ✭ 25 (-40.48%)
Mutual labels:  lib
gostreamer
Go example that uses channels to build an execution pipeline
Stars: ✭ 75 (+78.57%)
Mutual labels:  lib
React Scoped Css
CSS encapsulation solution for React
Stars: ✭ 214 (+409.52%)
Mutual labels:  lib
Mal4J
Java wrapper for the official MyAnimeList API
Stars: ✭ 23 (-45.24%)
Mutual labels:  lib
Dtkwidget
Deepin Toolkit, widget module for DDE look and feel
Stars: ✭ 112 (+166.67%)
Mutual labels:  lib
Vue Loaders
Vue + loaders.css
Stars: ✭ 127 (+202.38%)
Mutual labels:  lib
rawhttp
Raw HTTP client in Go for complete request control and customization.
Stars: ✭ 100 (+138.1%)
Mutual labels:  lib
Appmetrics.js
A small (< 1kb) library for measuring things in your web app and reporting the results to Google Analytics.
Stars: ✭ 1,383 (+3192.86%)
Mutual labels:  lib
tgcalls
Voice chats, private incoming and outgoing calls in Telegram for Developers
Stars: ✭ 408 (+871.43%)
Mutual labels:  lib
Easygo
基于Kotlin、OkHttp的声明式网络框架,像写HTML界面一样写网络调用代码
Stars: ✭ 40 (-4.76%)
Mutual labels:  lib
Stdlib
✨ Standard library for JavaScript and Node.js. ✨
Stars: ✭ 2,749 (+6445.24%)
Mutual labels:  lib
telegram
Golang Telegram Bot API
Stars: ✭ 13 (-69.05%)
Mutual labels:  lib
metalsmith-imagemin
Metalsmith plugin to minify images
Stars: ✭ 17 (-59.52%)
Mutual labels:  lib
impromptu.nvim
Create prompts fast and easy
Stars: ✭ 39 (-7.14%)
Mutual labels:  lib

SunriseSunset

Java utility which provides methods to determine the sunrise, sunset, civil twilight, nautical twilight, and astronomical twilight times of a given location.

Also provides methods:

  • to convert between Gregorian and Julian dates.
  • to know if it is currently day or night at a given location.

The formulas used by this class are from the Wikipedia articles on [Julian Day] (http://en.wikipedia.org/wiki/Julian_day) and [Sunrise Equation] (http://en.wikipedia.org/wiki/Sunrise_equation).

Adding the dependency

Gradle:

Add this repository:

maven { url "https://dl.bintray.com/caarmen/maven/" }

Declare the dependency:

compile 'ca.rmen:lib-sunrise-sunset:1.1.1'

Maven:

Add this repository:

<repository>
 <id>caarmen-repo</id>
 <url>https://dl.bintray.com/caarmen/maven/</url>
</repository>

Declare the dependency:

<dependency>
 <groupId>ca.rmen</groupId>
 <artifactId>lib-sunrise-sunset</artifactId>
 <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

Using the library

To get the sunrise and sunset times for today in Paris, France:

Calendar[] sunriseSunset = ca.rmen.sunrisesunset.SunriseSunset.getSunriseSunset(Calendar.getInstance(), 48.85837, 2.294481);
System.out.println("Sunrise at: " + sunriseSunset[0].getTime());
System.out.println("Sunset at: " + sunriseSunset[1].getTime());

The civil, nautical, and astronomical twilight times are retrieved in the same way:

Calendar[] civilTwilight = ca.rmen.sunrisesunset.SunriseSunset.getCivilTwilight(Calendar.getInstance(), 48.85837, 2.294481);
System.out.println("Civil twilight stops at: " + civilTwilight[0].getTime());
System.out.println("Civil twilight starts at: " + civilTwilight[1].getTime());

Calendar[] nauticalTwilight = ca.rmen.sunrisesunset.SunriseSunset.getNauticalTwilight(Calendar.getInstance(), 48.85837, 2.294481);
System.out.println("Nautical twilight stops at: " + nauticalTwilight[0].getTime());
System.out.println("Nautical twilight starts at: " + nauticalTwilight[1].getTime());

Calendar[] astronomicalTwilight = ca.rmen.sunrisesunset.SunriseSunset.getAstronomicalTwilight(Calendar.getInstance(), 48.85837, 2.294481);
System.out.println("Astronomical twilight stops at: " + astronomicalTwilight[0].getTime());
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 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].