|
@@ -2633,20 +2633,32 @@ namespace HealthMonitor.WebApi |
|
|
//} |
|
|
//} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private DateTime GetSampleTimeFromLastUpdate(DateTime lastUpdate,int interval) |
|
|
|
|
|
|
|
|
//private DateTime GetSampleTimeFromLastUpdate(DateTime lastUpdate,int interval) |
|
|
|
|
|
//{ |
|
|
|
|
|
// DateTime nowInterval = lastUpdate; |
|
|
|
|
|
// //if (nowInterval.Second > 0) |
|
|
|
|
|
// //{ |
|
|
|
|
|
// // nowInterval = nowInterval.AddMinutes(1); |
|
|
|
|
|
// //} |
|
|
|
|
|
// // 计算last_update到上一间隔的分钟数 |
|
|
|
|
|
// int minutesToSubtract = nowInterval.Minute % interval; |
|
|
|
|
|
|
|
|
|
|
|
// // 计算上一间隔的时间 |
|
|
|
|
|
// DateTime previousInterval = nowInterval.AddMinutes(-minutesToSubtract).AddSeconds(-nowInterval.Second).AddMilliseconds(-nowInterval.Millisecond); |
|
|
|
|
|
|
|
|
|
|
|
// return previousInterval; |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
public static DateTime GetSampleTimeFromLastUpdate(DateTime lastUpdate, int interval) |
|
|
{ |
|
|
{ |
|
|
DateTime nowInterval = lastUpdate; |
|
|
|
|
|
//if (nowInterval.Second > 0) |
|
|
|
|
|
//{ |
|
|
|
|
|
// nowInterval = nowInterval.AddMinutes(1); |
|
|
|
|
|
//} |
|
|
|
|
|
// 计算last_update到上一间隔的分钟数 |
|
|
|
|
|
int minutesToSubtract = nowInterval.Minute % interval; |
|
|
|
|
|
|
|
|
// 获取当前的分钟 |
|
|
|
|
|
int minute = lastUpdate.Minute; |
|
|
|
|
|
|
|
|
// 计算上一间隔的时间 |
|
|
|
|
|
DateTime previousInterval = nowInterval.AddMinutes(-minutesToSubtract).AddSeconds(-nowInterval.Second).AddMilliseconds(-nowInterval.Millisecond); |
|
|
|
|
|
|
|
|
// 按 15 分钟为单位划分时间段 |
|
|
|
|
|
int intervalStartMinute = (minute / interval) * interval; |
|
|
|
|
|
|
|
|
return previousInterval; |
|
|
|
|
|
|
|
|
// 返回当前时间刻度下的 DateTime,保留小时和新计算的分钟,秒和毫秒设为0 |
|
|
|
|
|
return new DateTime(lastUpdate.Year, lastUpdate.Month, lastUpdate.Day, lastUpdate.Hour, intervalStartMinute, 0, 0); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |