DateTime stohastic index use
See original GitHub issueHappyness,
This issue, it is in the LiteDB since the 3.x series, and still not fixed in the newest version.
The indexed Min Max values are stohastic. After insert in the same session they are ok, but after reopening the database (program restart) they returning UTC. The filtering looks good, but i am not sure if index is used there.
Here is a test code demonstrating the problem.
using System;
using System.IO;
using System.Linq;
using LiteDB;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LiteDBDateTimeIndexMinMax
{
[TestClass]
public class LiteDBDateTimeIndexMinMaxUnitTest
{
[TestMethod]
public void MinMaxStandardDateTime()
{
File.Delete("test.litedb");
LiteDatabase db1 = new LiteDatabase("test.litedb");
LiteCollection<DateTimeTest> coll1 = db1.GetCollection<DateTimeTest>();
coll1.EnsureIndex(x => x.dt);
coll1.Insert(new DateTimeTest() { DateTimeTestID = 1, dt = new DateTime(2018, 02, 22, 0, 0, 0) });
coll1.Insert(new DateTimeTest() { DateTimeTestID = 2, dt = new DateTime(2018, 02, 22, 23, 59, 59) });
MinMaxCommon(coll1);
db1.Dispose();
LiteDatabase db2 = new LiteDatabase("test.litedb");
LiteCollection<DateTimeTest> coll2 = db2.GetCollection<DateTimeTest>();
MinMaxCommon(coll2);
coll2.Insert(new DateTimeTest() { DateTimeTestID = 3, dt = new DateTime(2018, 02, 21, 23, 59, 59) });
coll2.Insert(new DateTimeTest() { DateTimeTestID = 4, dt = new DateTime(2018, 02, 23, 0, 0, 0) });
coll2.Insert(new DateTimeTest() { DateTimeTestID = 5, dt = new DateTime(2018, 02, 22, 0, 0, 1) });
coll2.Insert(new DateTimeTest() { DateTimeTestID = 6, dt = new DateTime(2018, 02, 22, 23, 59, 58) });
MinMaxCommon(coll2);
db2.Dispose();
LiteDatabase db3 = new LiteDatabase("test.litedb");
LiteCollection<DateTimeTest> coll3 = db3.GetCollection<DateTimeTest>();
MinMaxCommon(coll3);
}
private void MinMaxCommon(LiteCollection<DateTimeTest> coll)
{
var searchdatetime = new DateTime(2018, 02, 22, 0, 0, 10);
var min = coll.Min(x => x.dt).AsDateTime;
var max = coll.Max(x => x.dt).AsDateTime;
var smaller = coll.Find(x => x.dt < searchdatetime);
var greater = coll.Find(x => x.dt > searchdatetime);
var all = coll.FindAll().ToList();
var linqmin = all.Min(x => x.dt);
var linqmax = all.Max(x => x.dt);
Assert.AreEqual(min, linqmin);
Assert.AreEqual(max, linqmax);
}
public class DateTimeTest
{
public int DateTimeTestID { get; set; }
public DateTime? dt { get; set; }
public string mittomen { get; set; }
}
}
}
Joy and Harmony!
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Stochastic Oscillator: What It Is, How It Works, How To ...
A stochastic oscillator is a momentum indicator comparing a particular closing price of a security to a range of its prices over a...
Read more >Stochastics: An Accurate Buy and Sell Indicator
Easy to understand and highly accurate, stochastics is a technical indicator that shows when a stock has moved into an overbought or oversold...
Read more >Algorithmic Trading with Stochastic Oscillator in Python
Stochastic Oscillator is a momentum-based leading indicator that is widely used to identify whether the market is in the state of overbought or ......
Read more >Beginner's Guide to Trading with the Stochastic Oscillator ...
The Stochastic Oscillator is a great indicator to add to your trading algorithm. On its own, it can be used for momentum strategies, ......
Read more >Fast Stochastic Oscillator
The Fast Stochastic Oscillator is a momentum indicator that shows the location of the close relative to the high-low range over a set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @MiklosPathy, partial fixed. Now, index key are converted in Local date king. But, LiteDB has UTC parameter that are not used in this case. I will review this double serialize/deserialize bson implementation to use an single option.
Hi agan,
I ran the test with 5.10 and found exactly the same problem.
Here is the test adjusted for 5.x