Code Monkey home page Code Monkey logo

sun-js's Introduction

sun.js

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

sun-js's People

Contributors

ascorbic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sun-js's Issues

Wrong sunset time

I'm not sure if this is a bug or if I'm doing something wrong, but often I get the wrong sunset time, I will get the sunset of the previous day. I am working with a date that has been set to midnight of the current day using the following small function
function midnightify(time){ var new_time = new Date(time.getTime()); new_time.setHours(0); new_time.setMinutes(0); new_time.setSeconds(0); new_time.setMilliseconds(0); return new_time; }

when the following code is run
var lat = 41.116049; var lon = -73.782147; var current_time = new Date(); var midnight = midnightify(current_time); var sunset = midnight.sunset(lat, lon);

current time has the value of "Sat Jun 02 2018 13:58:43 GMT-0400 (EDT)"
midnight has the value of "Sat Jun 02 2018 00:00:00 GMT-0400 (EDT)"
sunset has the value of "Fri Jun 01 2018 20:21:10 GMT-0400 (EDT)"

It does not make sense to me that the sunset for the day of June 2nd would happen on June 1st. Let me know if I am just misconceiving something here.

Wrong date for sunrise time

When I find the sunrise and sunset time with respect to my current location, sunrise is calculated with tomorrow's date instead of today's date.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.