using NUnit.Framework;
using DateTimeZone;
namespace TestDateTimeZone
{
/// <summary>
/// Summary description for UtcDateTimeTest
/// </summary>
[TestFixture]
public class UtcDateTimeTest
{
[Test]
public void TestLocalDateTimeCreation()
{
//winter time test
LocalDateTime anHour = new LocalDateTime(2009, 10, 1, 23, 0, 0, TimeZones.UTC, true);
Assert.AreEqual(23, anHour.Hour);
}
[Test]
public void TestUtcCreation()
{
//winter time test
UtcDateTime anHour = new UtcDateTime(2009, 10, 1, 23, 0, 0);
Assert.AreEqual(23, anHour.Hour);
}
[Test]
public void TestUtcMin()
{
UtcDateTime oct1st2300 = new UtcDateTime(2009, 10, 1, 23, 0, 0);
UtcDateTime oct1st2200 = new UtcDateTime(2009, 10, 1, 22, 0, 0);
UtcDateTime minUtcDateTime = DateUtil.Min(oct1st2300, oct1st2200);
Assert.IsTrue(minUtcDateTime.GetDateTime() == oct1st2200.GetDateTime());
}
[Test]
public void TestUtcMax()
{
UtcDateTime oct1st2300 = new UtcDateTime(2009, 10, 1, 23, 0, 0);
UtcDateTime oct1st2200 = new UtcDateTime(2009, 10, 1, 22, 0, 0);
UtcDateTime maxUtcDateTime = DateUtil.Max(oct1st2300, oct1st2200);
Assert.IsTrue(maxUtcDateTime.GetDateTime() == oct1st2300.GetDateTime());
}
[Test]
public void TestStartOfDayInCETTimeZone()
{
UtcDateTime utc = new UtcDateTime(2009, 5,1,23,35,0);
CetDateTime cetDateTime = new CetDateTime(utc.ToLocalDateTime(TimeZones.CET));
CetDateTime startOfDay = (CetDateTime) cetDateTime.Date;
Assert.IsTrue(startOfDay.Equals(new CetDateTime(2009, 5, 2, 0, 0, 0)));
}
[Test]
public void TestEndOfDayInCETTimeZone()
{
UtcDateTime utc = new UtcDateTime(2009, 5, 1, 23, 35, 0);
CetDateTime cetDateTime = new CetDateTime(utc.ToLocalDateTime(TimeZones.CET));
LocalDateTime time = cetDateTime.Date.AddDays(1).AsLocalDateTime();
CetDateTime endOfDay = new CetDateTime(time.GetDateTime());
Assert.IsTrue(endOfDay.Equals(new CetDateTime(2009, 5, 3, 0, 0, 0)));
}
[Test]
public void TestNull()
{
UtcDateTime nullUtc = UtcDateTime.Null;
Assert.IsTrue(nullUtc.IsNull);
Assert.AreEqual(TimeZones.UTC, nullUtc.TimeZone);
}
[Test]
public void TestCompareTo()
{
UtcDateTime referenceDateTime = new UtcDateTime(2009, 11, 13, 12, 0, 0);
// Compare the reference date time with another equal date time, CompareTo should then return 0
UtcDateTime equalDateTime = new UtcDateTime(2009, 11, 13, 12, 0, 0);
int compareToResult = referenceDateTime.CompareTo(equalDateTime);
Assert.IsTrue(compareToResult == 0);
// Compare the reference date time with a date time which is earlier, CompareTo should then return a positive value
// because the reference date time is larger than the earlier date time.
UtcDateTime earlierDateTime = new UtcDateTime(2009, 11, 13, 11, 0, 0);
compareToResult = referenceDateTime.CompareTo(earlierDateTime);
Assert.IsTrue(compareToResult > 0);
// Compare the reference date time with a date time which is later, CompareTo should then return a negative value
// because the reference date time is smaller than the later date time.
UtcDateTime laterDateTime = new UtcDateTime(2009, 11, 13, 13, 0, 0);
compareToResult = referenceDateTime.CompareTo(laterDateTime);
Assert.IsTrue(compareToResult < 0);
}
}
}