/// <summary> /// Obtiene la fecha a partir de un Guid basado en la misma /// </summary> /// <param name="guid">Cadena que representa el guid</param> /// <param name="auxInformation">Devolverá la información auxiliar contenida</param> /// <param name="crcKey">Key usada para calcular el CRC</param> /// <returns>Fecha obtenida</returns> public static DateTime GuidToDate(string guid, out long dataOut, string crcKey) { DateTime date = DateTime.MinValue; string error = String.Empty; long data = 0; if (!GuidDate.Validate(guid, crcKey)) { error = "El guid no tiene un formato correcto o no coincide el checksum"; } string guidAux = new Regex(@"[^0-9a-fA-F]").Replace(guid, ""); try { int h, m, s, d, M, y, ms; s = Convert.ToInt32(guidAux.Substring(2, 2)); m = Convert.ToInt32(guidAux.Substring(4, 2)); h = Convert.ToInt32(guidAux.Substring(6, 2)); M = Convert.ToInt32(guidAux.Substring(8, 2)); d = Convert.ToInt32(guidAux.Substring(10, 2)); y = Convert.ToInt32(guidAux.Substring(13, 3), 16); ms = Convert.ToInt32(guidAux.Substring(16, 4), 16); dataOut = data = Convert.ToInt64(guidAux.Substring(20, 12), 16); date = new DateTime(y, M, d, h, m, s, ms); } catch (Exception ex) { throw new InvalidDateGuidException(ex.Message, ex, date, data); } if (!String.IsNullOrEmpty(error)) { throw new InvalidDateGuidException(error, date, data); } return(date); }
/// <summary> /// Valida que el checksun del GUID sea correcto /// </summary> /// <returns></returns> public bool Validate() { return(GuidDate.Validate(this.Guid, this.CRCKey)); }