sun-time

1.0.2 • Public • Published

sun-time :

Calculator of sunrise and sunset according to location(Long.,lat.) or city name .

Install :

  npm install sun-time;
 

If you want to increase the potential of finding city in local-database of city-coordinates , we recommend to install db-ctiy package .

npm install db-city;

However, db-city is a huge package (144 Mo) since it handles more than 3 Million cities . (Read more about "db-city" ) & how to avoid RAM overload .

Anyway, sun-time has more than 23k local cities .

How to use :

 var sun=require('sun-time');

1. sun(LAT,LONG,ELEVATION) :

  • Latitude is a real number between -90 and 90,

  • longitude is between -180 and 180

  • elevation is a positive number specifying the height in meters with respect to the surrounding terrain. The elevation parameter is optional.

  • Return an object with 2 attributs : i.e : {rise:"",set:""}

  • May returns an array of objects if more than one city have the same name.

    ### Use cases :

     sun(24.68773,46.72185)
       //->i am in Riyadh
      sun(24.68773,46.72185,20)
       // i am in mountain with height=20m

2. sun([LAT,LONG,ELEVATION],date) :

You can retrieve sun's times according to date .

  • date : You can use new Date() to specify today. Date can be also entered as a triple [year, month, day]. For example, [2009, 2, 26] specifies February 26, 2009.

    Since  `x-class` is one of `sun-time` dependencies , `Date.daysAgo`, `Date.daysNext`,`yesterday`,`tomorrow` functions are available as  `static` methods under `Date` class.
    

### Use cases : ```js sun([24,46],new Date()) //-> new Date() is the default sun([24,46],[1989,11,25]) // --> sun times at Nov 25,1989 sun([24,46],Date.daysAgo(7)); //--> before 1 week from now

```

3. sun([LAT,LONG,ELEVATION],date,{format:"24h",tz:3,dst:0}) :

sun method is still overloaded by some options :

  • format (DEFAULT: 24h):

    Output time format, according to the following table:

Format Description Example
24h 24-hour time format 17:35
12h 12-hour time format 5:35 pm
12hNS 12-hour format with no suffix 5:35
Float Floating point number 17.35
  • tz (DEFAULT : hours offset of System % GMT):

    The difference to Greenwich time (GMT) in hours. If omitted or set to "auto", timezone is extracted from the system.

  • dst (DEFAULT: 0):

    Daylight Saving Time: 1 if date is in daylight saving time, 0 otherwise. (summer time->1).

3. sun(CITY_NAME) :

 
       sun('Riyadh')
       //--> if city in the same country of system --> Works!
       //--------------
       //--> else, in this version, add timezone ("tz")
       sun('Tunis',new Date(),{tz:1})
       // "1" -> because Tunis (GMT+1)
 
       sun('கிரனாதா') // === sun("Granada")

The last instruction proves that sun-time supports i18n

     sun('London');
     // is the same
     sun('لندن')  ;

4. Get Directly sunrise or sunset

sun.rise('Mecaa');
sun.set('Newyork');

sun.rise & sun.set are overloaded such as sun itself.

License :

  Copyright (c) 2016 Abdennour TOUMI <http://abdennoor.com>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.

Package Sidebar

Install

npm i sun-time

Weekly Downloads

8

Version

1.0.2

License

MIT

Last publish

Collaborators

  • abdennour