diff --git a/X10D.Tests/src/Time/DateTimeOffsetTests.cs b/X10D.Tests/src/Time/DateTimeOffsetTests.cs new file mode 100644 index 0000000..ccd9206 --- /dev/null +++ b/X10D.Tests/src/Time/DateTimeOffsetTests.cs @@ -0,0 +1,69 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Time; + +namespace X10D.Tests.Time; + +[TestClass] +public class DateTimeOffsetTests +{ + [TestMethod] + public void AgeShouldBeCorrect() + { + DateTimeOffset birthday = new DateTime(2000, 1, 1); + DateTimeOffset today = DateTime.Now.Date; + + Assert.AreEqual(today.Year - birthday.Year, birthday.Age()); + } + + [TestMethod] + public void FirstShouldBeCorrect() + { + DateTimeOffset date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(2000, 1, 1), date.First(DayOfWeek.Saturday)); + Assert.AreEqual(new DateTime(2000, 1, 2), date.First(DayOfWeek.Sunday)); + Assert.AreEqual(new DateTime(2000, 1, 3), date.First(DayOfWeek.Monday)); + Assert.AreEqual(new DateTime(2000, 1, 4), date.First(DayOfWeek.Tuesday)); + Assert.AreEqual(new DateTime(2000, 1, 5), date.First(DayOfWeek.Wednesday)); + Assert.AreEqual(new DateTime(2000, 1, 6), date.First(DayOfWeek.Thursday)); + Assert.AreEqual(new DateTime(2000, 1, 7), date.First(DayOfWeek.Friday)); + } + + [TestMethod] + public void FirstDayOfMonthShouldBeCorrect() + { + DateTimeOffset today = DateTime.Now.Date; + + Assert.AreEqual(new DateTime(today.Year, today.Month, 1), today.FirstDayOfMonth()); + } + + [TestMethod] + public void LastShouldBeCorrect() + { + DateTimeOffset date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(2000, 1, 29), date.Last(DayOfWeek.Saturday)); + Assert.AreEqual(new DateTime(2000, 1, 30), date.Last(DayOfWeek.Sunday)); + Assert.AreEqual(new DateTime(2000, 1, 31), date.Last(DayOfWeek.Monday)); + Assert.AreEqual(new DateTime(2000, 1, 25), date.Last(DayOfWeek.Tuesday)); + Assert.AreEqual(new DateTime(2000, 1, 26), date.Last(DayOfWeek.Wednesday)); + Assert.AreEqual(new DateTime(2000, 1, 27), date.Last(DayOfWeek.Thursday)); + Assert.AreEqual(new DateTime(2000, 1, 28), date.Last(DayOfWeek.Friday)); + } + + [TestMethod] + public void LastDayOfMonthShouldBeCorrect() + { + DateTimeOffset date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(date.Year, date.Month, 31), date.LastDayOfMonth()); + } + + [TestMethod] + public void NextShouldBeCorrect() + { + DateTimeOffset date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(2000, 1, 8), date.Next(DayOfWeek.Saturday)); + } +} diff --git a/X10D.Tests/src/Time/DateTimeTests.cs b/X10D.Tests/src/Time/DateTimeTests.cs new file mode 100644 index 0000000..f2e6aac --- /dev/null +++ b/X10D.Tests/src/Time/DateTimeTests.cs @@ -0,0 +1,85 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Time; + +namespace X10D.Tests.Time; + +[TestClass] +public class DateTimeTests +{ + [TestMethod] + public void AgeShouldBeCorrect() + { + var birthday = new DateTime(2000, 1, 1); + DateTime today = DateTime.Now.Date; + + Assert.AreEqual(today.Year - birthday.Year, birthday.Age()); + } + + [TestMethod] + public void FirstShouldBeCorrect() + { + var date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(2000, 1, 1), date.First(DayOfWeek.Saturday)); + Assert.AreEqual(new DateTime(2000, 1, 2), date.First(DayOfWeek.Sunday)); + Assert.AreEqual(new DateTime(2000, 1, 3), date.First(DayOfWeek.Monday)); + Assert.AreEqual(new DateTime(2000, 1, 4), date.First(DayOfWeek.Tuesday)); + Assert.AreEqual(new DateTime(2000, 1, 5), date.First(DayOfWeek.Wednesday)); + Assert.AreEqual(new DateTime(2000, 1, 6), date.First(DayOfWeek.Thursday)); + Assert.AreEqual(new DateTime(2000, 1, 7), date.First(DayOfWeek.Friday)); + } + + [TestMethod] + public void FirstDayOfMonthShouldBeCorrect() + { + DateTime today = DateTime.Now.Date; + + Assert.AreEqual(new DateTime(today.Year, today.Month, 1), today.FirstDayOfMonth()); + } + + [TestMethod] + public void LastShouldBeCorrect() + { + var date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(2000, 1, 29), date.Last(DayOfWeek.Saturday)); + Assert.AreEqual(new DateTime(2000, 1, 30), date.Last(DayOfWeek.Sunday)); + Assert.AreEqual(new DateTime(2000, 1, 31), date.Last(DayOfWeek.Monday)); + Assert.AreEqual(new DateTime(2000, 1, 25), date.Last(DayOfWeek.Tuesday)); + Assert.AreEqual(new DateTime(2000, 1, 26), date.Last(DayOfWeek.Wednesday)); + Assert.AreEqual(new DateTime(2000, 1, 27), date.Last(DayOfWeek.Thursday)); + Assert.AreEqual(new DateTime(2000, 1, 28), date.Last(DayOfWeek.Friday)); + } + + [TestMethod] + public void LastDayOfMonthShouldBeCorrect() + { + var date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(date.Year, date.Month, 31), date.LastDayOfMonth()); + } + + [TestMethod] + public void NextShouldBeCorrect() + { + var date = new DateTime(2000, 1, 1); + + Assert.AreEqual(new DateTime(2000, 1, 8), date.Next(DayOfWeek.Saturday)); + } + + [TestMethod] + public void ToUnixTimeMillisecondsShouldBeCorrect() + { + var date = new DateTime(2000, 1, 1); + + Assert.AreEqual(946684800000, date.ToUnixTimeMilliseconds()); + } + + [TestMethod] + public void ToUnixTimeSecondsShouldBeCorrect() + { + var date = new DateTime(2000, 1, 1); + + Assert.AreEqual(946684800, date.ToUnixTimeSeconds()); + } +} diff --git a/X10D/src/DateTimeExtensions/DateTimeExtensions.cs b/X10D/src/Time/DateTimeExtensions.cs similarity index 99% rename from X10D/src/DateTimeExtensions/DateTimeExtensions.cs rename to X10D/src/Time/DateTimeExtensions.cs index b57550b..0d99a4f 100644 --- a/X10D/src/DateTimeExtensions/DateTimeExtensions.cs +++ b/X10D/src/Time/DateTimeExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D; +namespace X10D.Time; /// /// Extension methods for . diff --git a/X10D/src/DateTimeExtensions/DateTimeOffsetExtensions.cs b/X10D/src/Time/DateTimeOffsetExtensions.cs similarity index 99% rename from X10D/src/DateTimeExtensions/DateTimeOffsetExtensions.cs rename to X10D/src/Time/DateTimeOffsetExtensions.cs index b7961fa..97df8f7 100644 --- a/X10D/src/DateTimeExtensions/DateTimeOffsetExtensions.cs +++ b/X10D/src/Time/DateTimeOffsetExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D; +namespace X10D.Time; /// /// Extension methods for .