diff --git a/README.md b/README.md index b4b5c09..7234bc4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,11 @@ navigator.geolocation.getCurrentPosition(function(position) { var sunset = new Date().sunset(position.coords.latitude, position.coords.longitude); }); +//You can set a custom zenith to get twilight times. +//See the source for available zenith values and their meanings. +//Get civil dusk for Forks, WA +var twilight = new Date().sunset(47.95, -124.38, Date.zenith.CIVIL); + ``` By Matt Kane (@ascorbic). Copyright © 2012 Triggertrap Ltd. All Rights Reserved. diff --git a/sun.js b/sun.js index 3db78a2..a07d787 100644 --- a/sun.js +++ b/sun.js @@ -27,9 +27,23 @@ Date.prototype.sunset = function(latitude, longitude, zenith) { return this.sunriseSet(latitude, longitude, false, zenith); } +Date.zenith = { + /** Astronomical sunrise/set is when the sun is 18 degrees below the horizon. */ + ASTRONOMICAL: 108, + + /** Nautical sunrise/set is when the sun is 12 degrees below the horizon. */ + NAUTICAL: 102, + + /** Civil sunrise/set (dawn/dusk) is when the sun is 6 degrees below the horizon. */ + CIVIL: 96, + + /** Official sunrise/set is when the sun is 50' below the horizon. */ + OFFICIAL: 90.8333 +} + Date.prototype.sunriseSet = function(latitude, longitude, sunrise, zenith) { if(!zenith) { - zenith = 90.8333; + zenith = Date.zenith.OFFICIAL; }