public static bool TryParse(string value, out UnixTimestamp result) { result = new UnixTimestamp(); long seconds; if (!long.TryParse(value, out seconds)) return false; result = new UnixTimestamp(seconds); return true; }
public void Comparison() { UnixTimestamp timestamp = rawTimestamp; UnixTimestamp timestamp2 = rawTimestamp; UnixTimestamp timestamp3 = new UnixTimestamp(rawTimestamp).AddMonths(1); UnixTimestamp timestamp4 = new UnixTimestamp(rawTimestamp).AddMonths(-1); Assert.AreEqual(1, timestamp.CompareTo(null)); ExceptionAssert.Throws<ArgumentException>(() => timestamp.CompareTo("test")); Assert.AreEqual(0, timestamp.CompareTo((object)timestamp2)); Assert.AreEqual(0, timestamp.CompareTo(timestamp2)); ConditionAssert.Greater(0, timestamp.CompareTo(timestamp3)); ConditionAssert.Less(0, timestamp.CompareTo(timestamp4)); }
public void Equality() { UnixTimestamp timestamp = rawTimestamp; UnixTimestamp timestamp2 = rawTimestamp; UnixTimestamp timestamp3 = new UnixTimestamp(rawTimestamp).AddMonths(1); UnixTimestamp timestamp4 = new UnixTimestamp(rawTimestamp).AddMonths(-1); Assert.IsTrue(timestamp.Equals((object)timestamp2)); Assert.IsFalse(timestamp.Equals((object)timestamp3)); Assert.IsFalse(timestamp.Equals("test")); Assert.IsTrue(timestamp.Equals(timestamp2)); Assert.IsFalse(timestamp.Equals(timestamp3)); Assert.IsTrue(UnixTimestamp.Equals((object)timestamp, (object)timestamp2)); Assert.IsFalse(UnixTimestamp.Equals((object)timestamp, (object)timestamp3)); Assert.IsTrue(UnixTimestamp.Equals(timestamp, timestamp2)); Assert.IsFalse(UnixTimestamp.Equals(timestamp, timestamp3)); Assert.AreEqual(rawTimestamp.GetHashCode(), timestamp.GetHashCode()); }
/// <summary> /// Adds the specified <see cref="UnixTimestamp" /> to this instance /// and returns a new instance of UnixTimestamp /// </summary> public UnixTimestamp Add(UnixTimestamp unixTimestamp) { return new UnixTimestamp(secondsSinceEpoch + unixTimestamp); }
public bool Equals(UnixTimestamp other) { return other.secondsSinceEpoch == secondsSinceEpoch; }