{"id":18483379,"url":"https://github.com/guidesmiths/groundhog-day","last_synced_at":"2025-07-27T00:40:21.746Z","repository":{"id":57254384,"uuid":"64251185","full_name":"guidesmiths/groundhog-day","owner":"guidesmiths","description":"An injectable clock for time based tests","archived":false,"fork":false,"pushed_at":"2024-12-19T04:07:24.000Z","size":139,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-01-25T18:15:22.037Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guidesmiths.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-26T20:11:42.000Z","updated_at":"2024-12-19T04:07:24.000Z","dependencies_parsed_at":"2022-08-31T09:00:13.479Z","dependency_job_id":null,"html_url":"https://github.com/guidesmiths/groundhog-day","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidesmiths%2Fgroundhog-day","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidesmiths%2Fgroundhog-day/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidesmiths%2Fgroundhog-day/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidesmiths%2Fgroundhog-day/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guidesmiths","download_url":"https://codeload.github.com/guidesmiths/groundhog-day/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239200793,"owners_count":19599068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T12:35:32.434Z","updated_at":"2025-02-16T21:29:38.007Z","avatar_url":"https://github.com/guidesmiths.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# groundhog-day\n\ngroundhog-day is a wrapper around ```Date.now()``` with real and fake implementations. The real implementation returns the current time, the fake implementation returns a fixed time (defaults to Groundhog day). Use the real implementation in your production code, but inject the fake implementation in tests for predictable results.\n\n[![NPM version](https://img.shields.io/npm/v/groundhog-day.svg?style=flat-square)](https://www.npmjs.com/package/groundhog-day)\n[![NPM downloads](https://img.shields.io/npm/dm/groundhog-day.svg?style=flat-square)](https://www.npmjs.com/package/groundhog-day)\n[![Node.js CI](https://github.com/guidesmiths/groundhog-day/workflows/Node.js%20CI/badge.svg)](https://github.com/guidesmiths/groundhog-day/actions?query=workflow%3A%22Node.js+CI%22)\n[![Code Climate](https://codeclimate.com/github/guidesmiths/groundhog-day/badges/gpa.svg)](https://codeclimate.com/github/guidesmiths/groundhog-day)\n[![Test Coverage](https://codeclimate.com/github/guidesmiths/groundhog-day/badges/coverage.svg)](https://codeclimate.com/github/guidesmiths/groundhog-day/coverage)\n\n## TL;DR\n\n### 1. Use a fake clock in tests\n```js\nconst { ok, equal } = require('assert');\nconst { fake: clock } = require('groundhog-day');\nconst request = require('request');\nconst Server = require('../server');\n\ndescribe('Server', () =\u003e {\n\n  let server\n\n  before((done) =\u003e {\n    server = new Server(clock);\n    server.start(done);\n  });\n\n  after((done) =\u003e {\n    server.stop(done);\n  });\n\n  it('should set last modified header', (done) =\u003e {\n    request.get('http://localhost/demo', (err, res, body) =\u003e {\n      ok(err);\n      equal(res.headers['last-modified'], 'Tue, 2 Feb 2016 11:00:00 GMT');  // Groundhog Day\n    })\n  })\n})\n```\n\n### 2. Use a real clock in production\n```js\nconst Server = require('./server')\nconst { real: clock } = require('groundhog-day');\nnew Server(clock).start(err =\u003e {\n  if (err) process.exit(1)\n  console.log('Listening')\n})\n```\n\n### Fixing Time\nYou can configure the fixed time returned by the fake clock in any of the following ways:\n\nBy specifying the number of milliseconds\n```js\nconst { fake: clock } = require('groundhog-day');\nclock.fix(1469563181761);\n```\n\nBy specifying a date instance\n```js\nconst { fake: clock } = require('groundhog-day');\nclock.fix(new Date(1469563181761));\n```\n\nBy specifying a date string\n```js\nconst { fake: clock } = require('groundhog-day');\nclock.fix(new Date('2016-07-26T19:59:41.761Z'))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidesmiths%2Fgroundhog-day","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguidesmiths%2Fgroundhog-day","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidesmiths%2Fgroundhog-day/lists"}