{"id":18451831,"url":"https://github.com/peterhellberg/duration","last_synced_at":"2025-04-11T06:18:55.179Z","repository":{"id":33718215,"uuid":"37371956","full_name":"peterhellberg/duration","owner":"peterhellberg","description":"Parse a RFC 3339 duration string into time.Duration","archived":false,"fork":false,"pushed_at":"2022-11-29T17:07:15.000Z","size":20,"stargazers_count":30,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T04:13:09.659Z","etag":null,"topics":["duration-string","go","parser","rfc-3339"],"latest_commit_sha":null,"homepage":"https://tools.ietf.org/html/rfc3339","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/peterhellberg.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":"2015-06-13T13:12:42.000Z","updated_at":"2024-12-16T22:49:25.000Z","dependencies_parsed_at":"2023-01-15T02:11:53.862Z","dependency_job_id":null,"html_url":"https://github.com/peterhellberg/duration","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fduration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fduration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fduration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fduration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhellberg","download_url":"https://codeload.github.com/peterhellberg/duration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351649,"owners_count":21089318,"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":["duration-string","go","parser","rfc-3339"],"created_at":"2024-11-06T07:29:41.086Z","updated_at":"2025-04-11T06:18:55.148Z","avatar_url":"https://github.com/peterhellberg.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# :watch: duration\n\n[![Build status](https://github.com/peterhellberg/duration/actions/workflows/test.yml/badge.svg)](https://github.com/peterhellberg/duration/actions/workflows/test.yml)\n[![Go Report Card](https://goreportcard.com/badge/peterhellberg/duration)](https://goreportcard.com/report/peterhellberg/duration)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/peterhellberg/duration)\n[![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/peterhellberg/duration/blob/master/LICENSE)\n\nParse a [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) duration string into `time.Duration`\n\nThere are probably a few unsupported edge cases still to be fixed, please help me find them :)\n\nThe following constants are used to do the calculations for longer durations:\n\n```\nHoursPerDay = 24.0\nHoursPerWeek = 168.0\nHoursPerMonth = 730.4841667\nHoursPerYear = 8765.81\n```\n\nLook in the test for examples of both valid and invalid duration strings.\n\n## Installation\n\n    go get -u github.com/peterhellberg/duration\n\nFeel free to copy this package into your own codebase.\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/peterhellberg/duration\"\n)\n\nfunc main() {\n\tif d, err := duration.Parse(\"P1DT30H4S\"); err == nil {\n\t\tfmt.Println(d) // Output: 54h0m4s\n\t}\n}\n```\n\n## RFC3339 grammar for durations\n\n```\n   dur-second        = 1*DIGIT \"S\"\n   dur-minute        = 1*DIGIT \"M\" [dur-second]\n   dur-hour          = 1*DIGIT \"H\" [dur-minute]\n   dur-time          = \"T\" (dur-hour / dur-minute / dur-second)\n   dur-day           = 1*DIGIT \"D\"\n   dur-week          = 1*DIGIT \"W\"\n   dur-month         = 1*DIGIT \"M\" [dur-day]\n   dur-year          = 1*DIGIT \"Y\" [dur-month]\n   dur-date          = (dur-day / dur-month / dur-year) [dur-time]\n\n   duration          = \"P\" (dur-date / dur-time / dur-week)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fduration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhellberg%2Fduration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fduration/lists"}