/// <summary> /// Will return the value of DateTime.UtcNow at the time of the generation of the Guid will keep you from storing separate audit fields /// </summary> /// <param name="guid">A sequential Guid with the first 8 bytes containing the system ticks at time of generation</param> /// <returns>DateTime?</returns> public static DateTime?ToDateTime(this Guid guid) { var ticks = guid.ToTicks(); if (ticks.IsDateTime()) { return(ticks.ToDateTime()); } //Try conversion through sql guid ticks = new SqlGuid(guid).ToGuid().ToTicks(); return(ticks.IsDateTime() ? ticks.ToDateTime() : default(DateTime?)); }
/// <summary> /// Will return the value of SystemClock.Instance.GetCurrentInstant() at the time of the generation of the Guid will /// keep you from needing to store separate audit fields /// </summary> /// <param name="sqlGuid"> /// A sequential SqlGuid with the first sorted 8 bytes containing the system ticks at time of /// generation /// </param> /// <returns>Instant?</returns> public static Instant?ToInstant(this SqlGuid sqlGuid) => sqlGuid.ToDateTime().ToInstant();
/// <summary> /// Will return the value of SystemClock.Instance.GetCurrentInstant() at the time of the generation of the Guid will /// keep you from needing to store separate audit fields /// </summary> /// <param name="sqlGuid"> /// A sequential SqlGuid with the first sorted 8 bytes containing the system ticks at time of /// generation /// </param> /// <returns>Instant?</returns> public static Instant?ToInstant(this SqlGuid sqlGuid) { return(sqlGuid.ToDateTime().ToInstant()); }