Skip to content

Commit

Permalink
Fix index DateTime litedb-org#922
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid committed Mar 17, 2018
1 parent 58747f7 commit aecb2d6
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 11 deletions.
6 changes: 3 additions & 3 deletions LiteDB.Shell/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LiteDB.Shell")]
[assembly: AssemblyCopyright("MIT © 2017")]
[assembly: AssemblyCopyright("MIT © 2014-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("01ce385b-31a7-4b1a-9487-23fe8acb3888")]
[assembly: AssemblyVersion("3.1.4.0")]
[assembly: AssemblyFileVersion("3.1.4.0")]
[assembly: AssemblyVersion("3.1.5.0")]
[assembly: AssemblyFileVersion("3.1.5.0")]
[assembly: NeutralResourcesLanguage("en")]

79 changes: 79 additions & 0 deletions LiteDB.Tests/Database/DateTimeMinMaxTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.IO;
using System.Linq;
using LiteDB;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LiteDB.Tests
{
#region Model

public class DateTimeTest
{
public int Id { get; set; }
public DateTime? Date { get; set; }
}

#endregion

[TestClass]
public class DateTimeMinMax_Tests
{
[TestMethod]
public void DateTimeMinMax_Test()
{
var memory = new MemoryStream();

using (var db = new LiteDatabase(memory))
{
var col = db.GetCollection<DateTimeTest>();
col.EnsureIndex(x => x.Date);

col.Insert(new DateTimeTest() { Id = 1, Date = new DateTime(2018, 02, 22, 0, 0, 0) });
col.Insert(new DateTimeTest() { Id = 2, Date = new DateTime(2018, 02, 22, 23, 59, 59) });

MinMaxCommon(col);
}

using (var db = new LiteDatabase(memory))
{
var col = db.GetCollection<DateTimeTest>();

MinMaxCommon(col);

col.Insert(new DateTimeTest() { Id = 3, Date = new DateTime(2018, 02, 21, 23, 59, 59) });
col.Insert(new DateTimeTest() { Id = 4, Date = new DateTime(2018, 02, 23, 0, 0, 0) });
col.Insert(new DateTimeTest() { Id = 5, Date = new DateTime(2018, 02, 22, 0, 0, 1) });
col.Insert(new DateTimeTest() { Id = 6, Date = new DateTime(2018, 02, 22, 23, 59, 58) });

MinMaxCommon(col);
}

using (var db = new LiteDatabase(memory))
{
var col = db.GetCollection<DateTimeTest>();

MinMaxCommon(col);
}
}

private void MinMaxCommon(LiteCollection<DateTimeTest> coll)
{
var searchdatetime = new DateTime(2018, 02, 22, 0, 0, 10);

var min = coll.Min(x => x.Date).AsDateTime;
var max = coll.Max(x => x.Date).AsDateTime;

var smaller = coll.FindOne(x => x.Date < searchdatetime);
var greater = coll.FindOne(x => x.Date > searchdatetime);

var all = coll.FindAll().ToList();

var linqmin = all.Min(x => x.Date);
var linqmax = all.Max(x => x.Date);

Assert.AreEqual(min, linqmin);
Assert.AreEqual(max, linqmax);
}
}
}
6 changes: 3 additions & 3 deletions LiteDB.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LiteDB.Tests")]
[assembly: AssemblyCopyright("MIT © 2017")]
[assembly: AssemblyCopyright("MIT © 2014-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: ComVisible(false)]
[assembly: Guid("de183e83-7df6-475c-8185-b0070d098821")]
[assembly: AssemblyVersion("3.1.4.0")]
[assembly: AssemblyFileVersion("3.1.4.0")]
[assembly: AssemblyVersion("3.1.5.0")]
[assembly: AssemblyFileVersion("3.1.5.0")]
2 changes: 1 addition & 1 deletion LiteDB.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>LiteDB</id>
<version>3.1.3</version>
<version>3.1.5</version>
<title>LiteDB</title>
<authors>Mauricio David</authors>
<projectUrl>http://www.litedb.org</projectUrl>
Expand Down
6 changes: 3 additions & 3 deletions LiteDB/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Maurício David")]
[assembly: AssemblyProduct("LiteDB")]
[assembly: AssemblyCopyright("MIT © 2017")]
[assembly: AssemblyCopyright("MIT © 2014-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("54989b5c-4bcf-4d58-b8ba-9b014a324f76")]
[assembly: AssemblyVersion("3.1.4.0")]
[assembly: AssemblyFileVersion("3.1.4.0")]
[assembly: AssemblyVersion("3.1.5.0")]
[assembly: AssemblyFileVersion("3.1.5.0")]
[assembly: NeutralResourcesLanguage("en")]
7 changes: 6 additions & 1 deletion LiteDB/Utils/ByteReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ public string ReadString(int length)

public DateTime ReadDateTime()
{
return new DateTime(this.ReadInt64(), DateTimeKind.Utc);
// fix #921 converting index key into LocalTime
// this is not best solution because uctDate must be a global parameter
// this will be review in v5
var date = new DateTime(this.ReadInt64(), DateTimeKind.Utc);

return date.ToLocalTime();
}

public Guid ReadGuid()
Expand Down

0 comments on commit aecb2d6

Please sign in to comment.