Testing.Commons. It’s a matter of time

 
event

Face it: time is everywhere and cannot run away from it. That is why I chose time to be the subject of the first release of Testing.Commons, a mere 0.1.

Classes that deal with time in the BCL (DateTime, DateTimeOffset, TimeSpan) might have their issues. They might not be accurate. They might not be correct at all. There might be some better alternatives. But they are not going anywhere, anytime soon.

And code that make use of them needs to be tested and, honestly, those classes do not have the most expressive API when it comes to create instances of them. This feature is not that incredible useful in the “real world” (the world of production code) where dates are rarely hard-coded, but it does not hurt anyone if a bit of lipstick is put on top.

D-Day

DateTime can be created in a very visual way using a set of cleverly named extension methods.

Sometimes what one needs is whichever date between two bounds.

And sometimes what one needs is a number of dates between two bounds. Careful, though; an infinite stream of dates takes a long time to enumerate, limit the number of results.

Times Are A’ Changing

Dates are alright, but we have measures smaller than days.

We even have certain times of the day important enough to deserve a name on their own.

Where in the world is *

It took some time to figure out DateTime was not the best structure to deal with the artificial human-created trickeries that time zones are. Sometimes what we want to do is not performing some transformations between dates in different zones. We just want to specify exactly what we are creating.

The arrow of time

Time passes. And spans of time needs to be measured and compared. Another set of extension methods allows elegant creation of Timespans.

Get It While Fresh

You can get this first 0.1 release from NuGet package.

Geek Note:

If the reader’s mind complete the phrase with “Carmen Sandiego” we have one of three cases:

  1. old nerdy individual
  2. really nerdy individual
  3. facebook infected individual