public bool Equals(CalendarTimeSpan other) { return((this.Negative == other.Negative) && (this.Years == other.Years) && (this.Months == other.Months) && (this.Days == other.Days) && (this.Hours == other.Hours) && (this.Minutes == other.Minutes) && (this.Seconds == other.Seconds) && (this.Milliseconds == other.Milliseconds)); }
protected virtual void HandleIntervalCommand(CommandMatch cmd, IChannelMessageEventArgs msg) { var dateTimeString = (string)cmd.Arguments[0]; DateTime?timestamp = TimeUtil.DateTimeFromString(dateTimeString); if (!timestamp.HasValue) { return; } DateTime timestampUTC = timestamp.Value.ToUniversalTime(); DateTime nowUTC = DateTime.UtcNow; DateTime nowUTCFullSeconds = nowUTC.AddTicks(-(nowUTC.Ticks % TicksPerSecond)); CalendarTimeSpan diff = TimeComparison.CalendarDifference(nowUTCFullSeconds, timestampUTC); var pieces = new List <string>(); MaybeAddUnit(pieces, diff.Years, "year", "years"); MaybeAddUnit(pieces, diff.Months, "month", "months"); MaybeAddUnit(pieces, diff.Days, "day", "days"); MaybeAddUnit(pieces, diff.Hours, "hour", "hours"); MaybeAddUnit(pieces, diff.Minutes, "minute", "minutes"); MaybeAddUnit(pieces, diff.Seconds, "second", "seconds"); string message; if (pieces.Count == 0) { message = "That’s now!"; } else { var messageBuilder = new StringBuilder(); if (pieces.Count > 1) { messageBuilder.Append(string.Join(", ", pieces.Take(pieces.Count - 1))); // 1 year, 2 months, 3 days[ and 4 hours] messageBuilder.Append(" and "); // 1 year, 2 months, 3 days and [4 hours] } messageBuilder.Append(pieces.Last()); messageBuilder.Append(diff.Negative ? " ago." : " remaining."); message = messageBuilder.ToString(); } ConnectionManager.SendChannelMessage(msg.Channel, $"{msg.SenderNickname}: {message}"); }