Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TimeStamp from DateTime to Millisecond Instead of Ticks #127

Merged
merged 4 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NRedisStack/TimeSeries/DataTypes/TimeStamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TimeStamp
/// Build a TimeStamp from DateTime.
/// </summary>
/// <param name="dateTime">DateTime value</param>
public TimeStamp(DateTime dateTime) => Value = dateTime.Ticks;
public TimeStamp(DateTime dateTime) => Value = new DateTimeOffset(dateTime).ToUnixTimeMilliseconds();

/// <summary>
/// Build a TimeStamp from one of the strings "-", "+", "*".
Expand Down
3 changes: 2 additions & 1 deletion tests/NRedisStack.Tests/TimeSeries/TestAPI/TestAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public void TestOldAdd()
ts.Create(key);
ts.Add(key, new_dt, 1.1);
// Adding old event
Assert.Equal(old_dt, ts.Add(key, old_dt, 1.1));
var res = ts.Add(key, old_dt, 1.1);
Assert.Equal(old_dt.Value, res.Value);
}

[Fact]
Expand Down
3 changes: 2 additions & 1 deletion tests/NRedisStack.Tests/TimeSeries/TestAPI/TestAddAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ public async Task TestOldAdd()
await ts.CreateAsync(key);
await ts.AddAsync(key, newTimeStamp, 1.1);
// Adding old event
Assert.Equal(oldTimeStamp, await ts.AddAsync(key, oldTimeStamp, 1.1));
var res = await ts.AddAsync(key, oldTimeStamp, 1.1);
Assert.Equal(oldTimeStamp.Value, res.Value);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMADD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void TestSuccessfulMADD()
Assert.Equal(timestamps.Count, response.Count);
for (int i = 0; i < response.Count; i++)
{
Assert.Equal<DateTime>(timestamps[i], response[i]);
Assert.Equal(new DateTimeOffset(timestamps[i]).ToUnixTimeMilliseconds(), response[i].Value);
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public void TestOverrideMADD()
Assert.Equal(oldTimeStamps.Count, response.Count);
for (int i = 0; i < response.Count; i++)
{
Assert.Equal<DateTime>(oldTimeStamps[i], response[i]);
Assert.Equal(new DateTimeOffset(oldTimeStamps[i]).ToUnixTimeMilliseconds(), response[i].Value);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMAddAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task TestSuccessfulMAdd()
Assert.Equal(timestamps.Count, response.Count);
for (var i = 0; i < response.Count; i++)
{
Assert.Equal<DateTime>(timestamps[i], response[i]);
Assert.Equal(new DateTimeOffset(timestamps[i]).ToUnixTimeMilliseconds(), response[i].Value);
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task TestOverrideMAdd()
Assert.Equal(oldTimeStamps.Count, response.Count);
for (int i = 0; i < response.Count; i++)
{
Assert.Equal<DateTime>(oldTimeStamps[i], response[i]);
Assert.Equal(new DateTimeOffset(oldTimeStamps[i]).ToUnixTimeMilliseconds(), response[i].Value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void TestTimeStampImplicitCast()

DateTime now = DateTime.UtcNow;
ts = now;
Assert.Equal<DateTime>(now, ts);
Assert.Equal(new DateTimeOffset(now).ToUnixTimeMilliseconds(), ts.Value);

}
}
Expand Down