#18651: Fixing loss of millisenconds when using fields

Work Item : 18651

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-06-18 13:08:16 -07:00
parent eaf9cfcd4c
commit 17b300519c
4 changed files with 22 additions and 2 deletions

View File

@@ -8,5 +8,5 @@ e7fc05ff6137ed5459d198b2bea9a5804818b0bd src/Orchard.Web/Modules/Orchard.Forms
aca1f5aeb5dd426bc80c6142afc7f2717fc6d5a1 src/Orchard.Web/Modules/Orchard.Tokens
9f98da33ee293f29a3ea4a5a7c87246c171da0f0 src/Orchard.Web/Modules/Orchard.ViewPermissions
4ed51e0e76c2aacc2de90ce9984fd00cfdfae2ce src/orchard.web/Modules/Orchard.Alias
109844c63717ca7f881fb126a845184cca8de6f6 src/orchard.web/Modules/Orchard.Projections
d3a8dac3aca8deb5fd45e8864a4273a88a8741ee src/orchard.web/Modules/Orchard.Projections
0826b86677cd77cfb05342b3ba570f522dc3e786 src/orchard.web/modules/Orchard.Fields

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using NHibernate;
@@ -200,6 +201,14 @@ namespace Orchard.Tests.Data {
Assert.That(two.Name, Is.EqualTo("two"));
}
[Test]
public void StoringDateTimeDoesntRemovePrecision() {
_fooRepos.Create(new FooRecord { Name = "one", Timespan = DateTime.Parse("2001-01-01 16:28:21.489", CultureInfo.InvariantCulture) });
var one = _fooRepos.Fetch(f => f.Name == "one").Single();
Assert.That(one.Name, Is.EqualTo("one"));
Assert.That(one.Timespan.Value.Millisecond, Is.EqualTo(489));
}
}
}

View File

@@ -1,6 +1,9 @@
using System;
namespace Orchard.Tests.Records {
public class FooRecord {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual DateTime? Timespan { get; set; }
}
}

View File

@@ -28,7 +28,15 @@ namespace Orchard.ContentManagement.FieldStorage {
}
public void Set<T>(string name, T value) {
// using a special case for DateTime as it would lose milliseconds otherwise
if (typeof(T) == typeof(DateTime)) {
var text = ((DateTime)(object)value).ToString("o", CultureInfo.InvariantCulture);
Setter(name, typeof(T), text);
}
else {
Setter(name, typeof (T), Convert.ToString(value, CultureInfo.InvariantCulture));
}
}
}
}