question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Reactions:19
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
mattjohnsonpintcommented, May 28, 2021

I can probably live with the multi-targeting if we have to…

I think that’s the right move.

0reactions
0xcedcommented, Jun 17, 2021

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 on DateOnly: 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 and TimeOnly types.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found