{"id":13413928,"url":"https://github.com/cabify/timex","last_synced_at":"2026-01-17T08:48:32.999Z","repository":{"id":57507779,"uuid":"231434301","full_name":"cabify/timex","owner":"cabify","description":"A test-friendly replacement for golang's time package [managed by soy-programador]","archived":false,"fork":false,"pushed_at":"2020-08-03T08:54:37.000Z","size":24,"stargazers_count":71,"open_issues_count":1,"forks_count":5,"subscribers_count":81,"default_branch":"master","last_synced_at":"2025-02-25T13:56:09.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cabify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-01-02T18:06:48.000Z","updated_at":"2025-01-07T10:06:25.000Z","dependencies_parsed_at":"2022-09-26T17:50:46.408Z","dependency_job_id":null,"html_url":"https://github.com/cabify/timex","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/cabify/timex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cabify%2Ftimex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cabify%2Ftimex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cabify%2Ftimex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cabify%2Ftimex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cabify","download_url":"https://codeload.github.com/cabify/timex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cabify%2Ftimex/sbom","scorecard":{"id":261378,"data":{"date":"2025-08-11","repo":{"name":"github.com/cabify/timex","commit":"9b786c3d592fa976ac5fc0ba7861322d0e9b6f29"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":2,"reason":"Found 2/8 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T10:55:05.077Z","repository_id":57507779,"created_at":"2025-08-17T10:55:05.077Z","updated_at":"2025-08-17T10:55:05.077Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28504509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T06:57:29.758Z","status":"ssl_error","status_checked_at":"2026-01-17T06:56:03.931Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-07-30T20:01:52.909Z","updated_at":"2026-01-17T08:48:32.958Z","avatar_url":"https://github.com/cabify.png","language":"Go","readme":"# `timex`\n\n[![Build Status](https://travis-ci.org/cabify/timex.svg?branch=master)](https://travis-ci.org/cabify/timex)\n[![Coverage Status](https://coveralls.io/repos/github/cabify/timex/badge.svg?branch=master)](https://coveralls.io/github/cabify/timex?branch=master)\n[![GoDoc](https://godoc.org/github.com/cabify/timex?status.svg)](https://godoc.org/github.com/cabify/timex)\n\n`timex` is a test-friendly replacement for the `time` package.\n\n## Usage \n\nJust replace your `time.Now()` by a `timex.Now()` call, etc.\n\n## Mocking \n\nUse `timex.Override(...)` to replace the current implementation by another one, and use the function it returns to restore the default implementation. You can't override from several tests at the same time. You can use an auto-generated by [`mockery`][mockery] mock from `timexmock` package, or a controlled implementation from `timextest`.\n\n### `timexmock`\n\nThere's a `timexmock.Mocked(func(mocked *timexmock.Implementation) { ... })` wrapper that automatically creates a mock, sets it as the implementation to be used and defers a tear down to set the default implementation again.\n\nExample:\n\n```go\nfunc TestSleep(t *testing.T) {\n\ttimexmock.Mocked(func(mocked *timexmock.Implementation) {\n\t\tmocked.On(\"Sleep\", someDuration).Once()\n\t\tdefer mocked.AssertExpectations(t)\n\n\t\ttimex.Sleep(someDuration)\n\t})\n}\n```\n\n### `timextest`\n\nTimextest provides a more complex API useful to control the behavior of concurrent programs, it is especially useful when the code interacts with timers like `time.Ticker`. Just like `timexmock`, `timextest` also provides a `timextest.Mocked(time.Time, func(*TestImplementation))` function to make mocking easier. Few examples can be found in [`timextest/example_test.go`](./timextest/example_test.go), this is one of them:\n\n```go\nfunc ExampleTestImplementation_NewTicker() {\n\ttimextest.Mocked(now, func(mockedtimex *timextest.TestImplementation) {\n\t\tgo func() {\n\t\t\tticker := timex.NewTicker(time.Hour)\n\t\t\tfor t := range ticker.C() {\n\t\t\t\tfmt.Printf(\"%s\\n\", t)\n\t\t\t}\n\t\t}()\n\n\t\ttickerCall := \u003c-mockedtimex.NewTickerCalls\n\t\ttickerCall.Mock.Tick(now.Add(time.Second))\n\t\ttickerCall.Mock.Tick(now.Add(2 * time.Second))\n\n\t\t// Output:\n\t\t// 2009-11-10 23:00:01 +0000 UTC\n\t\t// 2009-11-10 23:00:02 +0000 UTC\n\t})\n}\n```\n\n## Drawbacks\n\n### Performance\n\nThere's an obvious performance impact caused by the indirection of the call, it's actually 20-30% slower, however, in absolute numbers we're talking about 30 nanoseconds per call, so you probably should not worry about that. Notice that the difference is so small that it's not easy to get a stable result.\n\n```\n$ go test -run=NONE -benchmem -benchtime=5s -bench=. .\ngoos: darwin\ngoarch: amd64\npkg: github.com/cabify/timex\nBenchmarkTimeNow-4    \t49619665\t       112 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkTimexNow-4   \t41256012\t       145 ns/op\t       0 B/op\t       0 allocs/op\n```\n\nIf you're really worried about performance, you can disable part of the indirection by compiling with `timex_disable` tag, which will provide results similiar to the native implemenation calls:\n\n```\n$ go test -run=NONE -benchmem -benchtime=5s -bench=. -tags=timex_disable .\ngoos: darwin\ngoarch: amd64\npkg: github.com/cabify/timex\nBenchmarkTimeNow-4    \t49866967\t       116 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkTimexNow-4   \t47965780\t       109 ns/op\t       0 B/op\t       0 allocs/op\n```\n\n### Dogma\n\nOh... yes, we're changing global variables and we'll obviously burn in hell, but if you're really into DI, you can also accept `timex.Implementation` interface as a dependency, and then inject either `timex.Default{}` or a testable implementation.\n\n[mockery]: https://github.com/vektra/mockery\n","funding_links":[],"categories":["测试相关","Testing","测试","Go","Template Engines","测试相关`测试库和测试数据集生成库`","Mock"],"sub_categories":["查询语","HTTP Clients","HTTP客户端","Mock"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcabify%2Ftimex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcabify%2Ftimex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcabify%2Ftimex/lists"}