--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Local to what, the web/app machine?
Personally, I've had enough 'fun' with systems trying to be helpful by converting dates to local.
I don't want the db guessing what I need. If I give you data, give it back as is. :-)
DateTimeOffset or NodaTime when I need to be precise. Otherwise, I'll store utc myself.
I can see situations where only local time matter, but in general, yes.
I've been burned by systems with out of band time zone information. Oh, that field is UTC. No no no, the other field is EST. Grrrr.
--
string sSerializedDate = null;
{
JsonSerializerSettings settingsSerialize = new JsonSerializerSettings();
settingsSerialize.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
var jsonSeriazlier = Newtonsoft.Json.JsonSerializer.Create(settingsSerialize);
DateTime d = new DateTime(2012, 1, 1, 15, 0, 0, DateTimeKind.Local);
StringBuilder sbSerializedDate = new StringBuilder();
StringWriter swSerializedDate = new StringWriter(sbSerializedDate);
jsonSeriazlier.Serialize(swSerializedDate, d);
sSerializedDate = sbSerializedDate.ToString(); //value here is: 2012-01-01T14:00:00Z (UTC)
}
DateTime deserializedDate;
{
JsonSerializerSettings settingsDeserialize = new JsonSerializerSettings();
settingsDeserialize.DateTimeZoneHandling = DateTimeZoneHandling.Local;
var jsonDeserializer = Newtonsoft.Json.JsonSerializer.Create(settingsDeserialize);
StringReader srDeserializedDate = new StringReader(sSerializedDate);
deserializedDate = (DateTime)jsonDeserializer.Deserialize(srDeserializedDate, typeof(DateTime));
//date here is "01/Jan/12 3:00:00 PM" Kind=Local
}
What about when the date originates from a client in yet another time zone?
What about when you really want a local time in the db?
What about when you really trying to model a date without a time: March 3rd?
There are a lot of cases raven can't make universal assumptions about.
That said, maybe you can set the serializer for raven. It is json.net.
--
Since Matt turned me onto DateTimeOffset and the perils of time generally, it makes sense to use DateTimeOffset often...with or without raven db. :-)
--