TelemetryDataCache.GetOrDefault(..) Fix Timezone issue

This commit is contained in:
ngfrolov 2023-09-12 16:22:01 +05:00
parent 5e0ab46e57
commit c0db1a02d3
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -22,6 +22,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
{
public TDto? FirstByDate { get; init; }
public CyclycArray<TDto> LastData { get; init; } = null!;
public double TimezoneHours { get; init; } = 5;
}
private IServiceProvider provider = null!;
@ -226,6 +227,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
{
FirstByDate = first,
LastData = cacheItem,
TimezoneHours = hoursOffset,
};
return item;
}
@ -234,7 +236,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
{
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
return null;
IEnumerable<TDto> data = cacheItem.LastData;
if (!data.Any())
@ -242,19 +244,23 @@ namespace AsbCloudInfrastructure.Services.SAUB
if (request.GeDate.HasValue)
{
if (data.First().DateTime > request.GeDate.Value)
var geDate = request.GeDate.Value.ToRemoteDateTime(cacheItem.TimezoneHours);
if (data.First().DateTime > geDate)
return null;
data = data.Where(d => d.DateTime >= request.GeDate);
data = data.Where(d => d.DateTime >= geDate);
}
else
{
if (request.Order == 0)
return null;
}
}
if (request.LeDate.HasValue)
if (request.LeDate.HasValue)
{
var leDate = request.LeDate.Value.ToRemoteDateTime(cacheItem.TimezoneHours);
data = data.Where(d => d.DateTime >= request.LeDate);
}
if (request.Divider > 1)
data = data.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % request.Divider == 0);