Quantcast
Channel: Customized Commerce 13 and earlier versions
Viewing all articles
Browse latest Browse all 9642

List of DateTime Property and DateTimeKind

$
0
0

I am trying to update page property programmatically.

The type of the property is IList<DateTime>.

The source list of dates contains only UTC dates  (DateTimeKind.Utc)

After saving changes and re-reading page object it turns out that all dates are converted to Local time

The question is: what a heck?

Code demo is below.

List<DateTime> newDays = GetDays(); // all UTC dates, 
HomePage page = _contentLoader.Get<HomePage>(pageRefHere);
var clone = page.CreateWritableClone() as HomePage;
clone.SpecialDateTimes = newDays; // SpecialDateTimes is still in utc here
_contentRepository.Save(clone, SaveAction.Publish, AccessLevel.NoAccess);
page = _contentLoader.Get<HomePage>(pageRefHere); // re-read page 
var days = page.SpecialDateTimes; // all dates are local now

Viewing all articles
Browse latest Browse all 9642

Trending Articles