{"id":13412451,"url":"https://github.com/hako/durafmt","last_synced_at":"2025-10-06T21:51:12.720Z","repository":{"id":41142605,"uuid":"59328422","full_name":"hako/durafmt","owner":"hako","description":":clock8:  Better time duration formatting in Go! ","archived":false,"fork":false,"pushed_at":"2021-06-08T08:57:54.000Z","size":70,"stargazers_count":506,"open_issues_count":10,"forks_count":48,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-08-13T15:55:18.543Z","etag":null,"topics":["duration","fmt","formatter","go","golang","time"],"latest_commit_sha":null,"homepage":"","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/hako.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-20T21:49:33.000Z","updated_at":"2025-08-13T03:11:27.000Z","dependencies_parsed_at":"2022-09-21T01:10:31.928Z","dependency_job_id":null,"html_url":"https://github.com/hako/durafmt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hako/durafmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hako%2Fdurafmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hako%2Fdurafmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hako%2Fdurafmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hako%2Fdurafmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hako","download_url":"https://codeload.github.com/hako/durafmt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hako%2Fdurafmt/sbom","scorecard":{"id":453269,"data":{"date":"2025-08-11","repo":{"name":"github.com/hako/durafmt","commit":"5c1018a4e16b9db6718f25e524de025b1fc67303"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.2,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"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":"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":8,"reason":"Found 7/8 approved changesets -- score normalized to 8","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":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"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":"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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/hako/durafmt/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/hako/durafmt/test.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"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":"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":"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 29 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"}},{"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"}}]},"last_synced_at":"2025-08-19T08:45:48.755Z","repository_id":41142605,"created_at":"2025-08-19T08:45:48.755Z","updated_at":"2025-08-19T08:45:48.755Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278686638,"owners_count":26028325,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["duration","fmt","formatter","go","golang","time"],"created_at":"2024-07-30T20:01:24.816Z","updated_at":"2025-10-06T21:51:12.697Z","avatar_url":"https://github.com/hako.png","language":"Go","funding_links":[],"categories":["Go","Date and Time","日期和时间","日期和时间`用于处理日期和时间的库`","Date \u0026 Time","\u003cspan id=\"日期和时间-date-and-time\"\u003e日期和时间 Date and Time\u003c/span\u003e","Relational Databases","日期和時間"],"sub_categories":["Search and Analytic Databases","检索及分析资料库","Advanced Console UIs","SQL 查询语句构建库","高级控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高級控制台界面"],"readme":"# durafmt\n\n[![Build Status](https://travis-ci.org/hako/durafmt.svg?branch=master)](https://travis-ci.org/hako/durafmt) [![Go Report Card](https://goreportcard.com/badge/github.com/hako/durafmt)](https://goreportcard.com/report/github.com/hako/durafmt) [![codecov](https://codecov.io/gh/hako/durafmt/branch/master/graph/badge.svg)](https://codecov.io/gh/hako/durafmt) [![GoDoc](https://godoc.org/github.com/hako/durafmt?status.svg)](https://godoc.org/github.com/hako/durafmt) \n[![Open Source Helpers](https://www.codetriage.com/hako/durafmt/badges/users.svg)](https://www.codetriage.com/hako/durafmt)\n\n\n\ndurafmt is a tiny Go library that formats `time.Duration` strings (and types) into a human readable format.\n\n```\ngo get github.com/hako/durafmt\n```\n\n# Why\n\nIf you've worked with `time.Duration` in Go, you most likely have come across this:\n\n```\n53m28.587093086s // :)\n```\n\nThe above seems very easy to read, unless your duration looks like this:\n\n```\n354h22m3.24s // :S\n```\n\n# Usage\n\n### durafmt.ParseString()\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/hako/durafmt\"\n)\n\nfunc main() {\n\tduration, err := durafmt.ParseString(\"354h22m3.24s\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds\n\t// duration.String() // String representation. \"2 weeks 18 hours 22 minutes 3 seconds\"\n}\n```\n\n### durafmt.ParseStringShort()\n\nVersion of `durafmt.ParseString()` that only returns the first part of the duration string.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/hako/durafmt\"\n)\n\nfunc main() {\n\tduration, err := durafmt.ParseStringShort(\"354h22m3.24s\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(duration) // 2 weeks\n\t// duration.String() // String short representation. \"2 weeks\"\n}\n```\n\n### durafmt.Parse()\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"github.com/hako/durafmt\"\n)\n\nfunc main() {\n\ttimeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second)\n\tduration := durafmt.Parse(timeduration).String()\n\tfmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds\n}\n```\n\n#### LimitFirstN()\n\nLike `durafmt.ParseStringShort()` but for limiting the first N parts of the duration string.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"github.com/hako/durafmt\"\n)\n\nfunc main() {\n\ttimeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second)\n\tduration := durafmt.Parse(timeduration).LimitFirstN(2) // // limit first two parts.\n\tfmt.Println(duration) // 2 weeks 18 hours\n}\n```\n\n#### Custom Units\n\nLike `durafmt.Units{}` and `durafmt.Durafmt.Format(units)` to stringify duration with custom units.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"github.com/hako/durafmt\"\n)\n\nfunc main() {\n\ttimeduration := (354 * time.Hour) + (22 * time.Minute) + (1 * time.Second) + (100*time.Microsecond)\n\tduration := durafmt.Parse(timeduration)\n\t// units in portuguese\n\tunits, err := durafmt.DefaultUnitsCoder.Decode(\"ano,semana,dia,hora,minuto,segundo,milissegundo,microssegundo\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(duration.Format(units)) // 2 semanas 18 horas 22 minutos 1 segundo 100 microssegundos\n\n    // custom plural (singular:plural)\n\tunits, err = durafmt.DefaultUnitsCoder.Decode(\"ano,semana:SEMANAS,dia,hora,minuto,segundo,milissegundo,microssegundo\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(duration.Format(units)) // 2 SEMANAS 18 horas 22 minutos 1 segundo 100 microssegundos\n}\n```\n\n# Contributing\n\nContributions are welcome! Fork this repo, add your changes and submit a PR.\n\nIf you would like to fix a bug, add a feature or provide feedback you can do so in the issues section.\n\ndurafmt is tested against `golangci-lint` and you can run tests with `go test`. \n\nWhen contributing, running `go test; go vet; golint` or `golangci-lint` is recommended.\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhako%2Fdurafmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhako%2Fdurafmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhako%2Fdurafmt/lists"}