Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eloi

pustovitDmytro362MIT1.0.4

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

time manipulation, time travel, mock date, date testing, future testing, past testing, global date override, runtime date shift, date mocking, time testing tool, temporal testing, time-shifting library, test automation, date control, date mock, date, time

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.

changelog

1.0.4 (2024-12-18)

Docs

  • changle logo to absolute url (ebcdc24)

1.0.3 (2024-12-16)

Chore

Fix

  • fixes correct print in logs (516d38d)

1.0.2 (2024-12-13)

Docs

  • adds logo to npmingnore (21c519e)

1.0.1 (2024-12-13)

Docs

1.0.0 (2024-12-13)

Chore

  • 'Chore' semanticCommitType for updating devDependencies (4bf79e1)
  • (ci) fix gitleaks version (badd1c1)
  • (git) Add logs to gitignore (d4d2077)
  • (refactor) remove unused argument (6f28b59)
  • (test) helper packages for tests (e195b58)
  • (test) working with tmp dir for test factory (cfeafbc)
  • (tests) clearCache on module load is optional (96c2ae5)
  • (tests) moves load to factory (4acb941)
  • additional quotes in glob pattern (f6d15cf)
  • adds a security policy (ed86aba)
  • adds 'typo' PR template (e20404d)
  • adds appveyor (d560b4e)
  • adds bump strategy for devDependencies (non-major) (03c9587)
  • adds CIRCLE_SKIP_DEPLOY variable (231549d)
  • adds circle-ci conditions (5a40980)
  • adds CODE_OF_CONDUCT (a969a8d)
  • adds commitlint (38ded63)
  • adds danger to circle-ci (ae48ac3)
  • adds danger to validate pr (7fb7040)
  • adds danger token to circle (82f4156)
  • adds dangerfile to npm ignore (8842c70)
  • adds dummy line to calc coverage (800de67)
  • adds empty line to pr comment (36d8a09)
  • adds gitleaks to circle pipeline (114946e)
  • adds jscpd to ignore (8520cea)
  • adds lock file lint (f5a4679)
  • adds pr context (ce163d9)
  • adds sonarcloud config (c92973d)
  • adds sponsorships (35ed8e0)
  • adds stabilityDays to renovate (3b262bc)
  • adds target branch to semantic release (c4fb3f1)
  • adds technical dept check (e16a8e2)
  • adds telegra.ph release notes (aa811a5)
  • adds test-results to circle-ci (767c5b3)
  • adds tests for packing process (9b9602d)
  • adds tests for prior node versions (4b00012)
  • adds todo files to gitignore (1e579dc)
  • adds trusted bots to danger (892f4a1)
  • adds whitesorce bolt bot (0888eee)
  • anti-terrorism disclaimer (96327fe)
  • calc fossa results in cirrus (b2b48c1)
  • change extention of test files to .test.js (d84ac03)
  • change renovate schedule (b983eab)
  • change tgz label (5e0e512)
  • combine mine packages in renovate updates (54c97b8)
  • contributor login in danger message (76349e6)
  • corrected extglob matching (72a2201)
  • corrected pack pattern (273497a)
  • create auto pr for major dependencies (d2583a6)
  • deploy ci as single command (96c2800)
  • deploy in circle-ci (a62a5f2)
  • disable build for coverage check (0b6e984)
  • dont pin devDeps in renovate (5fb0e8d)
  • dont store package-tests artifacts (50ebff1)
  • drop semantic-release preinstalled plugins (69b1950)
  • enhance own updates commit messages (49a2365)
  • exit code 0 when skip (f6ee0bf)
  • export default in tests (9d210e6)
  • fill test entry with template (9177859)
  • fix json in renovate (8ad7928)
  • fixes audit (14597ff)
  • fixes audit [devDependencies] (d08b1fc)
  • fixes Breaking increment in semantic-release (d1c4d53)
  • fixes ci (0576a01)
  • Fixes danger-pr in circe-ci (adff8b3)
  • fixes debt typo in travis job (f9fd463)
  • fixes eslint-plugin-unicorn version (dd45e9a)
  • fixes later schedule (a0cfb5c)
  • fixes npm audit (c3beccd)
  • fixes npm audit (0500470)
  • fixes package process (364e26b)
  • fixes prevent require handler (7923f0e)
  • fixes renovate config (982abaf)
  • fixes renovate config (05c5bc5)
  • fixes some audit dev dependencies (e5983c2)
  • fixes some npm audit vulnerabilities (b913fee)
  • fixes some npm audit vulnerabilities (9330c38)
  • fixes some npm audit vulnerabilities (f7a14d5)
  • fixes some npm audit vulnerabilities (#86) (eb549de), closes #86
  • fixes spellcheck in bugreport (7d754b6)
  • ignoring all for npm packaging (409201a)
  • integrate APPVEYOR_BUILD_ID to build tests (16cdd48)
  • integrate fossa (b65e961)
  • integrate lalaps (dd4f238)
  • integrate node-package-tester (9d53bf3)
  • inverse logical condition (65dd0ad)
  • Lock file maintenance (ce88841)
  • Lock file maintenance (85b7c09)
  • Lock file maintenance (29fe760)
  • Lock file maintenance (9892cc5)
  • Lock file maintenance (98e62b3)
  • Lock file maintenance (7af4484)
  • Lock file maintenance (1ffc991)
  • Lock file maintenance (47bfacf)
  • Lock file maintenance (19c2389)
  • Lock file maintenance (2b00aec)
  • Lock file maintenance (dea06c9)
  • Lock file maintenance (e0043d8)
  • Lock file maintenance (5d305a8)
  • Lock file maintenance (cdf4f11)
  • Lock file maintenance (3291a21)
  • multi os tests for travis (7c8ce28)
  • not allow to fail on node 16 (22ed683)
  • not fail package if no tmp exists (5693813)
  • package-tester improvements (d5d868b)
  • prevent package:test from using devdependencies (dc896f3)
  • regenerate lock file in node 14 (edd0926)
  • regerate lock file (3b5cb86)
  • removes unused devDependencies (ddb100a)
  • replace appveyor to actions (13aff75)
  • run pr workflow only for pull requests (03e0b08)
  • set myself as default assignee in pr (0dcd0ce)
  • set YARGS_MIN_NODE_VERSION 10 (9b6bef9)
  • split circle ci jobs (9f75a6b)
  • telegram notifications on release (3a8036a)
  • test-security in separete ci job (a4bd846)
  • test-security in separete ci job (9559dbc)
  • tests/entry.js module resolving (c840f8b)
  • update .renovaterc to automerge after successfull checks (2e76ceb)
  • update default renovate rules (7e83bc4)
  • Update dependency @rollup/plugin-commonjs to v19 (bf29948)
  • Update dependency @rollup/plugin-node-resolve to v13 (265fd82)
  • Update dependency babel-plugin-module-resolver to v4 (b8eb86f)
  • Update dependency danger to v11 (1779a27)
  • Update dependency eslint to v7 (0e79e0f)
  • Update dependency eslint-plugin-regexp to ^0.12.0 (51ff304)
  • Update dependency eslint-plugin-regexp to ^0.13.0 (#36) (3a8d3ec), closes #36
  • Update dependency eslint-plugin-sonarjs to ^0.9.0 (81d9681)
  • Update dependency eslint-plugin-unicorn to v33 (bfa00ff)
  • Update dependency eslint-plugin-unicorn to v34 (#34) (86efbac), closes #34
  • Update dependency fs-extra to v10 (a0adecc)
  • Update dependency glob-parent to 5.1.2 [SECURITY] (c957512)
  • Update dependency husky to v7 (3578711)
  • Update dependency mocha to v8 (627a45b)
  • Update dependency mocha to v9 (93b7a17)
  • Update dependency nanoid to 3.1.31 [SECURITY] (#83) (89d3014), closes #83
  • Update dependency node-fetch to 2.6.7 [SECURITY] (#84) (11e82bc), closes #84
  • Update dependency nyc to v15 (1caf199)
  • Update dependency uuid to v8 (ebae34b)
  • update deps badge (0836169)
  • Update devDependencies (non-major) (01bd6c0)
  • Update devDependencies (non-major) (85a0161)
  • Update devDependencies (non-major) (609151a)
  • Update devDependencies (non-major) (5b1a6c3)
  • Update devDependencies (non-major) (51200bf)
  • Update devDependencies (non-major) (33211c3)
  • Update devDependencies (non-major) (#48) (b3f6184), closes #48
  • Update devDependencies (non-major) (#65) (d60ef28), closes #65
  • Update devDependencies (non-major) (#66) (69aac8f), closes #66
  • Update devDependencies (non-major) (#92) (f492769), closes #92
  • Update devDependencies (non-major) to v13 (6894ad9)
  • update eslint (6b174b1)
  • update eslint (4aac03c)
  • update eslint-config-incredible (2f39edb)
  • update eslint-config-incredible (58c31d2)
  • Update issue templates (8fdb1af)
  • update lock file (4ffb878)
  • Update pr template (1d4eb34)
  • update semantic release rules (a075dab)
  • update semantic to use commit convention (7e079b2)
  • Update semantic-release monorepo (b7ab2b1)
  • update travis badge (e159104)
  • updates semanticCommitType rule (1a1d119)
  • upgrade circle-ci to 2.1 (fab79a9)
  • upgrade semantic-release to v.19 [security] (0888454)
  • use danger for internall pr (d838ede)
  • use incredible eslint config (b03d74a)
  • use native tarball generation (eeefda5)
  • using static test entry (21e5b7d)

Docs

Fix

New