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 🙏

© 2026 – Pkg Stats / Ryan Hefner

date-fns-broadcast

v1.1.1

Published

date-fns plugin for broadcast calendar week, month, quarter, and year calculations

Readme

date-fns-broadcast

A set of helper functions for working with broadcast calendar dates, built to be compatible with date-fns.

Installation

npm install date-fns-broadcast date-fns

What is a Broadcast Calendar?

The Broadcast Calendar is a standardized calendar used primarily in the broadcasting industry for planning and purchasing radio and television programs and advertising. It was designed to provide uniform billing periods and has been widely adopted by broadcasters, agencies, and advertisers.

Key characteristics:

  • Every week starts on Monday and ends on Sunday
  • Every month has either 4 or 5 complete weeks (28 or 35 days)
  • Every month ends on the last Sunday of the calendar month
  • The first week of every broadcast month always contains the first day of the calendar month
  • Years can have either 52 or 53 weeks

53-Week Years

A broadcast calendar will have 53 weeks in:

  • A leap year where January 1 falls on a Saturday or Sunday
  • A common year where January 1 falls on a Sunday

Known 53-week years in the 21st century: 2006, 2012, 2017, 2023, 2028, 2034, 2040, 2045, 2051, 2056, 2062, 2068, 2073, 2079, 2084, 2090, and 2096.

Functions

Week Functions

  • startOfBroadcastWeek(date) - Returns the Monday of the broadcast week
  • endOfBroadcastWeek(date) - Returns the Sunday of the broadcast week
  • getBroadcastWeek(date) - Returns the week number (1-53) within the broadcast year

Month Functions

  • startOfBroadcastMonth(date) - Returns the first Monday of the broadcast month
  • endOfBroadcastMonth(date) - Returns the last Sunday of the broadcast month
  • getBroadcastMonth(date) - Returns the broadcast month number (1-12)
  • formatBroadcastMonth(date, formatStr?) - Returns the broadcast month as a formatted string (default: "MMMM yyyy")

Quarter Functions

  • startOfBroadcastQuarter(date) - Returns the first Monday of the broadcast quarter
  • endOfBroadcastQuarter(date) - Returns the last Sunday of the broadcast quarter
  • getBroadcastQuarter(date) - Returns the quarter number (1-4)

Year Functions

  • startOfBroadcastYear(date) - Returns the start of the broadcast year
  • endOfBroadcastYear(date) - Returns the end of the broadcast year
  • getBroadcastYear(date) - Returns the broadcast year number
  • startOfBroadcastYearByNumber(year) - Returns the start of the broadcast year for a given year number

Enumeration Functions

  • eachBroadcastWeekOfYear(year) - Returns an array of week-start Mondays for the broadcast year (52 or 53 dates)
  • eachBroadcastWeekOfQuarter(date) - Returns an array of week-start Mondays for the broadcast quarter (13 or 14 dates)
  • eachBroadcastWeekOfMonth(date) - Returns an array of week-start Mondays for the broadcast month (4 or 5 dates)
  • eachBroadcastQuarterOfYear(year) - Returns an array of 4 quarter-start dates for the broadcast year
  • eachBroadcastMonthOfYear(year) - Returns an array of 12 month-start dates for the broadcast year
  • eachBroadcastMonthOfQuarter(date) - Returns an array of 3 month-start dates for the broadcast quarter containing the given date

Count Functions

  • countBroadcastWeeksInYear(year) - Returns the number of broadcast weeks in the year (52 | 53)
  • countBroadcastWeeksInMonth(date) - Returns the number of broadcast weeks in the month (4 | 5)

Utility Functions

  • renderBroadcastCalendar(year) - Returns a string representation of the broadcast calendar for a given year

A note on date construction

Avoid constructing dates from short ISO strings like new Date("2025-01-01"). JavaScript treats these as UTC midnight, which in non-UTC timezones resolves to the previous day — a common source of off-by-one errors.

Prefer local date construction:

// ✅ correct — uses local time
const date = new Date(2025, 0, 1);

// ⚠️ avoid — parsed as UTC, may resolve to Dec 31 in your timezone
const date = new Date("2025-01-01");

This applies to all date-fns functions, not just this library.

Examples

import {
  getBroadcastWeek,
  getBroadcastMonth,
  getBroadcastYear,
  startOfBroadcastMonth,
  endOfBroadcastMonth,
  formatBroadcastMonth,
} from "date-fns-broadcast";

// Basic lookups
const date = new Date(2025, 0, 1); // January 1, 2025
getBroadcastWeek(date);   // 1
getBroadcastMonth(date);  // 1
getBroadcastYear(date);   // 2025

// Broadcast month boundaries can differ from calendar month boundaries.
// January 1, 2025 falls on a Wednesday, so the broadcast month starts
// on the previous Monday, December 30, 2024.
startOfBroadcastMonth(date); // 2024-12-30
endOfBroadcastMonth(date);   // 2025-01-26

// Format a broadcast month
formatBroadcastMonth(date);           // "January 2025"
formatBroadcastMonth(date, "MMM yy"); // "Jan 25"