npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spacetime-daylight

v1.5.1

Published

calculate approximate sunlight times for a given timezone

Downloads

74

Readme

a spacetime plugin to calculate sunlight exposure for a given timezone/location, in local time.

This project is really just a neat opportunity to combine some exceptional open-source javascript libraries:

that's all it does.

it bundles-in the spacetime-geo plugin, too.

sunrise/sunset

import spacetime from 'spacetime'
import daylight from 'spacetime-daylight'
spacetime.extend(daylight)

let d = spacetime('June 5th 3:30pm', 'Canada/Eastern')
d.sunrise().time()
// 6:43am
d.sunset().time()
// 7:13pm
d.noon().time()
// 1:17pm

132kb or so,

solar position

find the position of the sun, at a place and time:

let s = spacetime.today('Europe/Stockholm').time('3:00am')
let hours = s.every('hour', s.time('11:00pm'))
hours.forEach((d) => {
  console.log(d.time(), d.sunPosition())
})

Altitude means how high the sun is. 90° is directly overhead, 0° means it's setting, or rising. negative numbers means it's dark.

Azimuth describes how far it is east-to-west 0° is North. Negative numbers are east (morning). Noon should have the same azimuth as midnight.

solstice calculator

some rough millisecond-math for estimating solstice dates for a given year:

let s = spacetime('march 3rd 2007')
console.log(s.summerSolstice().format('nice'))

(this is not recommended for advanced astronomy, or distant years)

API

d.sunrise()

d.sunset()

d.noon()

d.dusk()

d.dawn()

//this one does some helper diff logic
d.daylight()
/*{
  dawn: '5:02am',
  sunrise: '5:38am',
  sunset: '9:04pm',
  dusk: '9:40pm',
  duration:
   { inHours: 16,
     inMinutes: 926,
     inSeconds: 55540,
     human: { hours: 15, minutes: 25, seconds: 40 } },
  current: { progress: 0.49936982355059417, status: 'day' }
}*/

Examples:

find out the rate the length-of-day is changing

let s = spacetime('November 12 2018', 'Europe/London')
let today = s.daylight().inSeconds
let tomorrow = s.add(1, 'day').daylight().inSeconds
let diff = today - tomorrow
console.log(`today is ${diff / 60} minutes longer`)
// 'today is 3.2 minutes longer'

find-out where the sun is rising now:

let maybeList = spacetime.whereIts('4:00am', '9:30am')
maybeList.forEach((tz) => {
  let d = spacetime.now(tz)
  if (d.isBetween(d.dawn(), d.sunrise())) {
    //calculate how minutes until sunrise
    let diff = d.diff(d.sunrise())
    console.log(tz + ' in ' + diff.minutes + ' mins - @ ' + d.sunrise().time())
  }
})
// Asia/Kamchatka in 25 mins - @ 6:01am
// Asia/Magadan in 4 mins - @ 4:40am
// Pacific/Midway in 19 mins - @ 5:55am

See also

  • timespace - by MapBox, using Moment - larger and more-accurate.

MIT