mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#18651: Fixing loss of millisenconds when using fields
Work Item : 18651 --HG-- branch : 1.x
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
||||
}
|
@@ -28,7 +28,15 @@ namespace Orchard.ContentManagement.FieldStorage {
|
||||
}
|
||||
|
||||
public void Set<T>(string name, T value) {
|
||||
Setter(name, typeof(T), Convert.ToString(value, CultureInfo.InvariantCulture));
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user