The Problem with Time That .NET 8 Finally Fixed

Поділитися
Вставка
  • Опубліковано 11 жов 2024
  • Check out my courses: dometrain.com
    Become a Patreon and get source code access: / nickchapsas
    Hello everybody I'm Nick, and in this video, I will introduce you to the brand new .NET 8 type, called TimeProvider, which aims to solve a problem that has been in .NET since its inception.
    Workshops: bit.ly/nickwor...
    Don't forget to comment, like and subscribe :)
    Social Media:
    Follow me on GitHub: bit.ly/ChapsasG...
    Follow me on Twitter: bit.ly/ChapsasT...
    Connect on LinkedIn: bit.ly/ChapsasL...
    Keep coding merch: keepcoding.shop
    #csharp #dotnet

КОМЕНТАРІ • 192

  • @nickchapsas
    @nickchapsas  Рік тому +49

    Ignore the fact that in this example this code is running on the server. It's irrelevant to the point of this video. It could be a CLI tool or a Blazor Server app that runs locally as a Dektop app with Electron. Focus on the Time point.

    • @greysontyrud
      @greysontyrud Рік тому +5

      did you post the link you mention at 7:09?

  • @clayMeisman
    @clayMeisman Рік тому +103

    Can you please make a video about the datetimeoffset and why it's better over datetime?

    • @proosee
      @proosee Рік тому

      @Dionte Smith in simple scenarios like you've just described it doesn't matter much.

    • @dputra
      @dputra Рік тому

      Working in a company that employs employees in several timezones, having the timezone instead of using UTC built in could provide extra context. Is it created in the morning of creator's time? Is it edited in the afternoon of the editor's time?
      Without that, you have to lookup each users's timezone. Not very ideal if your employees crossing timezones frequently.
      And yes, it's not for everyone. If you are happy with UTC datetime, then use it.

  • @Shadow_Play3r
    @Shadow_Play3r Рік тому +168

    DateTimeOffset vs DateTime has always confused me. Some teams have contracts with offset others with stock.

    • @pilotboba
      @pilotboba Рік тому

      DateTimeOffset is an unambiguous point in time where DateTime combines with the Kind property. So if you are trying to do the right thing and always use UtcNow() but you store it in a Datetime and don't set the Kind to UTC, some date/time conversions (like serialization) might not give you the results you expect.
      I think DateTimeOffset is more precise than Datetime as well.

    • @billy65bob
      @billy65bob Рік тому

      You can feed dates with a time zone offset into a DateTime just fine, It'll localise it to the same instant in the local timezone with the proper DateTimeKind set.
      Whether the respects the Kind is a different matter alltogether (usually the answer is no)
      When it comes to data structures, when you care for the TimeZone (e.g. for localisation), you will generally use DateTimeOffset over DateTime. Unfortunately it's not always the case.

    • @AbrahamWilson
      @AbrahamWilson Рік тому +18

      This. Please make a video on this.

    • @y.katlego
      @y.katlego Рік тому

      Same

  • @morganishere123
    @morganishere123 Рік тому +17

    I'd created a IDateTimeProvider very similarly to the ISystemClock as you've referenced. I really like how they've put some of the Stopwatch functionality in this new TimeProvider class; it should make asserting time differences easier in unit tests (E.g. when you log how long a service took to run)

  • @ernest1520
    @ernest1520 Рік тому +28

    It's good that they provide some framework-level time dependency like this. However, due to the issues that you just showed with setting up a mock, I'd rather stick to my custom IDateTimeProvider. What the team behind it should do is to provide an interface for the TimeProvider.

  • @madsxcva
    @madsxcva Рік тому +21

    I treated DateTime variables as external dependencies (since they are when they are based on system time) and as consequence I would want to receive DateTime as a parameter. in the video example the endpoint would have a date parameter that then would be passed to the method

    • @maxbradley9534
      @maxbradley9534 Рік тому

      Sure but then you are just passing the problem up the chain. Now that method that passes in the DateTime is not testable.

    • @madsxcva
      @madsxcva Рік тому

      @@maxbradley9534 I am passing the responsibility to provide the date to the end user. That doesnt make the method non testable, on the contrary it makes the method that exists testable, because any unit test that uses DateTime.Now or other methods that rely on external resources should be considered failed tests . I can change the machine time and make it output whatever i want, thus the test is not consistent and is a bad test.

    • @benjamininkorea7016
      @benjamininkorea7016 Рік тому +2

      @@madsxcva Eh? So when you're unit testing, you prefer to sit there for 24 hours? Because "consistent" time runs at a rate of 1 second per second.

  • @TheBuzzSaw
    @TheBuzzSaw Рік тому +38

    Since .NET 8 is far from finalized, the team should be made aware that this design is highly suspect.

  • @silentdebugger
    @silentdebugger Рік тому +9

    I went even further beyond and created a TimeProvider interface which provides an overridable definition of Delay() (to replace Task.Delay()) so I can do deterministic unit testing of time-dependent code - for example I can make a unit test for "does a token expire from the token cache after 24 hours" just by fast-forwarding simulated time

    • @desertfish74
      @desertfish74 Рік тому

      This is a great application for this

    • @ashbjorn
      @ashbjorn Рік тому +1

      For my curiosity, how would it be any different than providing an instance of your interface where 24 hours would already have passed?

    • @oleggavrilov7083
      @oleggavrilov7083 Рік тому

      Can you throw a quick example of your test and that TimeProvider? Github gist would be great

  • @conway9214
    @conway9214 Рік тому +12

    Looking forward for the DateTime vs DateTimeOffset video 🎉

  • @frankhaugen
    @frankhaugen Рік тому +14

    I would have preferred a minimalistic interface, but I followed the discussion as it was streamed on youtube, and I get why it is the way it is

    • @SamMackrill
      @SamMackrill Рік тому +1

      Do expand a bit please

    • @ProfessorCodemunkie
      @ProfessorCodemunkie Рік тому +9

      Do you have a link to this discussion please?

    • @frankhaugen
      @frankhaugen Рік тому

      @@ProfessorCodemunkie ua-cam.com/video/KVDnUSH90qI/v-deo.html

    • @Ju57u5
      @Ju57u5 Рік тому

      @@ProfessorCodemunkie ua-cam.com/video/KVDnUSH90qI/v-deo.htmlh34m27s

    • @ashbjorn
      @ashbjorn Рік тому

      I believe AftercastGames is referring to this link? ua-cam.com/video/WW65sGkDINQ/v-deo.html
      Edit: Seems this is a link to when the discussion was a bit older, but still relevant imo.

  • @ricmrodrigues
    @ricmrodrigues Рік тому +1

    I've implemented this before as ambient context with a good default, such as the one you're using there, given it's a cross cutting, basic concern. Still solves it but no need to inject it everywhere.

  • @Saiyugi16
    @Saiyugi16 Рік тому +7

    Re: DateTimeOffset vs DateTime I would appreciate to hear your perspective on the reason for which is better

  • @T___Brown
    @T___Brown Рік тому +21

    Its better to have an excuse why i cant do a unit test

  • @billy65bob
    @billy65bob Рік тому +4

    There's so much they can do with the built in DateTime object too with respect to its Kind, they could genuinely make it intuitive, but I don't expect them to because of legacy concerns.
    DateTime uses its Kind wrong in almost every single context; it cares about it when you don't, it disregards it when you care about it, and it makes ridiculous assumptions when you don't have one.

  • @ivanbanov8939
    @ivanbanov8939 Рік тому +1

    They have also added a class called FakeTimeProvider to Microsoft.Extensions.Time.Testing which makes mocking a lot easier.

  • @diadetediotedio6918
    @diadetediotedio6918 Рік тому +14

    What we need now is a abstraction layer for file system, it would make possible some very interesting things like some tests for file system operations

    • @bomret
      @bomret Рік тому +9

      There already is System.IO.Abstractions

    • @adrian_franczak
      @adrian_franczak Рік тому

      @@bomret isnt this 3rd party lib?

    • @bomret
      @bomret Рік тому +2

      @@adrian_franczak yes. But it’s been around for more than a decade and is very widely used.

  • @Vespura_
    @Vespura_ Рік тому +4

    Please make a video about datetimeoffset!

  • @petrzurek5713
    @petrzurek5713 Рік тому +6

    The best channel for .NET enthusiasts, keep on going mate 🦾

  • @AftercastGames
    @AftercastGames Рік тому +1

    This is pretty similar to what I do already. Although I take a much simpler approach and have one source class for all of my time related events, and I have multiple classes that listen to those events and then notify other classes that they need to perform specific functions. No interfaces necessary.

  • @sajagjain7169
    @sajagjain7169 Рік тому +4

    Why should we use date time offset? Can you please make a video?

    • @adrian_franczak
      @adrian_franczak Рік тому

      its important if your app is dealing with different timezones and storing everything as UTC will be confusing for user (summer/winter time)

  • @DeserdiVerimas
    @DeserdiVerimas Рік тому +86

    This should totally have been an interface, that mocking setup is complicated.

    • @modernkennnern
      @modernkennnern Рік тому

      On the GitHub PR there's a link to a 1.5hr UA-cam video that - somewhere in it - contains an argument as to why it's not.
      If you can find it, please link it to me :p.. I saw the PR yesterday during break and I forgot about it

    • @garcipat
      @garcipat Рік тому +4

      Agree 100%, this is ugly.

    • @jonathansaindon788
      @jonathansaindon788 Рік тому +2

      Absolutely! I dont think the setup would be that much different tough…

    • @carl-henrikkristoffersen2313
      @carl-henrikkristoffersen2313 Рік тому +1

      It's not that bad imo, pretty much anything you'd mock ends up being messy. Unless it's super simple unit tests.

    • @Ju57u5
      @Ju57u5 Рік тому +1

      They will very likely provide a fake class so you won't need to mock it anyway and just use their implementation.

  • @sunilanthony17
    @sunilanthony17 Рік тому

    It's like you're reading my mind. I'm currently working with datetime logic and had to write a time wrapper so I can unit test it. Mind is also an abstract class..

  • @brucerosner3547
    @brucerosner3547 Рік тому +1

    Much ado about about the obvious. Over 30 years ago I was writing business programs in Fortran. It was clear then that the date and time printed on business reports sometimes need be independent of the current computer clock. Viola write a layer to provide times. I'm sure there is some "gang of four" jargon for this approach but it is something any decent programmer should know intuitively.

  • @diadetediotedio6918
    @diadetediotedio6918 Рік тому +1

    I was using an interface with basically the same name of .NET 8, it was ITimeProvider, in general I think interfaces can be better but an abstract class is still valid

  • @zagoskintoto
    @zagoskintoto Рік тому

    Love the vid. I'm really bad with dates, timestamps, etc. Glad to have content on this and hoping for more!

  • @yurii1111
    @yurii1111 Рік тому +1

    It feels that this provider lacks the interface segregation principle. It contains several different features that may be split into multiple interfaces. From the usage perspective it will be much more obvious, as now it looks similar to a service locator (anti-?)pattern.

  • @Kirides
    @Kirides Рік тому +4

    using an abstract class allows them to add more and more methods to the TimeProvider without breaking all existing software unlinke an interface.
    its the same with DbConnection vs IDbConnection.

    • @nickchapsas
      @nickchapsas  Рік тому +5

      But that's why they added default implementations in interfaces in C# 8

    • @Kirides
      @Kirides Рік тому

      @@nickchapsas default interface implementations allow for "multiple inheritance" and are limited to only function if the caller explicitly invokes the methods on the interface, you can't use them on the concrete types that implement the interface

    • @Ju57u5
      @Ju57u5 Рік тому

      ​@@nickchapsas I think those don't work because they are planning to ship it down level.

  • @xq_nemesis
    @xq_nemesis Рік тому +2

    Please make a video on why to use DateTimeOffset ❤

  • @pawefelcyn2119
    @pawefelcyn2119 Рік тому +1

    Please, make a video about why we should use DateTimeOffset

  • @harriehausenman8623
    @harriehausenman8623 Рік тому +6

    This has never been a problem in any big consulting firm:
    Just test it 3 times a day! 🤣
    jokes aside: thanks for the update, great video as usual 🤗

  • @jcmorin2007
    @jcmorin2007 Рік тому +1

    I agree that it should be an Interface!

  • @antonmartyniuk
    @antonmartyniuk Рік тому +1

    It also took them 20 years to create a file-scoped namespaces. This tiny little code formatting feature should have been done like 10 years ago

  • @tomheijtink8688
    @tomheijtink8688 Рік тому +2

    I had rather that they created their own nodatime variation. Even with a type to store time zone and version and hook it up with EF core to make some geolocation based time calculations. It’s quite a lot of work to maintain and a consistent code base with different time zones and versions.

    • @quetzalcoatl-pl
      @quetzalcoatl-pl Рік тому

      Yeah. And most probably that's exactly why they did not.

  • @Bliss467
    @Bliss467 Рік тому +1

    I generally prefer using minus operator for getting elapsed time so I’d like to see that with the timers but since c# requires operators be defined statically you wouldn’t be able to mock it ☹️

  • @stoorps
    @stoorps Рік тому +2

    They probably used an abstract rather than an interface with default implementations for backwards compatibility with netstandard2.0, which doesn't support default implementations for interfaces.

  • @truman5652
    @truman5652 Рік тому +1

    The main bug with time - it's how the time was implemented in real world. I mean timezones and local times. All of us have common time and we need to use one time for all areas of the world, then million of time issues will be solved. Morning, Day, Evening, Night will have own time range for each area, but time should be equal in any point of the Earth.

  • @tanglesites
    @tanglesites Рік тому +1

    That’s cool. But passing the frequency in, doesn’t that make it system dependent as well? Or did I did not understand that right? Awesome content. As always.

  • @awmy3109
    @awmy3109 Рік тому +2

    Why is generate greeting not taking the date time as a parameter?
    I don't use DateTimeOffset because I convert all dates to UTC in my systems before storage and all processing and computation is done in UTC. Conversion to local time is only done during presentation in the UI. DateTimeOffset is only needed when you want to store time with an offset that is not zero. UTC's offset is zero.

    • @nickchapsas
      @nickchapsas  Рік тому +3

      So you don’t care about the user’s offset from utc? For example when you wanna email all users during their morning hours to improve email opening rates, how do you know what is "morning" for them when there is no UI or client? Storing everything is UTC out of context is naive

    • @awmy3109
      @awmy3109 Рік тому

      @@nickchapsas I store the user's actual desired timezone in a database field that they can always change later. That's what I use to accept datetime from them and convert to UTC using TimeZoneInfo.ConvertTimeToUtc()
      before saving. Also when displaying, or doing something like the email you talked about, I use their stored timezone to convert from UTC to their desired timezone.
      One major advantage of converting to UTC before saving in database is that you are never affected by daylight savings changes. Also computation or filtering data based on time is easier because they are all stored in UTC.

  • @TuxCommander
    @TuxCommander Рік тому

    Please consider your (maybe our) wish for an ITimeProvider interface.
    If they do it, this will obsolete all our nice homebrew stuff.
    The timeprovider is nice, but I'll stay with my custom interface for now.
    At least we can note that they addressed the issue.

  • @abdifatahAnnaati
    @abdifatahAnnaati Рік тому

    When it comes to DateTime, every language/Framework out there has it's own ups & downs. I usually depend on My won Custom Class/Interfaces/Services but it a bit confusing/Tidy/messy sometimes and When I opened this video I was honestly expecting an Interface(ITimeProvider) instead of an abstract class but hey it's a good progress still I guess and the team should be made aware of this.

  • @TheMasonX23
    @TheMasonX23 Рік тому

    Why DateTimeOffset? Love the videos, thanks for the great content!

  • @Detyrious
    @Detyrious Рік тому +1

    I'm a total und utter noob in C# (and programming) and just starting to learn, but wouldn't the "dateTimeNow" object be 'tightly coupled' with GenerateGreetText, something one should avoid, and I should inject a DateTime object with the time of the greeting I want? So I can mock it in the test? Like I said, I just learn C# via UA-cam and I have no idea what I'm doing.

    • @flying-eagle-method
      @flying-eagle-method Рік тому

      Your instinct is correct. Logic that works on time should be separated from code that gets the time.
      In a more complex scenario, however, that does multiple steps with delays and timeouts, having a mockable time interface that speeds up time is helpful.

  • @tevolutionYT
    @tevolutionYT Рік тому +1

    Did you ask this question to chatgpt!! As far I remember you did!! And your reaction was out of the world!

    • @nickchapsas
      @nickchapsas  Рік тому +1

      Yeap, that was part of the test that ChatGPT solved!

  • @davidreis5086
    @davidreis5086 Рік тому

    Please make a video explaining why you think they made an abstract class, and why they should be using interfaces for that!

  • @michaelconrad2690
    @michaelconrad2690 Рік тому +1

    So, it looks like this would not stop someone on your project calling DateTime.Now. Are you aware of any analyzer, or similar, which could make sure everyone uses the new abstraction? I was thinking the other day about making an analyzer which can do that. Though its only the DateTime.Now and things like the methods on File which seem like clear targets for something like that.

  • @verzivull
    @verzivull Рік тому

    I've seen some ways to solve it by using MS test shims. Which is of course are working in enterprise environment. I usually use my own interface for DateTime... But the need to test such scenario with DateTime is happening not very often

  • @adamding3873
    @adamding3873 Рік тому

    I agree that it should be an interface. If the system doesn't provide it, for my own newly development projects, I would use a custom time provider interface.

  • @proosee
    @proosee Рік тому

    TBH this should be a standard thing to provide interface for a class. The hell, make it part of the language, like if I have class Foo, then I have e.g. Foo.interface. I can't even tell how much time I *wasted* (yes, it is a waste) to write those wrapper classes just to be able to abstract from framework or some referenced library logic.

  • @sachinjangir166
    @sachinjangir166 Рік тому +1

    make a video on datetime and datetimeoffset pls

  • @quetzalcoatl-pl
    @quetzalcoatl-pl Рік тому

    ITimeProvider interface. Cool. Finally a standard one for basic uses. But I'm absolutely shocked that they introduced TimeProvider class (ok, let's have a handy default impl) with STATIC getters wired to system time AGAIN. Holy cow, what for? Those who currently use hard-wired system time, once they hear "the new TimeProvider is better, please do use it instead", they're going to use the static getters as they are accustomed to, gaining literally nothing. It's a goddamn FifthElement's BigRedDontPressMeButton. You just don't add old broken features under bunch of new names if you want to fix your library and want your users to learn to do better. D'oh!

  • @rjpajaron
    @rjpajaron Рік тому

    Can I have written version of this video? I have a hard time with DateTime handling.

  • @Alexvilg
    @Alexvilg Рік тому

    Would it be better to inject a delegate to this method which could provide a datetime?

  • @Thorarin
    @Thorarin Рік тому

    I kind of hate the clock abstraction they made. So bad I'm tempted to keep using my own or NodaTime.

  • @local9
    @local9 Рік тому +2

    Finally, hopefully over time this will improve now its finally here.

  • @phizc
    @phizc Рік тому

    They should make *ITimeProvider* a d have *TimeProvider* implement it. That way it would be easy to make a mocked implementation of the interface. This will be moot when roles and extensions/shapes get added though, since then you can just define the shape/interface you need after the fact.
    I *really* hope it's coming un 8.0, but I'm not holding my breath..

  • @BlazorPlate
    @BlazorPlate Рік тому

    Can we use TimeProvider as scoped service instead of singleton?

  • @lukegordon4734
    @lukegordon4734 Рік тому

    Pretty shocked they went an abstract class route. Hopefully they do go w/ an interface approach

  • @DanielAWhite27
    @DanielAWhite27 Рік тому

    I’d love to see the stopwatch type take one of these in as a constructor so you could test your code with a stopwatch

  • @mattwatsonkc
    @mattwatsonkc Рік тому +1

    This is the perfect example of something to never unit test at all. Very simple code that doesn't need testing. If you even did, you could have just passed in date times with specific times to test and never used a time provider.

  • @DummyFace123
    @DummyFace123 Рік тому

    But yeah I’ve convinced every company I’ve worked in the past 10 years to used an IDateTimeProvider instead of DateTime static directly. Easy sell, there’s no other way to reliably unit test time dependent logic

  • @timseguine2
    @timseguine2 Рік тому

    Ugh. TBH this doesn't really change much for me, since I have a design rule to only ever mock interfaces and never concrete or abstract types. I know that sounds a bit dogmatic, but I'd rather have a slight bit of mess in a trivial wrapper than risk having weird test code.

  • @dreamglimmer
    @dreamglimmer Рік тому +1

    let them fix/simplify that working with client(saved peer user/taken from request) timezone, instead relying on assumption that client cares if it's afternoon on server or not..

  • @JonnyWideFoot
    @JonnyWideFoot Рік тому

    I've been coding dotnet professionally since 1.1. In every one of my projects I've added an ITime with a default implementation returning utcnow. I've never understood why Microsoft refuse to provide this common mockable interface. It's simple...

  • @ryan-heath
    @ryan-heath Рік тому

    Why is the stopwatch functionality put into the timeprovider?
    When would you mock the stopwatch?

    • @nickchapsas
      @nickchapsas  Рік тому +1

      If you’re using it to measure something and that measurement is part of something like a log parameter and you need to verify it

  • @benjamininkorea7016
    @benjamininkorea7016 Рік тому +1

    Not gonna lie. I've never seen a need to unit test time of day.
    Very interesting solution to a problem I never really worried about. :D

  • @simongeering
    @simongeering 10 місяців тому

    Good grief I'll stick with my own IDateTimeProvider that takes 1 line to mock for the default common utcnow use case

  • @jameshancock
    @jameshancock Рік тому

    Yes it should be an interface with default implementations on the interface.

  • @albe1620
    @albe1620 Рік тому

    It's little confusing that they added the stopwatch features to it. Why not using them directly over the Stopwatch class?

    • @CraigologyAustralia
      @CraigologyAustralia Рік тому

      That was my thought too, seems like unnecessary duplication of the framework surface area.

  • @robertsilver1296
    @robertsilver1296 Рік тому +1

    Sorry, someone is going to have to explain to me the difference between this video and just, in the tests, putting DateTime(2023, 01, 01, 8, 0, 0). I can’t see the difference because the video is not explaining in detail where it’s getting it’s time from.

  • @11r3start11
    @11r3start11 Рік тому

    Seems like interfaces are default and the most "expected" way to abstract things, espesially for external consumers.
    So I really dont uderstand why they "expose" abstract class, with this silly ticks parameter)

  • @parlor3115
    @parlor3115 Рік тому +2

    @Nick, do you have plans just in case the AI takeover happens within the next couple of years? Like do you have an alternative career path or a lucrative non-tech side project in case this happens in the short term?

    • @nickchapsas
      @nickchapsas  Рік тому +20

      I’m finally gonna start my dream beekeeping business

    • @rafekemmis3097
      @rafekemmis3097 Рік тому

      @@nickchapsasStart now to corner the AI bee market!

    • @bomret
      @bomret Рік тому

      You could use the swarm intelligence of the bees as your AI 😄

    • @vasiliyfofanov2605
      @vasiliyfofanov2605 Рік тому

      @@nickchapsas Cool! Maybe you have another UA-cam channel about it?

    • @proosee
      @proosee Рік тому

      In complex scenarios the reason why Dapper is faster is because you are using SQL, a native language for your database engine - the example in video is where compiling a query takes more time than fetching data, in contrary, for complex queries the opposite happens: compilation of the query is fast, but the query itself is complex, so database engine takes time to process it, then other factors comes to place, mostly that you are using LINQ, so some things might be "lost in translation" when EF is compiling to SQL.
      I made this error only once, I spend enormous time to optimise LINQ for complicated query with some minor success and then I just downloaded Dapper, wrote it in SQL and it just worked few times faster (BTW, we were still using EF everywhere else, it's too convenient, Dapper was only for report-like complicated queries). My mistake was that I was using wrong tool to solve the problem - SQL is a language that was specifically designed to deal with querying data, there is no reason to make your life difficult for purity sake.

  • @DamienSawyer
    @DamienSawyer Рік тому

    I think I'll still use Nodatime

  • @damiantedrow3218
    @damiantedrow3218 Рік тому +1

    It looks to me like test induced design that offers no benefit for production code. Maybe someone can reply with an example of how this helps a real world scenario to change my mind.

  • @Rose-ec6he
    @Rose-ec6he Рік тому +1

    Yayy new nick upload!

  • @RudiOnRails
    @RudiOnRails Рік тому +1

    If you decide to do a DateTime video please consider looking at something like NodaTime in that same video. Would be interesting to see if nodatime is really required.

  • @LaheralHaake
    @LaheralHaake Рік тому

    Definitely should be an interface. Who knows, maybe they change it in the future

  • @jazzweather
    @jazzweather 11 місяців тому

    I don't understand why one couldn't just create a DateTime object instead of using system time and pass it to the test cases.

  • @retokaderli9010
    @retokaderli9010 Рік тому

    For e.g a REST API... can time provider be the client time (zone)?

    • @nickchapsas
      @nickchapsas  Рік тому

      Depends on how you use it but yeah you can set a LocalTimeZone as long as you have the user’s offset from UTC

  • @peterkitts8815
    @peterkitts8815 Рік тому

    Please tell me about DateTimeOffset

  • @ashutoshkushawaha6664
    @ashutoshkushawaha6664 Рік тому

    Hello TimeProvider is not available in visual studio 17.6 preview 2, What can I do to bring in my project?

    • @nickchapsas
      @nickchapsas  Рік тому +1

      Download preview 4

    • @ashutoshkushawaha6664
      @ashutoshkushawaha6664 Рік тому

      ​@@nickchapsasI found Preview 1 and Preview 2 for Visual Studio 17.6, but I'm looking for a download link for Preview 4. Could you please provide a link or direct me to a trusted source where I can download it? Thank you.

    • @ashutoshkushawaha6664
      @ashutoshkushawaha6664 Рік тому

      @@nickchapsas I was able to find Preview 1,2 and Preview 3 for Visual Studio 17.6, but I'm looking for a download link for Preview 4. Could you please provide a link or direct me to a trusted source where I can download it? Thank you

  • @bsoter
    @bsoter Рік тому

    Finally I can remove all my IDateTimeProvider interface usage and substitute it with .NET native interf... oh, wait... an abstract class?

  • @fifty-plus
    @fifty-plus Рік тому

    I think I'll stick with Noda and IClock.

  • @antibioticaddict
    @antibioticaddict Рік тому

    Why could this all of not been done in an interface?

  • @daniilchertkov2067
    @daniilchertkov2067 Рік тому

    And solution looks like addon of stopwarch...still raw solution, so we have to expect different implementaion after sometime ...looks like

  • @terminator4974
    @terminator4974 Рік тому

    I always dislike the fact there are no interfaces. I mean its 2022 decoupling is mandatory i never inject an intstance always an interface and the exception to the rule is third party instances only when i can mock them easily in unit test. If not they will get abstracted away behind a concrete implementation of own with an exclude from codecoverage attribute. Very bad but at least i control my own interaction with the 3rd party code.

    • @adrian_franczak
      @adrian_franczak Рік тому

      sometime interfaces are useless - "abstraction hell" and errors in runtime, in most cases you have only one implementation and interface is only used for testing but it can be solved differently

    • @terminator4974
      @terminator4974 Рік тому

      @@adrian_franczak i get your point but it doesnt mean interfaces are a way to abstraction hell and not are useless when you only have one concrete class implementing the interface. If you want to swap out the old implementation for the new one you get rekt with your hard dependencies and your "ugly" way of testing your own implementation interacting with the 3rd party library

  • @HakunaMatata225
    @HakunaMatata225 Рік тому

    Trivial problem, and trivial unit test....!!!

  • @DummyFace123
    @DummyFace123 Рік тому

    Lol you just answered your own question for why it’s an abstract class and not an interface, the high frequency stuff

  • @lordicemaniac
    @lordicemaniac Рік тому

    so why utcnow instead of now?

  • @pilotboba
    @pilotboba Рік тому +1

    I was so hoping you would say Dotnet was removing null. :)

  • @ecblanco
    @ecblanco Рік тому

    Comment to remind you DateTimeOffSet Video. Cheers.

  • @anon0
    @anon0 Рік тому

    they shouldve named it timeservice

  • @obinnaokafor6252
    @obinnaokafor6252 Рік тому

    Well done, Microsoft.

  • @BernhardMillauer
    @BernhardMillauer Рік тому

    My IClock implementation is much better. Based on an interface, default service calls DateTime.* and if I want, I can TimeTravel in my unit tests in the TestableClock instance. Microsoft did it again, wrong.

  • @MrHeavyRunner
    @MrHeavyRunner Рік тому

    What's wrong with having DateTime as parameter and using DateTime new() or .Parse in test to run it? There you get consistent results. Omg what is this video even about...

  • @DxCKnew
    @DxCKnew Рік тому

    The more everything become more abstract/interfaces and dependency-injected, the more over-complicated and over-engineered the code seem to me.

  • @alirezanet
    @alirezanet Рік тому

    ahh I don't like it, IDateTime interface would be much nicer

  • @denm8822
    @denm8822 Рік тому +4

    Oh, inject this, inject that... In a blink of an your constructor becomes total mess

    • @rafekemmis3097
      @rafekemmis3097 Рік тому

      You can always just resolve it using the IServiceProvider when you need it.

    • @diadetediotedio6918
      @diadetediotedio6918 Рік тому

      Lmao

    • @diadetediotedio6918
      @diadetediotedio6918 Рік тому +2

      Use a source generator if this is a great problem for you, or better, split your code better and not create so powerful classes

    • @JerryFederspiel
      @JerryFederspiel Рік тому +3

      If your constructor is taking a lot of dependencies, your class is probably doing too much. If your constructor is a mess, that also suggests that the constructor itself is doing too much. Ideally, a constructor should just get the object in a valid state so it can start taking method calls; often that just means assigning the dependencies to fields.

  • @NotACat20
    @NotACat20 Рік тому

    Bullshit twice. TimeProvider is just mix everything in single interface, but them should not. Places where you need QPC is strictly not places where you need wall clock and measure units is different.

  • @terminator4974
    @terminator4974 Рік тому

    Im just wondering why u use nsubstitute instead of moq. Thanks for this great video :)