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

time-offset

v1.0.1

Published

Accumulative Time Calculator: A simple calculator for time offsets that provides methods to manipulate and retrieve time values.

Readme

TimeOffset Library

The TimeOffset library is a simple utility for managing time in seconds. It allows you to accumulate time through various methods, including adding seconds, minutes, hours, and days. The library is designed to work in an accumulative mode, essentially functioning as a calculator for time offsets.

Installation

To use the TimeOffset library, you can install it via npm:

npm install time-offset

For yarn:

yarn add time-offset

Usage

Importing the Library

You can import the TimeOffset class into your project as follows:

import { TimeOffset } from 'time-offset';

Creating an Instance

You can create an instance of TimeOffset with an optional initial time-to-live (TTL) in seconds:

const timeOffset = new TimeOffset(3600); // Initializes with 1 hour (3600 seconds)

Adding Time

You can add time in seconds, minutes, hours, or days using the following methods:

  • Add Seconds

    timeOffset.addSeconds(30); // Adds 30 seconds
  • Add Minutes

    timeOffset.addMinutes(5); // Adds 5 minutes (300 seconds)
  • Add Hours

    timeOffset.addHours(2); // Adds 2 hours (7200 seconds)
  • Add Days

    timeOffset.addDays(1); // Adds 1 day (86400 seconds)

Static Methods

You can also create a new TimeOffset instance and add time in a single line using static methods:

const newTimeOffset = TimeOffset.addSeconds(120); // Creates a new instance with 120 seconds

Retrieving Values

You can retrieve the accumulated time in seconds or get future/past dates based on the accumulated time:

  • Get Accumulated Seconds

    const totalSeconds = timeOffset.toAccumulatedSeconds();
  • Get Future Date

    const futureDate = timeOffset.toFutureDate(); // Returns a Date object for the future
  • Get Past Date

    const pastDate = timeOffset.toDatePast(); // Returns a Date object for the past

Example

Here’s a simple example demonstrating the usage of the TimeOffset library:

import { TimeOffset } from 'time-offset';

const timeOffset = new TimeOffset();
timeOffset.addHours(1).addMinutes(30).addSeconds(45);

console.log(`Total seconds: ${timeOffset.toAccumulatedSeconds()}`); // Outputs total accumulated seconds
console.log(`Future date: ${timeOffset.toFutureDate()}`); // Outputs future date
console.log(`Past date: ${timeOffset.toDatePast()}`); // Outputs past date

API

Constructor

  • constructor(ttl: number = 0): Initializes a new instance of TimeOffset with an optional TTL in seconds.

Methods

  • addSeconds(seconds: number): TimeOffset: Adds the specified seconds to the accumulated time.
  • addMinutes(minutes: number): TimeOffset: Adds the specified minutes to the accumulated time.
  • addHours(hours: number): TimeOffset: Adds the specified hours to the accumulated time.
  • addDays(days: number): TimeOffset: Adds the specified days to the accumulated time.
  • toAccumulatedSeconds(): number: Returns the total accumulated time in seconds.
  • toFutureDate(): Date: Returns a Date object representing the future date based on the accumulated time.
  • toDatePast(): Date: Returns a Date object representing the past date based on the accumulated time.

Author

Support

If you have questions or suggestions, create issue