The RIGHT way to deal with Date and Time in C#

preview_player
Показать описание

Hello everybody I'm Nick and in this video I will show you how you can use DateTime and DateTimeOffset correctly in your code, to make sure that it is testable. This is a technique that even Microsoft themselves are using and it is considered a best practice when dealing with time and date sensitive code.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet
Рекомендации по теме
Комментарии
Автор

I need that video about DateTime vs DateTimeOffset.

birdegop
Автор

This is exactly what I have in my projects but instead of DateTimeOffset, I'm using DateTime. Looking forward to see the comparison between them.

taipanprasithpongchai
Автор

Yes a video explaining the difference between DateTime and DateTimeOffset and Time and Timespan how Time zone is handled will be fine.

vertigosoft
Автор

As a senior C# developer, I must say, your videos are just awsome and professional.

johnny_rain
Автор

In a company I was working for a few years ago we used NodaTime and it worked just fine. It's like the implementation you showed but much more complete. It's a nuget package created by the one and only John Skeet :D

xcastor
Автор

@nick chapsas please make the video on the difference between datetime and datetimeoffset

Ubhaya
Автор

For sure want a video about DateTime vs DateTimeOffset. Good video as always!

andrewborges
Автор

love the additional context of different teams working on .NET solving the same problem over and over. it really demonstrates how common this problem is, and how practical it is to be using the same solution in our own code.

Zashxq
Автор

Nice vid, I do the same & is what Mark Seeman advocated for years ago on his old MS blog. One thing I like to do is make it an optional param and new up the default if not provided. This way I don't have to bother adding anything to DI and only pass in an non-default when testing.

davemasters
Автор

I would love a video on DateTime and DateTimeOffset and all the pitfalls developers commonly run into.

steveanon
Автор

Can't express how handy this has been. Thanks for making the video.

jcx-
Автор

Nice video, It would be interesting to see an example of how DateTimeOffset should be used in a database table to track events and if that is not enough in some scenarios (future events) then how to use NodaTime.

brunocandia
Автор

Nick, shouldn't that be 'public *sealed* class GreeterService' 😉

Great vid, looking forward to the DateTimeOffset video!

alexclark
Автор

Interesting. I find it simpler ( more simple?) to create an extension method on datetime/datetimepart. It's less code, just as testable and lends itself well to domain specific language.

stevehoff
Автор

I prefer a optional parameter using nullable datetimeoffset. If null, I default to system time. If used within the class, and scope of use is ok with a captured time at instanciation, then I can see this pattern as well

snapching
Автор

Such a small change, such a gain of testability.
Great as always, thank you so much.
And yes, please, please, please, show us, why it ist DateTimeOffset instead of just DateTime.

bbohac
Автор

Great video as always Nick!
Was also a pleasure meeting you at NDC (after the cruise) :)

ThePeebl
Автор

A very good example to show the advantages of D, Dependency inversion, from the SOLID principles.

Sergio_Loureiro
Автор

I've for a while struggled to wrap my mind around the differences between fake, mocks and stubs and when to use which one. Do you have any videos covering this in detail with examples, or do you plan on making one in the future?

TheMathias
Автор

It's like you reading my mind, was having trouble with dates and time. Thanks for the video

kelvin