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

php-carbon.js

v1.0.2

Published

A JavaScript date manipulation library inspired by PHP's Carbon, providing a simple and intuitive API for working with dates and times.

Readme

php-carbon.js

A JavaScript date manipulation library inspired by PHP's Carbon, providing a simple and intuitive API for working with dates and times.

Table of Contents

Installation

Install the library via npm:

npm install php-carbon.js

Usage

Create a new Carbon instance and use its methods to manipulate and query dates:

import Carbon from 'php-carbon.js';

// Create a new Carbon instance for the current date and time
const now = Carbon.now();
console.log(now.format('Y-m-d H:i:s')); // e.g., "2025-05-19 20:45:00"

// Create a specific date
const date = Carbon.createFromDate(2023, 12, 25);
console.log(date.format('Y-m-d')); // "2023-12-25"

// Add days and get human-readable difference
const future = date.addDays(10);
console.log(future.diffForHumans()); // "in 10 days"

Features

  • Simple Date Creation: Create dates from various inputs (strings, numbers, Date objects).
  • Fluent Manipulation: Add or subtract years, months, days, hours, minutes, and seconds.
  • Comparison: Compare dates to check if they are before, after, or equal to another date.
  • Formatting: Format dates using a simple syntax inspired by PHP's Carbon.
  • Human-Readable Differences: Get time differences in a human-friendly format (e.g., "2 days ago").
  • Utility Methods: Check for leap years, weekdays, weekends, and more.

Methods

Creation Methods

  • Carbon.now(): Creates a Carbon instance for the current date and time.
  • Carbon.parse(date): Creates a Carbon instance from a string, number, or Date object.
  • Carbon.make(date): Alias for parse.
  • Carbon.today(): Creates a Carbon instance for today at midnight.
  • Carbon.tomorrow(): Creates a Carbon instance for tomorrow at midnight.
  • Carbon.yesterday(): Creates a Carbon instance for yesterday at midnight.
  • Carbon.createFromDate(year, month, day): Creates a Carbon instance for a specific date.
  • Carbon.createFromTime(hour, minute, second): Creates a Carbon instance for a specific time today.
  • Carbon.createFromDateTime(year, month, day, hour, minute, second): Creates a Carbon instance for a specific date and time.

Getter Methods

  • year(): Returns the year (e.g., 2025).
  • month(): Returns the month (1-12).
  • day(): Returns the day of the month (1-31).
  • hour(): Returns the hour (0-23).
  • minute(): Returns the minute (0-59).
  • second(): Returns the second (0-59).
  • dayOfWeek(): Returns the day of the week (0=Sunday, 6=Saturday).
  • dayOfYear(): Returns the day of the year (1-366).
  • weekOfYear(): Returns the ISO week number (1-53).
  • daysInMonth(): Returns the number of days in the current month.

Manipulation Methods

  • addDays(days), subDays(days): Adds or subtracts days.
  • addMonths(months), subMonths(months): Adds or subtracts months.
  • addYears(years), subYears(years): Adds or subtracts years.
  • addHours(hours), subHours(hours): Adds or subtracts hours.
  • addMinutes(minutes), subMinutes(minutes): Adds or subtracts minutes.
  • addSeconds(seconds), subSeconds(seconds): Adds or subtracts seconds.
  • startOfDay(), endOfDay(): Sets the time to the start or end of the day.
  • startOfMonth(), endOfMonth(): Sets the date to the start or end of the month.
  • startOfYear(), endOfYear(): Sets the date to the start or end of the year.
  • startOfWeek(), endOfWeek(): Sets the date to the start or end of the week (Monday-Sunday).
  • nextWeekday(), previousWeekday(): Moves to the next or previous weekday.
  • nextOrSameDay(dayOfWeek), previousOrSameDay(dayOfWeek): Moves to the next or previous occurrence of a specific day of the week.

Comparison Methods

  • isSameDay(other), isSameMonth(other), isSameYear(other): Checks if two dates share the same day, month, or year.
  • isSameHour(other), isSameMinute(other), isSameSecond(other): Checks if two dates share the same hour, minute, or second.
  • isAfter(other), isBefore(other): Checks if the date is after or before another.
  • isSameOrAfter(other), isSameOrBefore(other): Checks if the date is the same or after/before another.
  • diffInDays(other, absolute), diffInMonths(other, absolute), diffInYears(other, absolute): Calculates the difference in days, months, or years.

Formatting Methods

  • format(format): Formats the date using tokens like Y (year), m (month), d (day), H (hour), i (minute), s (second).
  • toDate(): Returns a native JavaScript Date object.
  • toString(): Returns the date as an ISO string.
  • diffForHumans(other, absolute): Returns a human-readable time difference (e.g., "2 hours ago").

Utility Methods

  • isWeekend(), isWeekday(): Checks if the date is a weekend or weekday.
  • isToday(), isTomorrow(), isYesterday(): Checks if the date is today, tomorrow, or yesterday.
  • isFuture(), isPast(): Checks if the date is in the future or past.
  • isLeapYear(): Checks if the year is a leap year.
  • copy(): Creates a new Carbon instance with the same date.

Contributing

Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository

License

This project is licensed under the MIT License.