Nodatime iclock3/28/2023 System.DateTime value = default(System.DateTime) ![]() It helps you to think about your data more clearly, and express operations on that data more precisely. вот url private string GetCountryTime(string country) Noda Time is an alternative date and time API for. From a unit testing perspective NodaTime makes the process also a bit easier as it exposes an IClock interface to get the current time, which can be mocked or you can even use their own FakeClock class to assist with testing. When you instantiate a Logger in your production code, you can give it SystemClock.Instance. Now log the message with the timestamp. Instead of accessing SystemClock directly, use an IClock instance that's supplied via its constructor: public class Logger We recommend providing an instance of IClock to anything that needs it, which allows you to write tests using the stub clock in the NodaTime.Testing assembly (or your own implementation).Īs a simple example, suppose you have a Logger class that needs the current time. Although it's not strictly incorrect to call directly, in the same way as you might call UtcNow, it's strongly discouraged as a matter of style for production code. IClock is intended for use anywhere you need to have access to the current time. SystemClock.Now returns the current time as an Instant value: Instant now = īut you may want to heed the remarks in the documentation for the IClock interface:
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |