DateTime Save and Fetch

Topics: Customizing Orchard, Writing modules
Sep 21, 2012 at 11:34 PM

I have a custom Part that contains a date (DateTime). I set the date, create/store the Part and when I retrieve the Part with the date, the date has a DateTime.Kind of Unspecified. What I would like is to assume all my dates are Utc and when they are pulled out of the database and umarshalled into the Part, have it's Type set to Utc. What is the best way to do this? Is using a filter in the ContentHandler the place for this? Is it appropriate to update the Part in the OnLoading handler? I'm a bit new to Orchard.

Background: The issues is that I use this Part date in a view model that gets sent across the wire as JSON. The JavaScriptSerializer, for whatever reason, will apply a TimeZone transformation to Local and Unspecified DateTime Kind's. I could setup such that when I create the view model from the part, I make sure the date is Utc, but I'd rather do it at the lowest level possible.

Developer
Oct 4, 2012 at 11:52 AM

Using a ContentHandler would be perfect to initialize activated / loaded content parts.