protected override DateTime GetItemLastModified(XmlElement source) { // Last modification time of a folder is computed as the most recent last modification // time of any of its children walked recursively. Starting value is read from its // attribute which can be set by a direct operation like renaming. Last modification // of a file or of a common item has to be stored as an attribute of the item element // otherwise the creation date is returned - the item has not been modified yet. var modified = source.GetAttribute("Modified"); var date = string.IsNullOrEmpty(modified) ? GetItemCreated(source) : ValueUtility.GetDate(modified); if (GetItemType(source) == ItemType.Folder) { var children = source.ChildNodes.OfType <XmlElement>(); if (children.Any()) { var maximum = children.Max(item => GetItemLastModified(item)); if (maximum > date) { date = maximum; } } } return(date); }
protected override DateTime GetListLastDeleted(XmlElement source) { // Last deletion time inside a list has to be stored as an attribute otherwise an // invalid value is returned. var date = source.GetAttribute("Deleted"); return(string.IsNullOrEmpty(date) ? DateTime.MinValue : ValueUtility.GetDate(date)); }
DateTime GetListDate(XmlElement source, string name) { // List Properties Created and Modified come in the format YYYYMMDD HH:MM:SS. Other // properties with a date value come in the format YYYY-MM-DD HH:MM:SS which is // acceptable for the DateTime.Parse() method. Let's ensure the latter format. var value = source.GetAttribute(name); if (!value.Contains('-')) { value = value.Insert(6, "-").Insert(4, "-"); } return(ValueUtility.GetDate(value)); }
public void TestGetDate() { Assert.AreEqual(new DateTime(2012, 11, 30), ValueUtility.GetDate("2012-11-30")); Assert.AreEqual(new DateTime(2012, 11, 30, 01, 02, 03), ValueUtility.GetDate("2012-11-30 01:02:03")); try { ValueUtility.GetDate(""); Assert.Fail(); } catch {} try { ValueUtility.GetDate("1"); Assert.Fail(); } catch {} }
DateTime GetItemDate(XmlElement source, string rawName, string displayName) { var date = source.GetAttribute(rawName); if (!string.IsNullOrEmpty(date)) { return(ValueUtility.GetDate(date)); } date = source.GetAttribute(displayName); if (!string.IsNullOrEmpty(date)) { return(ValueUtility.GetDate(ValueUtility.GetLookupValue(date))); } return(DateTime.MinValue); }
protected override DateTime GetItemCreated(XmlElement source) { return(ValueUtility.GetDate(source.GetAttribute("Created"))); }