{"id":13527754,"url":"https://github.com/microsoft/clock","last_synced_at":"2025-04-01T09:32:02.567Z","repository":{"id":53606282,"uuid":"48821515","full_name":"microsoft/clock","owner":"microsoft","description":":clock4: Time utility with lovely mocking support","archived":true,"fork":false,"pushed_at":"2022-10-10T21:28:40.000Z","size":29,"stargazers_count":76,"open_issues_count":2,"forks_count":16,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-03-30T21:37:51.291Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/microsoft.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":"SECURITY.md","support":null}},"created_at":"2015-12-30T22:11:09.000Z","updated_at":"2025-01-28T09:48:17.000Z","dependencies_parsed_at":"2023-01-19T20:16:23.049Z","dependency_job_id":null,"html_url":"https://github.com/microsoft/clock","commit_stats":null,"previous_names":["watchbeam/clock","mixer/clock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fclock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fclock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fclock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fclock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/clock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246616382,"owners_count":20806125,"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-08-01T06:01:59.855Z","updated_at":"2025-04-01T09:32:02.225Z","avatar_url":"https://github.com/microsoft.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# clock [![GoDoc](https://godoc.org/github.com/mixer/clock?status.svg)](https://godoc.org/github.com/mixer/clock) [![Build Status](https://travis-ci.org/mixer/clock.svg)](https://travis-ci.org/mixer/clock)\n\nTime utility with lovely mocking support.\n\nThis is essentially a replacement for the `time` package which allows you to seamlessly swap in mock times, timers, and tickers. See the godocs (link above) for more detailed usage.\n\n### Example\n\n**hello.go**\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/mixer/clock\"\n)\n\nfunc main() {\n    fmt.Printf(\"the time is %s\", displayer{clock.C}.formatted())\n}\n\ntype displayer struct {\n    c clock.Clock\n}\n\nfunc (d displayer) formatted() string {\n    now := d.c.Now()\n    return fmt.Sprintf(\"%d:%d:%d\", now.Hour(), now.Minute(), now.Second())\n}\n```\n\n**hello_test.go**\n\n```go\npackage main\n\nimport (\n    \"testing\"\n    \"time\"\n\n    \"github.com/mixer/clock\"\n    \"github.com/stretchr/testify/assert\"\n)\n\nfunc TestDisplaysCorrectly(t *testing.T) {\n    date, _ := time.Parse(time.UnixDate, \"Sat Mar  7 11:12:39 PST 2015\")\n    c := clock.NewMockClock(date)\n    d := displayer{c}\n\n    assert.Equal(t, \"11:12:39\", d.formatted())\n    c.AddTime(42 * time.Second)\n    assert.Equal(t, \"11:13:21\", d.formatted())\n}\n```\n\n### API \u0026 Compatibility\n\nThe API provided by this package and the mock version is nearly identical to that of the `time` package, with two notable differences:\n - The channel for Ticker and Timer instances is accessed via the `.Chan()` method, rather than reading the `.C` property. This allows the structures to be swapped out for their mock variants.\n - The mock Ticker never skips ticks when time advances. This allows you to call `.AddTime`/`.SetTime` on the mock clock without having to advance to each \"ticked\" time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fclock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fclock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fclock/lists"}