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

timestamp-to-friendly-date

v1.0.1

Published

A function to convert Unix timestamp to a human-friendly date string.

Downloads

3

Readme

Timestamp to Human-friendly Date String Converter

This package provides a simple utility function that converts a Unix timestamp into a human-friendly date string. It takes into account the current date and time to provide a more meaningful representation of the input timestamp. The package uses the dayjs library for date manipulation and formatting, which will be installed automatically as a dependency.

Features

  • Automatically formats the date string based on the input timestamp and the current date.
  • Displays "Today", "Tomorrow", or "Yesterday" when appropriate.
  • Shows the day of the week for dates within the same week.
  • Formats the date string with a month, day, and time for dates within the same year.
  • Includes the year in the date string for dates outside the current year.

Usage:

  1. Install the package:
npm install timestamp-to-friendly-date
  1. Import the convertTimestampToDateString function in your JavaScript or TypeScript file:
import { formatFriendlyDateString } from 'timestamp-to-friendly-date';
  1. Use the convertTimestampToDateString function to convert a Unix timestamp to a human-friendly date string:
import { formatFriendlyDateString } from 'timestamp-to-friendly-date';

// Today's timestamp
const todayTimestamp = new Date().getTime();
console.log(formatFriendlyDateString(todayTimestamp)); // Output: "Today, 2:00 PM" (assuming it's 2:00 PM now)

// Tomorrow's timestamp
const tomorrowTimestamp = new Date().getTime() + 24 * 60 * 60 * 1000;
console.log(formatFriendlyDateString(tomorrowTimestamp)); // Output: "Tomorrow, 2:00 PM" (assuming it's 2:00 PM now)

// Yesterday's timestamp
const yesterdayTimestamp = new Date().getTime() - 24 * 60 * 60 * 1000;
console.log(formatFriendlyDateString(yesterdayTimestamp)); // Output: "Yesterday, 2:00 PM" (assuming it's 2:00 PM now)

// Timestamp within the same week
const thisWeekTimestamp = new Date().getTime() + 2 * 24 * 60 * 60 * 1000;
console.log(formatFriendlyDateString(thisWeekTimestamp)); // Output: "Wednesday, 2:00 PM" (assuming it's Monday 2:00 PM now)

// Timestamp within the same year
const thisYearTimestamp = new Date().getTime() + 30 * 24 * 60 * 60 * 1000;
console.log(formatFriendlyDateString(thisYearTimestamp)); // Output: "May 01, 2:00 PM" (assuming it's April 01, 2:00 PM now)

// Timestamp outside the current year
const otherYearTimestamp = new Date().getTime() + 365 * 24 * 60 * 60 * 1000;
console.log(formatFriendlyDateString(otherYearTimestamp)); // Output: "Apr 01, 2024, 2:00 PM" (assuming it's April 01, 2023, 2:00 PM now)

Please note that this package depends on dayjs, which will be installed automatically when you install this package.