Skip to content
Snippets Groups Projects
Commit beaba51e authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Prevent integer overflow issues with time delta methods.

parent 75c693c6
No related branches found
No related tags found
No related merge requests found
......@@ -17,8 +17,8 @@ namespace ATxCommon
/// </summary>
/// <param name="refDate">The reference DateTime to check.</param>
/// <returns>The number of minutes between the reference date and now.</returns>
public static int MinutesSince(DateTime refDate) {
return (int)(DateTime.Now - refDate).TotalMinutes;
public static long MinutesSince(DateTime refDate) {
return (long)(DateTime.Now - refDate).TotalMinutes;
}
/// <summary>
......@@ -26,8 +26,8 @@ namespace ATxCommon
/// </summary>
/// <param name="refDate">The reference DateTime to check.</param>
/// <returns>The number of seconds between the reference date and now.</returns>
public static int SecondsSince(DateTime refDate) {
return (int)(DateTime.Now - refDate).TotalSeconds;
public static long SecondsSince(DateTime refDate) {
return (long)(DateTime.Now - refDate).TotalSeconds;
}
/// <summary>
......@@ -35,7 +35,7 @@ namespace ATxCommon
/// </summary>
/// <param name="delta">The time span in seconds.</param>
/// <returns>A string describing the duration, e.g. "2 hours 34 minutes".</returns>
public static string SecondsToHuman(int delta) {
public static string SecondsToHuman(long delta) {
const int second = 1;
const int minute = second * 60;
const int hour = minute * 60;
......@@ -70,7 +70,7 @@ namespace ATxCommon
/// </summary>
/// <param name="delta">The time span in minutes.</param>
/// <returns>A string describing the duration, e.g. "2 hours 34 minutes".</returns>
public static string MinutesToHuman(int delta) {
public static string MinutesToHuman(long delta) {
return SecondsToHuman(delta * 60);
}
......@@ -79,7 +79,7 @@ namespace ATxCommon
/// </summary>
/// <param name="delta">The time span in days.</param>
/// <returns>A string describing the duration, e.g. "12 days" or "3 weeks".</returns>
public static string DaysToHuman(int delta) {
public static string DaysToHuman(long delta) {
return MinutesToHuman(delta * 60 * 24);
}
}
......
......@@ -424,7 +424,7 @@ namespace ATxService
Log.Error("Unhandled exception in OnTimedEvent(): {0}\n\n" +
"Trying exponential backoff, setting timer interval to {1} ms ({3}).\n\n" +
"StackTrace: {2}", ex.Message, _mainTimer.Interval, ex.StackTrace,
TimeUtils.SecondsToHuman((int)_mainTimer.Interval / 1000));
TimeUtils.SecondsToHuman((long)_mainTimer.Interval / 1000));
}
finally {
// make sure to enable the timer again:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment