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

Move time-delta code to TimeUtils.

parent 30fc2794
No related branches found
No related tags found
No related merge requests found
......@@ -11,5 +11,23 @@ namespace ATXCommon
public static string Timestamp() {
return DateTime.Now.ToString("yyyy-MM-dd__HH-mm-ss");
}
/// <summary>
/// Calculate the time delta since the given date in minutes.
/// </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;
}
/// <summary>
/// Calculate the time delta since the given date in seconds.
/// </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;
}
}
}
......@@ -489,8 +489,7 @@ namespace AutoTx
SendLowSpaceMail(SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring));
UpdateServiceState();
var delta = (int)(DateTime.Now - _lastUserDirCheck).TotalSeconds;
if (delta >= 120)
if (TimeUtils.SecondsSince(_lastUserDirCheck) >= 120)
CreateIncomingDirectories();
// tasks depending on the service state:
......@@ -934,7 +933,7 @@ namespace AutoTx
if (string.IsNullOrEmpty(report))
return "";
report = "Expired folders in grace location:\n" + report;
var delta = (int)(DateTime.Now - _status.LastGraceNotification).TotalMinutes;
var delta = TimeUtils.MinutesSince(_status.LastGraceNotification);
report += "\nTime since last grace notification: " + delta + "\n";
if (delta >= _config.GraceNotificationDelta) {
SendAdminEmail(report, "Grace location cleanup required.");
......
......@@ -80,7 +80,7 @@ namespace AutoTx
if (_config.SendAdminNotification == false)
return;
var delta = (int)(DateTime.Now - _status.LastAdminNotification).TotalMinutes;
var delta = TimeUtils.MinutesSince(_status.LastAdminNotification);
if (delta < _config.AdminNotificationDelta) {
Log.Debug("Suppressed admin email, interval too short ({0} vs. {1}):\n\n{2}\n{3}",
delta, _config.AdminNotificationDelta, subject, body);
......@@ -109,9 +109,11 @@ namespace AutoTx
if (string.IsNullOrWhiteSpace(spaceDetails))
return;
var delta = (int)(DateTime.Now - _status.LastStorageNotification).TotalMinutes;
if (delta < _config.StorageNotificationDelta)
var delta = TimeUtils.MinutesSince(_status.LastStorageNotification);
if (delta < _config.StorageNotificationDelta) {
Log.Trace("Only {0} minutes since last low-space-notification, skipping.", delta);
return;
}
Log.Warn("WARNING: {0}", spaceDetails);
_status.LastStorageNotification = DateTime.Now;
......
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