Hey everyone π
I wanted to share a little library Iβve been building lately, called timewarp-sim
. If youβve ever had to test date logic or simulate time passing, you know how frustrating it can be. You either end up waiting forever, fiddling with your system clock, or writing tons of brittle mocks.
timewarp-sim solves this cleanly by giving you a deterministic time machine for your JavaScript and TypeScript code.
β¨ What does it do?
β
Freeze time at a specific moment
β
Advance time however you like (seconds, hours, even decades)
β
Travel to any timestamp instantly
β
Globally mock Date.now()
and new Date()
so all your dependencies see the same simulated clock
β
Register hooks to react whenever time changes
β
Unfreeze and return to real time anytime
π‘ Why should you care?
If you work on:
- Session or token expiration logic
- Caching and TTL validation
- Recurring jobs (cron-like scheduling)
- Billing or subscription renewals
- Reports that aggregate data by date
- Anything else where time matters
β¦this tool can save you hours of debugging and testing.
You no longer have to wait for timeouts to expire or write fragile setTimeout
hacks- just jump forward in time with a single line of code.
β‘ Quick Example
import { Timewarp } from "timewarp-sim";
console.log("Real time:", new Date());
Timewarp.freeze();
console.log("Frozen:", Timewarp.now());
Timewarp.enableGlobalMocking();
console.log("Mocked Date.now():", Date.now());
Timewarp.advance(60 * 60 * 1000);
console.log("After 1 hour:", new Date());
Timewarp.travelTo(new Date("2040-01-01T00:00:00Z"));
console.log("Traveled to:", new Date());
Timewarp.unfreeze();
Timewarp.disableGlobalMocking();
console.log("Back to real time:", new Date());
π Get Involved
timewarp-sim is open source, and Iβd love to see it grow with help from the community!
π β Star the project on GitHub
π Open issues for bugs or feature ideas
π Contribute code if you want to make it even better
If you find it useful, share it with your teammates or that friend who still uses setTimeout(999999999)
to simulate waiting.
Top comments (1)