Timemachine is a JavaScript utility designed to facilitate testing of time-dependent applications by overriding the native `Date` object. The package is currently at version 0.3.2, with its last known publication being over six years ago, indicating an abandoned status. It provides a straightforward API to configure a specific date, timestamp, or a time offset, and can optionally simulate a continuously ticking clock, which is useful for testing dynamic time displays or intervals. A key differentiator for Timemachine is its broad compatibility, supporting global namespaces, RequireJS, CommonJS, and NodeJS environments, making it suitable for older or mixed JavaScript projects. Its core functionality involves directly monkey-patching the global `Date` constructor and its prototypes, allowing for precise control over time within test scenarios where time manipulation is critical.
npm install timemachineVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure Timemachine to a specific date, show its effect, and then reset to native time.
Consider migrating to actively maintained alternatives like `jest.useFakeTimers()` (for Jest), `@sinonjs/fake-timers`, or `date-fns` for robust date manipulation without monkey-patching.
Always ensure to call `timemachine.reset()` after your time-sensitive operations to restore the native `Date` behavior and prevent leaks between tests. Isolate tests to prevent interference.
Carefully test its behavior in your specific environment. For ESM, you might need bundler configurations for CommonJS interop. Modern alternatives often offer better compatibility.
Install via npm (`npm install timemachine`) if you still need to use this package, but again, consider alternatives.
Ensure `require('timemachine')` is executed and assigned, or that the script loading the library has completed in a browser environment before attempting to call its methods.Review your test setup for other time-mocking libraries. Ensure `timemachine.reset()` is called in an `afterEach` or `afterAll` hook in your test framework to clean up state.
No dependency data recorded yet.