public void EndOfMonth() { DateTime date; DateTime endOfMonth; // normal 30 day month date = new DateTime(2018, 9, 15); endOfMonth = date.EndOfMonth(); Assert.AreEqual(new DateTime(2018, 9, 15), date); // make sure that the original DateTime is not modified Assert.AreEqual(new DateTime(2018, 9, 30), endOfMonth); // normal 31 day month date = new DateTime(2018, 12, 20); endOfMonth = date.EndOfMonth(); Assert.AreEqual(new DateTime(2018, 12, 31), endOfMonth); // february 28 date = new DateTime(2018, 2, 10); endOfMonth = date.EndOfMonth(); Assert.AreEqual(new DateTime(2018, 2, 28), endOfMonth); // february 29 date = new DateTime(2016, 2, 1); endOfMonth = date.EndOfMonth(); Assert.AreEqual(new DateTime(2016, 2, 29), endOfMonth); // already last day date = new DateTime(1993, 1, 31); endOfMonth = date.EndOfMonth(); Assert.AreEqual(new DateTime(1993, 1, 31), endOfMonth); // current end of month date = DateTime.Today.EndOfMonth(); endOfMonth = DateTimeUtility.EndOfMonth(); Assert.AreEqual(date, endOfMonth); }