{"id":20526559,"url":"https://github.com/nikvoronin/json.timeinterval","last_synced_at":"2026-05-08T02:10:02.100Z","repository":{"id":190697644,"uuid":"683146241","full_name":"nikvoronin/Json.TimeInterval","owner":"nikvoronin","description":"Extends System.Text.Json with a custom new TimeInterval type.","archived":false,"fork":false,"pushed_at":"2023-08-27T07:51:00.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T11:27:05.019Z","etag":null,"topics":["converter","csharp","dotnet","json","system-text-json","timespan"],"latest_commit_sha":null,"homepage":"","language":"C#","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/nikvoronin.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-25T17:57:48.000Z","updated_at":"2023-10-23T00:52:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bc42c9d-4e31-4187-888d-39df4ba0e4c2","html_url":"https://github.com/nikvoronin/Json.TimeInterval","commit_stats":null,"previous_names":["nikvoronin/json.timeinterval"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2FJson.TimeInterval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2FJson.TimeInterval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2FJson.TimeInterval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2FJson.TimeInterval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikvoronin","download_url":"https://codeload.github.com/nikvoronin/Json.TimeInterval/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242133430,"owners_count":20077095,"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":["converter","csharp","dotnet","json","system-text-json","timespan"],"created_at":"2024-11-15T23:14:43.975Z","updated_at":"2026-05-08T02:09:57.057Z","avatar_url":"https://github.com/nikvoronin.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Json.TimeInterval\n\nExtends `System.Text.Json` with a custom new `TimeInterval` type. Be aware, it is implemented for deserialization or read only!\n\n```json\n{\n    \"TheDevice\": {\n        \"Timeout\": \"3s\",\n        \"PollingInterval\": \"500ms\",\n        \"RefreshTokenEvery\": \"1h 15m\"\n    }\n}\n```\n\n## Format\n\nUse string quotes `\"\"` to decorate values:\n\n```json\n\"KeyName\": \"1500ms\"\n```\n\n- Only unsigned integer values for time units.\n- Possible delimeters: `- _:/'` (space included).\n- `\"3m 1h 2m\"` is equivalent to `\"1h 5m\"`. Identical time units are sum up: `3m + 2m = 5m`.\n- System TimeSpan is allowable, so `\"00:01:02:000\"` is equivalent to `\"1h 2m\"`.\n\n### Examples\n\n- \"1h34m26s134ms\"\n- \"1h 12m127s\"\n- \"1d/12h 15m 7s\"\n- \"3d/12h_15m:12s---347ms\"\n\n## How to use\n\n```csharp\npublic class MyClass_ToDeserializeJson\n{\n    public Device TheDevice {get; set;}\n\n    public class Device \n    {\n        public TimeInterval Timeout {get; set;}\n            = TimeSpan.FromSeconds( 3 );\n\n        public TimeInterval PollingInterval {get; set;}\n            = TimeSpan.FromMilliseconds( 500 );\n\n        public TimeInterval RefreshTokenEvery {get; set;}\n            = TimeSpan.FromHours( 1 )\n            + TimeSpan.FromMinutes( 15 ) );\n    }\n}\n\n...\n\npublic async Task Main()\n{\n    TimeSpan pollingInterval =\n        // Use streams not strings! This is just a short example.\n        JsonSerializer.Deserialize\u003cMyClass_ToDeserializeJson\u003e(\n            File.ReadAllText( \"./devsettings.json\" ) )\n        .TheDevice\n        .PollingInterval;\n\n    while (!Console.KeyAvailable) {\n        Debug.Write(\".\")\n        await Task.Delay( pollingInterval );\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikvoronin%2Fjson.timeinterval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikvoronin%2Fjson.timeinterval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikvoronin%2Fjson.timeinterval/lists"}