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

eloi

v1.0.4

Published

A lightweight JavaScript library for shifting the global Date object forward or backward in time during runtime

Downloads

334

Readme

Logo

eloi

A lightweight JavaScript library for shifting the global Date object forward or backward in time during runtime. Perfect for testing systems against future or past dates without manually manipulating your system clock.

Version Bundle size Downloads

CodeFactor SonarCloud Codacy Scrutinizer

Dependencies Security Build Status Coverage Status

Commit activity FOSSA License Made in Ukraine

Table of Contents

🇺🇦 Help Ukraine

I am based in Kyiv, Ukraine, and during these challenging times, it is more important than ever to support Ukraine in its fight for freedom and sovereignty. The war has had a profound impact on millions of lives, and every contribution can make a difference.

We fight for democratic values, freedom, for our future! Once again Ukrainians have to stand against evil, terror, against genocide. The outcome of this war will determine what path human history is taking from now on.

💛💙 If you find this library useful, consider helping Ukrainians by donating to reputable organizations providing aid or supporting the efforts of the Ukrainian people in any way you can. Together, we can make a meaningful impact.

Motivation

Eloi was created to provide a convenient and reliable way to test how applications behave with different dates and times without requiring changes to the system clock.

This can be particularly useful for simulating future expiration dates, verifying date-based logic, or ensuring long-running systems handle transitions correctly.

By offering a runtime solution, Eloi eliminates the risks and complexities associated with altering system-wide settings, making it an invaluable tool for developers working on time-sensitive features.

Requirements

Platform Status

To use library you need to have node and npm installed in your machine:

  • node >=10
  • npm >=6

Package is continuously tested on darwin, linux and win32 platforms. All active and maintenance LTS node releases are supported.

Installation

To install the library run the following command

  npm i --save eloi

Usage

Basic Example:

import eloi from 'eloi';

// Shift time 1 year into the future
const year = 365 * 24 * 60 * 60 * 1000;

eloi.shift(year); // 1 year in milliseconds

console.log(new Date()); // Prints future date
console.log(Date.now());

eloi.reset(); // Reset to original Date
console.log(new Date()); // Prints the current date

Advanced Example:

import { Eloi } from 'eloi';

// Create a local Eloi instance
const eloi = new Eloi(Date, { global: false });
const CustomDate = eloi.shift(-24 * 60 * 60 * 1000); // 1 day back in time

console.log(new CustomDate()); // Prints Yesterday
console.log(new Date());       // Prints Today

// Reset not required since global Date is untouched

Configuration

constructor(OriginalDate = Date, options = {})

  • OriginalDate (optional): The Date implementation to use as the base.
  • options.global (optional): Whether to replace the global Date. Default is true.

shift(offsetMs) Shifts time by the specified offset (in milliseconds). Returns a modified Date class.

  • offsetMs: The number of milliseconds to shift. Positive for future, negative for past.

reset() Resets the global Date object to its original implementation.

Contribute

Make the changes to the code and tests. Then commit to your branch. Be sure to follow the commit message conventions. Read Contributing Guidelines for details.