public static DateTime GetDateTime(this BsonDocument doc, string fieldName, bool dateOnly = false) { DateTime def = Tools.DefaultDate; DateTime dt = def; string[] fields = fieldName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (fields.Length == 1) { dt = Tools.DefaultDate; var val = doc.GetValue(fieldName, dt); if (val.IsValidDateTime) { dt = val.ToUniversalTime(); } else { dt = Tools.ToDateTime(val.ToString(), dateOnly); } } else { var newindex = String.Join(".", fields.Skip(1).ToArray()); dt = BsonHelper.GetDateTime(doc.GetValue(fields[0]).AsBsonDocument, newindex, dateOnly); } if (dateOnly) { dt = Tools.ToDateTime(String.Format("{0:dd-MMM-yyyy}", dt)); } return(dt); }
public static DateIsland GetDateInfo(this BsonDocument d, string field) { DateTime dt = BsonHelper.GetDateTime(d, field); return(new DateIsland(dt)); }