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

@postlight/seasons

v1.0.0

Published

Calculates the astronomical season for a given date or year

Downloads

16

Readme

Astronomical Seasons

This package calculates the astronomical season for a given date or year.

Astronomical seasons are based around natural rotation of the Earth around the sun. Each season begins with either a solstice or an equinox, and which season those represent depends on which side of the equator you're on. Learn more about astronomical and meteorological (month-based) seasons here.

Features

  • Get the current season of a date
  • Get the date and time of the solstice/equinox in a month, which marks the beginning of a season
    • As a UTC datetime
    • As a Julian Day
  • Get a list of all the solstices and equinoxes in a given year, which mark the beginning of a new season

Installation

yarn add @postlight/seasons

# or

npm install @postlight/seasons

Usage

The package can be called using import or required, and has been built for both CommonJS and ECMAScript module formats.

Below example demonstrates how to get the current season of a date.

import { getCurrentSeason } from "@postlight/seasons";

const currentSeason = getCurrentSeason(new Date());
console.log(currentSeason);

Functions

getCurrentSeason(date, isNorthernHemisphere?)

Gets the name of the current season for the date. Since season names are different in each hemisphere, "isNorthernHemisphere" is an optional argument and defaults to true. The season is determined on the local timezone, since the UTC date must be converted to a timezone since some solstices and equinoxes are different dates (ex: December 2023).

This function returns "spring", "summer", "winter", or "fall"

getSeasonStart(monthIndex, year)

Gets the next upcoming equinox or solstice, which is the start of the astronomical season. This returns the date and time in UTC, and it needs to be converted to the local datetime to get the correct season start date.

Example usage to get the December solstice in 2023 for EST timezone:

// Get start of winter in northern hemisphere for EST timezone
seasons.getSeasonStart(11, 2023).toLocaleString("en-US", {
  timeZone: "America/New_York",
});

// Should output: 12/21/2023, 10:28:45 PM
const utcSeasonStart = seasons.getSeasonStart(11, 2023); // result: 2023-12-22T03:28:45.400Z

// Convert UTC season start date to local season start date
const localStart = new Date(
  utcSeasonStart.getFullYear(),
  utcSeasonStart.getMonth(),
  utcSeasonStart.getDate()
);

// If local is EST timezone, should output: 2023-12-21T05:00:00.000Z

getSeasons(year) Returns a list of all the seasons in a year as UTC dates. These dates will need to be converted to the local datetime to get the correct season start date.

Result format: [march-equinox, june-solstice, september-equinox, december-solstice]

getSeasonStartJulianDay(monthIndex, year)

Returns the upcoming solstice or equinox for a month and year as a Julian Day.

getDateFromJulianDay(julianDay: number)

Converts a Julian day into a UTC date.

Sources

Below are sources that were used to create this astronomical season calculator.

License

Licensed under either of the below, at your preference:

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

🔬 A Labs project from your friends at Postlight. Happy coding!