Example #1
0
        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;
        }
Example #2
0
        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));
        }
Example #3
0
        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());
        }
Example #4
0
 /// <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);
 }
Example #5
0
 public bool Equals(UnixTimestamp other)
 {
     return other.secondsSinceEpoch == secondsSinceEpoch;
 }