https://github.com/maxkoshevoi/dateonlytimeonly.aspnet
Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET Core API
https://github.com/maxkoshevoi/dateonlytimeonly.aspnet
Last synced: 2 months ago
JSON representation
Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET Core API
- Host: GitHub
- URL: https://github.com/maxkoshevoi/dateonlytimeonly.aspnet
- Owner: maxkoshevoi
- License: mit
- Created: 2021-09-15T20:29:08.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-06-01T07:30:14.000Z (about 2 years ago)
- Last Synced: 2025-04-19T06:02:44.004Z (3 months ago)
- Language: C#
- Homepage:
- Size: 31.3 KB
- Stars: 120
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DateOnlyTimeOnly.AspNet
Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET Core API
## Installation
Get it from NuGet
- Base package: [](https://www.nuget.org/packages/DateOnlyTimeOnly.AspNet/)
- Swashbuckle support: [](https://www.nuget.org/packages/DateOnlyTimeOnly.AspNet.Swashbuckle/)## Usage
Call `AddDateOnlyTimeOnlyStringConverters` on `services`:
```cs
builder.Services.AddDateOnlyTimeOnlyStringConverters();
```After that:
- **For .NET 6**: all `DateOnly` and `TimeOnly` action arguments will be received and returned as ISO 8601 string;
- **For .NET 7**: adds support to use `TimeOnly` as Dictionary key (the rest is available out of the box).## Swagger support
### NSwag
No additional action is needed.
### Swashbuckle
#### v6.5.0 and after:
No additional action is needed.
#### Before v6.5.0:
Install `DateOnlyTimeOnly.AspNet.Swashbuckle` package, and add `UseDateOnlyTimeOnlyStringConverters` to your swagger configuration:
```cs
builder.Services.AddSwaggerGen(c => c.UseDateOnlyTimeOnlyStringConverters());
```