{"id":22065825,"url":"https://github.com/karenpayneoregon/dataonly-timeonly","last_synced_at":"2025-05-13T01:40:30.741Z","repository":{"id":45280639,"uuid":"413218457","full_name":"karenpayneoregon/dataonly-timeonly","owner":"karenpayneoregon","description":"Basic code samples for DateOnly and TimeOnly","archived":false,"fork":false,"pushed_at":"2022-12-27T15:11:28.000Z","size":216,"stargazers_count":3,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T05:41:25.432Z","etag":null,"topics":["csharp","dateonly","netcore6","timeonly"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karenpayneoregon.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-03T23:13:07.000Z","updated_at":"2024-06-11T18:39:54.000Z","dependencies_parsed_at":"2023-01-31T04:02:02.800Z","dependency_job_id":null,"html_url":"https://github.com/karenpayneoregon/dataonly-timeonly","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fdataonly-timeonly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fdataonly-timeonly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fdataonly-timeonly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fdataonly-timeonly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karenpayneoregon","download_url":"https://codeload.github.com/karenpayneoregon/dataonly-timeonly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856572,"owners_count":21974573,"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":["csharp","dateonly","netcore6","timeonly"],"created_at":"2024-11-30T19:22:12.121Z","updated_at":"2025-05-13T01:40:30.690Z","avatar_url":"https://github.com/karenpayneoregon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Working with DateOnly and TimeOnly (C#)\n\nThis repository demonstrates simple usage of [DateOnly Struct](https://docs.microsoft.com/en-us/dotnet/api/system.dateonly?view=net-6.0) done with a prerelease product.\n\nThere is a [class project](https://github.com/karenpayneoregon/dataonly-timeonly/blob/master/FileLibrary/Classes/Operations.cs) which is responsible for reading a json file with type Person class into a list using [System.Text.Json. JsonSerializer.Deserialize](https://docs.microsoft.com/en-us/dotnet/api/system.text.json?view=net-5.0). In the unit test project this data is tested as instances of the Person class.\n\n## Extension\n\nTo convert a DateOnly variable to a DateTime we use ToDateTime which requires a TimeOnly so to keep code light here is a lazy [extension](https://github.com/karenpayneoregon/dataonly-timeonly/blob/master/FileLibrary/LanguageExtensions/DateOnlyExtensions.cs) which default to mid-night or allows changing hours and/or minutes.\n\n```charp\npublic static DateTime ToDateTime(this DateOnly sender, int hour = 0, int minutes = 0)\n    =\u003e sender.ToDateTime(new TimeOnly(hour, minutes));\n```\n\n\n## Remarks\n\n- File scoped namespaces feature from C# 10 won't work\n- To use DateOnly and TimeOnly install [SDK 6x](https://dotnet.microsoft.com/download/dotnet/6.0?WT.mc_id=DT-MVP-5002866)\n- If using `VS2019` for desktop projects\n  - Set Use previews as shown in the image below\n  - Set `TargetFramework` to `net6.0-windows`\n\n```xml\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n  \u003cPropertyGroup\u003e\n\t  \u003cLangVersion\u003e9.0\u003c/LangVersion\u003e\n\t  \u003cTargetFramework\u003enet6.0-windows\u003c/TargetFramework\u003e\n  \u003c/PropertyGroup\u003e\n\n\u003c/Project\u003e\n```\n\n- Currently no code samples for [TimeOnly](https://docs.microsoft.com/en-us/dotnet/api/system.timeonly?view=net-6.0) which will follow shortly.\n\n## See also\n\n- [Developers can benefit from enhanced Date and Time types and Timezone support](https://github.com/dotnet/runtime/issues/45318)\n- NodaTime [ZonedDateTime](https://nodatime.org/2.4.x/api/NodaTime.ZonedDateTime.html)\n\n\n![img](assets/figure1.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fdataonly-timeonly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarenpayneoregon%2Fdataonly-timeonly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fdataonly-timeonly/lists"}