HollowMan6 / sun.js

Calculate sunrise and sunset times in Javascript.(JS计算日出日落时间)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sun.js

last-commit Node.js Package

Followers watchers stars forks

Open Source Love GPL Licence Repo-Size

Total alerts Language grade: JavaScript

New: Modified by Hollow Man so that the specified time is always between sunrise and sunset time.

Copyright © 2020 hollowman6 from Lanzhou University (兰州大学).


Calculate sunrise and sunset times in Javascript.

This library extends the Javascript Date object, adding methods to calculate sunrise and sunset times. It also extends the Math object to add several useful support functions. If you don't like core JS types being extended you should probably rewrite this!

Based loosely and indirectly on Kevin Boone's SunTimes Java implementation of the US Naval Observatory's algorithm.

Usage is very simple:

//Sunset tonight at the Triggertrap office
var sunset = new Date().sunset(51.4541, -2.5920);

//Sunrise at Stonehenge on midsummer's day 2000

var sunrise = new Date("2000-06-21").sunrise(51.1788, -1.8262);

//Combine it with geolocation. Sunset tonight at your location.

navigator.geolocation.getCurrentPosition(function(position) {
   	var sunset = new Date().sunset(position.coords.latitude, position.coords.longitude);
});

By Matt Kane (@ascorbic). Copyright © 2012 Triggertrap Ltd. All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA, or connect to: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html

About

Calculate sunrise and sunset times in Javascript.(JS计算日出日落时间)

License:GNU Lesser General Public License v2.1


Languages

Language:JavaScript 99.0%Language:Shell 1.0%