Skip to content

Commit

Permalink
RavenDB-21649 : address more PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv86 committed Nov 20, 2023
1 parent 4857eb1 commit 1fa64de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ string GetSourceAndId()

private static RangeGroup InitializeRangeSpecs(string groupByTimePeriod, DateTime from, DateTime to, TimeSpan? offset)
{
TimeSeriesReader.AddOffsetIfNeeded(offset, ref from, ref to);
(from, to) = TimeSeriesReader.AddOffsetIfNeeded(offset, from, to);

if (groupByTimePeriod != null)
return RangeGroup.ParseRangeFromString(groupByTimePeriod, from);
Expand Down
29 changes: 12 additions & 17 deletions src/Raven.Server/Documents/TimeSeries/TimeSeriesReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ internal bool Init()
return false;
}

AddOffsetIfNeeded(_offset, ref _from, ref _to);
(_from, _to) = AddOffsetIfNeeded(_offset, _from, _to);

return true;
}
Expand Down Expand Up @@ -619,31 +619,26 @@ internal string GetCurrentSegmentChangeVector()
return (etag, changeVector, baseline);
}

internal static void AddOffsetIfNeeded(TimeSpan? offset, ref DateTime from, ref DateTime to)
internal static (DateTime From, DateTime To) AddOffsetIfNeeded(TimeSpan? offset, DateTime from, DateTime to)
{
if (offset.HasValue == false)
return;
return (from, to);

AddOffset(offset.Value, ref from);
AddOffset(offset.Value, ref to);
from = AddOffset(offset.Value, from);
to = AddOffset(offset.Value, to);
return (from, to);
}

private static void AddOffset(TimeSpan offset, ref DateTime date)
private static DateTime AddOffset(TimeSpan offset, DateTime date)
{
var withOffset = date.Ticks + offset.Ticks;
if (withOffset < 0)
{
date = DateTime.MinValue;
return;
}

return DateTime.MinValue;

if (withOffset > DateTime.MaxValue.Ticks)
{
date = DateTime.MaxValue;
return;
}

date = date.Add(offset);
return DateTime.MaxValue;

return date.Add(offset);
}
}

Expand Down

0 comments on commit 1fa64de

Please sign in to comment.