Created
November 26, 2015 09:52
-
-
Save Steinblock/7407f7d2218fc46a7e0d to your computer and use it in GitHub Desktop.
DateTimeExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DateTimeExtensions | |
{ | |
public static DateTime TrimMilliseconds(this DateTime date) | |
{ | |
return date.AddMilliseconds(-date.Millisecond); | |
} | |
} | |
[TestClass] | |
public class DateTimeExtensionsTest | |
{ | |
[TestMethod] | |
public void CanTrimMilliseconds() | |
{ | |
var date1 = new DateTime(1,1,1, 1,1,1).AddMilliseconds(1); | |
var date2 = new DateTime(1, 1, 1, 1, 1, 1).AddMilliseconds(2); | |
Assert.AreNotEqual(date1, date2); | |
Assert.AreEqual(date1.TrimMilliseconds(), date2.TrimMilliseconds()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment