{"id":23564741,"url":"https://github.com/pr0ger/freezer","last_synced_at":"2025-04-30T16:19:52.999Z","repository":{"id":56911714,"uuid":"58331443","full_name":"Pr0Ger/Freezer","owner":"Pr0Ger","description":"Let your Swift tests travel through time","archived":false,"fork":false,"pushed_at":"2016-05-09T19:58:41.000Z","size":6,"stargazers_count":8,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T16:19:45.969Z","etag":null,"topics":["date","mocking","swift","testing"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pr0Ger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-08T21:08:10.000Z","updated_at":"2022-09-24T10:37:39.000Z","dependencies_parsed_at":"2022-08-21T03:20:15.365Z","dependency_job_id":null,"html_url":"https://github.com/Pr0Ger/Freezer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pr0Ger%2FFreezer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pr0Ger%2FFreezer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pr0Ger%2FFreezer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pr0Ger%2FFreezer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pr0Ger","download_url":"https://codeload.github.com/Pr0Ger/Freezer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251739717,"owners_count":21635903,"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":["date","mocking","swift","testing"],"created_at":"2024-12-26T17:17:28.688Z","updated_at":"2025-04-30T16:19:52.977Z","avatar_url":"https://github.com/Pr0Ger.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Freezer\nFreezer is a library that allows your Swift tests to travel through time by mocking `NSDate` class.\n\n## Usage\n\nOnce `Freezer.start()` has been invoked, all calls to `NSDate()` or `NSDate(timeIntervalSinceNow: secs)` will return the time that has been frozen.\n\n### Helper function\n\n```swift\nfreeze(NSDate(timeIntervalSince1970: 946684800)) {\n\tprint(NSDate()) // 2000-01-01 00:00:00 +0000\n}\n```\n\n### Raw usage\n\n```swift\nlet freezer = Freezer(to: NSDate(timeIntervalSince1970: 946684800))\nfreezer.start()\nprint(NSDate()) // 2000-01-01 00:00:00 +0000\nfreezer.stop()\n```\n\n### Time shifting\n\nFreezer will move you to a specified point in time, but then the time will keep ticking.\n\n```swift\ntimeshift(NSDate(timeIntervalSince1970: 946684800)) {\n\tprint(NSDate()) // 2000-01-01 00:00:00 +0000\n\tsleep(2)\n\tprint(NSDate()) // 2000-01-01 00:00:02 +0000\n}\n```\n\n### Nested calls\n\nFreezer allows performing nested freezing/shifts\n\n```swift\nfreeze(NSDate(timeIntervalSince1970: 946684800)) {\n\tfreeze(NSDate(timeIntervalSince1970: 946684000)) {\n\t\tfreeze(NSDate(timeIntervalSince1970: 946684800)) {\n\t\t\tprint(NSDate()) // 2000-01-01 00:00:00 +0000\n\t\t}\n\t\tprint(NSDate()) // 1999-12-31 23:46:40 +0000\n\t}\n\tprint(NSDate()) // 2000-01-01 00:00:00 +0000\n}\n```\n\n## Installation\n\n### CocoaPods\n\nJust add `pod 'Freezer', '~\u003e 1.0'` to your test target in `Podfile`.\n\n### Carthage\n\nThere is no Xcode project, so Carthage will not build a framework for this library. You can still use it, just add `github \"Pr0Ger/Freezer\" ~\u003e 1.0` to your `Cartfile` and then add `Carthage/Checkout/Freezer/freezer.swift` to your test target.\n\n### Manual\n\nJust copy freezer.swift to your Xcode project and add it to your tests target. Most likely this library will not be updated, unless Apple breaks something by changing an internal implementation of `NSDate`, so this way is good too.\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr0ger%2Ffreezer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpr0ger%2Ffreezer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr0ger%2Ffreezer/lists"}