Support conversion to/from DateOnly and TimeOnly
See original GitHub issue.NET 6 Preview 4 added DateOnly
and TimeOnly
structs. I would like to propose that Noda Time should support two-way conversion between DateOnly
and LocalDate
, and between TimeOnly
and LocalTime
.
public struct LocalDate
{
public static LocalDate FromDateOnly(DateOnly date);
public static LocalDate FromDateOnly(DateOnly date, CalendarSystem calendar);
public DateOnly ToDateOnly();
}
public struct LocalTime
{
public static LocalTime FromTimeOnly(TimeOnly time);
public TimeOnly ToTimeOnly();
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:19
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Converting DateOnly and TimeOnly to DateTime and vice ...
Converting DateTime to DateOnly and TimeOnly is very easy and simple and already well supported in library itself. Hope it is useful. Thanks...
Read more >How to use the DateOnly and TimeOnly structures
Use the following examples to learn about DateOnly : Convert DateTime to DateOnly; Add or subtract days, months, years; Parse and format ......
Read more >DateOnly And TimeOnly Types In .NET 6 : r/dotnet
But we didn't need that, all we did was comparison, conversion to/from DateTime and de/serialization. So instead we used 16-bit year, ...
Read more >I can't parse DateOnly type in .net 7 web api
AspNet package but didn't resolve my issue. still getting The JSON value could not be converted to DateOnly error. this is the payload...
Read more >Using DateOnly and TimeOnly in .NET 6 - Steve Gordon
Just as with DateOnly, we can convert from an existing DateTime into a TimeOnly using the FromDateTime static method. 1. 2. 3. var...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think that’s the right move.
I already have started experimenting with adding a
net6.0
target, you can have a look at my net6.0-DateOnly-TimeOnly branch.Currently, I have added the .NET 6.0 target framework and fixed all the nullability warnings that ensued. And in my last commit, I just implemented
public static LocalDate FromDateOnly(DateOnly date)
and an extension method onDateOnly
:public static LocalDate ToLocalDate(this DateOnly date) => LocalDate.FromDateOnly(date);
Now, many tests (1691) are failing on .NET 6.0 (same root cause related to building the time zone map) but that should probably be tracked in another issue since it’s completely unrelated to the new
DateOnly
andTimeOnly
types.