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

temporal-fns

v1.1.2

Published

A utility library for working with JavaScript Temporal objects, providing helper functions for date and time manipulations.

Downloads

329

Readme

temporal-fns

A utility library for working with Temporal dates and times, providing helper functions for common date and time manipulations.

Installation

bun install temporal-fns
npm install temporal-fns
pnpm install temporal-fns

Functions

startOfMonth

Gets the first day of the month for the given Temporal object. Optionally, the time can be preserved instead of resetting to the start of the day (00:00:00.000000000).

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.
  2. [options] (Object): The options object.
    • preserveTime (boolean): Specify whether to preserve the original time. Defaults to false.

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the first day of the month.

Example

import { Temporal } from "@js-temporal/polyfill";
import { startOfMonth } from "temporal-fns";

const dateTime = Temporal.PlainDateTime.from("2024-02-24T14:24:24");

startOfMonth(dateTime);
// => Temporal.PlainDateTime 2024-02-01T00:00:00

startOfMonth(dateTime, { preserveTime: true });
// => Temporal.PlainDateTime 2024-02-01T14:24:24

startOfWeek

Gets the first day of the week (Monday) for the given Temporal object.

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the first day of the week (Monday).

Example

import { Temporal } from "@js-temporal/polyfill";
import { startOfWeek } from "temporal-fns";

const date = Temporal.PlainDate.from("2024-02-21"); // A Wednesday

startOfWeek(date);
// => Temporal.PlainDate 2024-02-19 (Monday)

startOfDay

Sets the time to the start of the day (00:00:00.000000000).

Arguments

  1. temporal (Temporal.PlainTime | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to modify.

Returns

(Temporal.PlainTime | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object with the time set to the start of the day.

Example

import { Temporal } from "@js-temporal/polyfill";
import { startOfDay } from "temporal-fns";

const dateTime = Temporal.PlainDateTime.from("2024-02-24T14:24:24");

startOfDay(dateTime);
// => Temporal.PlainDateTime 2024-02-24T00:00:00

endOfMonth

Gets the last day of the month for the given Temporal object. Optionally, the time can be preserved instead of resetting to the end of the day (23:59:59.999999999).

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.
  2. [options] (Object): The options object.
    • preserveTime (boolean): Specify whether to preserve the original time. Defaults to false.

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the last day of the month.

Example

import { Temporal } from "@js-temporal/polyfill";
import { endOfMonth } from "temporal-fns";

const dateTime = Temporal.PlainDateTime.from("2024-02-24T14:24:24");

endOfMonth(dateTime);
// => Temporal.PlainDateTime 2024-02-29T23:59:59.999999999

endOfMonth(dateTime, { preserveTime: true });
// => Temporal.PlainDateTime 2024-02-29T14:24:24

endOfWeek

Gets the last day of the week (Sunday) for the given Temporal object.

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the last day of the week (Sunday).

Example

import { Temporal } from "@js-temporal/polyfill";
import { endOfWeek } from "temporal-fns";

const date = Temporal.PlainDate.from("2024-02-21"); // A Wednesday

endOfWeek(date);
// => Temporal.PlainDate 2024-02-25 (Sunday)

endOfDay

Sets the time to the end of the day (23:59:59.999999999).

Arguments

  1. temporal (Temporal.PlainTime | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to modify.

Returns

(Temporal.PlainTime | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object with the time set to the end of the day.

Example

import { Temporal } from "@js-temporal/polyfill";
import { endOfDay } from "temporal-fns";

const dateTime = Temporal.PlainDateTime.from("2024-02-24T14:24:24");

endOfDay(dateTime);
// => Temporal.PlainDateTime 2024-02-24T23:59:59.999999999

nextDayOfWeek

Gets the next occurrence of a specific day of the week after the given Temporal object.

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.
  2. dayOfWeek (1 | 2 | 3 | 4 | 5 | 6 | 7): The desired day of the week (1 = Monday, 7 = Sunday).

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the next occurrence of the specified day of the week.

Example

import { Temporal } from "@js-temporal/polyfill";
import { nextDayOfWeek } from "temporal-fns";

const date = Temporal.PlainDate.from("2024-02-21");

nextDayOfWeek(date, 5); // Next Friday
// => Temporal.PlainDate 2024-02-23

previousDayOfWeek

Gets the previous occurrence of a specific day of the week before the given Temporal object.

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.
  2. dayOfWeek (1 | 2 | 3 | 4 | 5 | 6 | 7): The desired day of the week (1 = Monday, 7 = Sunday).

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the previous occurrence of the specified day of the week.

Example

import { Temporal } from "@js-temporal/polyfill";
import { previousDayOfWeek } from "temporal-fns";

const date = Temporal.PlainDate.from("2024-02-21");

previousDayOfWeek(date, 1); // Previous Monday
// => Temporal.PlainDate 2024-02-19

firstDayOfWeekOfMonth

Gets the first occurrence of a specific day of the week in the month of the given Temporal object.

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.
  2. dayOfWeek (1 | 2 | 3 | 4 | 5 | 6 | 7): The desired day of the week (1 = Monday, 7 = Sunday).

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the first occurrence of the specified day of the week in the month.

Example

import { Temporal } from "@js-temporal/polyfill";
import { firstDayOfWeekOfMonth } from "temporal-fns";

const date = Temporal.PlainDate.from("2024-02-24");

firstDayOfWeekOfMonth(date, 1); // First Monday of the month
// => Temporal.PlainDate 2024-02-05

lastDayOfWeekOfMonth

Gets the last occurrence of a specific day of the week in the month of the given Temporal object.

Arguments

  1. temporal (Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): The Temporal object to query.
  2. dayOfWeek (1 | 2 | 3 | 4 | 5 | 6 | 7): The desired day of the week (1 = Monday, 7 = Sunday).

Returns

(Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime): Returns the new Temporal object set to the last occurrence of the specified day of the week in the month.

Example

import { Temporal } from "@js-temporal/polyfill";
import { lastDayOfWeekOfMonth } from "temporal-fns";

const date = Temporal.PlainDate.from("2024-02-24");

lastDayOfWeekOfMonth(date, 1); // Last Monday of the month
// => Temporal.PlainDate 2024-02-26