diff --git a/VisualCard.Calendar/Parts/Implementations/DateCreatedInfo.cs b/VisualCard.Calendar/Parts/Implementations/DateCreatedInfo.cs index 9aad8c7..d096fc1 100644 --- a/VisualCard.Calendar/Parts/Implementations/DateCreatedInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/DateCreatedInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset created = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset created = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information DateCreatedInfo _time = new(finalArgs, elementTypes, valueType, created); diff --git a/VisualCard.Calendar/Parts/Implementations/Event/DateEndInfo.cs b/VisualCard.Calendar/Parts/Implementations/Event/DateEndInfo.cs index d82712e..67db7b5 100644 --- a/VisualCard.Calendar/Parts/Implementations/Event/DateEndInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Event/DateEndInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset end = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset end = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information DateEndInfo _time = new(finalArgs, elementTypes, valueType, end); diff --git a/VisualCard.Calendar/Parts/Implementations/Event/DateStampInfo.cs b/VisualCard.Calendar/Parts/Implementations/Event/DateStampInfo.cs index 0859285..ab49d8f 100644 --- a/VisualCard.Calendar/Parts/Implementations/Event/DateStampInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Event/DateStampInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset stamp = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset stamp = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information DateStampInfo _time = new(finalArgs, elementTypes, valueType, stamp); diff --git a/VisualCard.Calendar/Parts/Implementations/Event/DateStartInfo.cs b/VisualCard.Calendar/Parts/Implementations/Event/DateStartInfo.cs index b9316af..777e1f4 100644 --- a/VisualCard.Calendar/Parts/Implementations/Event/DateStartInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Event/DateStartInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset start = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset start = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information DateStartInfo _time = new(finalArgs, elementTypes, valueType, start); diff --git a/VisualCard.Calendar/Parts/Implementations/LastModifiedInfo.cs b/VisualCard.Calendar/Parts/Implementations/LastModifiedInfo.cs index acbbef7..1f683b6 100644 --- a/VisualCard.Calendar/Parts/Implementations/LastModifiedInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/LastModifiedInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset created = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset created = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information LastModifiedInfo _time = new(finalArgs, elementTypes, valueType, created); diff --git a/VisualCard.Calendar/Parts/Implementations/Legacy/AudioAlarmInfo.cs b/VisualCard.Calendar/Parts/Implementations/Legacy/AudioAlarmInfo.cs index 5496141..f5ff96a 100644 --- a/VisualCard.Calendar/Parts/Implementations/Legacy/AudioAlarmInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Legacy/AudioAlarmInfo.cs @@ -83,7 +83,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string audioResource = split[3]; // Process the run time and the repeat times - DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime); + DateTimeOffset runTime = VcardCommonTools.ParsePosixDateTime(unprocessedRunTime); int repeat = 0; if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat)) throw new ArgumentException("Invalid repeat times"); diff --git a/VisualCard.Calendar/Parts/Implementations/Legacy/DaylightInfo.cs b/VisualCard.Calendar/Parts/Implementations/Legacy/DaylightInfo.cs index 7e602ec..bfa3525 100644 --- a/VisualCard.Calendar/Parts/Implementations/Legacy/DaylightInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Legacy/DaylightInfo.cs @@ -89,8 +89,8 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, // Process the UTC offset and start/end dates TimeSpan utcOffset = VcardCommonTools.ParseUtcOffset(unprocessedUtc); - DateTimeOffset startDate = VcardCommonTools.ParsePosixDate(unprocessedStart); - DateTimeOffset endDate = VcardCommonTools.ParsePosixDate(unprocessedEnd); + DateTimeOffset startDate = VcardCommonTools.ParsePosixDateTime(unprocessedStart); + DateTimeOffset endDate = VcardCommonTools.ParsePosixDateTime(unprocessedEnd); // Populate the fields DaylightInfo _geo = new(finalArgs, elementTypes, valueType, true, utcOffset, startDate, endDate, standard, daylight); diff --git a/VisualCard.Calendar/Parts/Implementations/Legacy/DisplayAlarmInfo.cs b/VisualCard.Calendar/Parts/Implementations/Legacy/DisplayAlarmInfo.cs index d7f8f0b..47abb7e 100644 --- a/VisualCard.Calendar/Parts/Implementations/Legacy/DisplayAlarmInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Legacy/DisplayAlarmInfo.cs @@ -83,7 +83,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string display = split[3]; // Process the run time and the repeat times - DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime); + DateTimeOffset runTime = VcardCommonTools.ParsePosixDateTime(unprocessedRunTime); int repeat = 0; if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat)) throw new ArgumentException("Invalid repeat times"); diff --git a/VisualCard.Calendar/Parts/Implementations/Legacy/MailAlarmInfo.cs b/VisualCard.Calendar/Parts/Implementations/Legacy/MailAlarmInfo.cs index c4aa7b0..054f301 100644 --- a/VisualCard.Calendar/Parts/Implementations/Legacy/MailAlarmInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Legacy/MailAlarmInfo.cs @@ -89,7 +89,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string note = split[4]; // Process the run time and the repeat times - DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime); + DateTimeOffset runTime = VcardCommonTools.ParsePosixDateTime(unprocessedRunTime); int repeat = 0; if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat)) throw new ArgumentException("Invalid repeat times"); diff --git a/VisualCard.Calendar/Parts/Implementations/Legacy/ProcedureAlarmInfo.cs b/VisualCard.Calendar/Parts/Implementations/Legacy/ProcedureAlarmInfo.cs index bac5b54..1c1fb17 100644 --- a/VisualCard.Calendar/Parts/Implementations/Legacy/ProcedureAlarmInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Legacy/ProcedureAlarmInfo.cs @@ -83,7 +83,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string procedure = split[3]; // Process the run time and the repeat times - DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime); + DateTimeOffset runTime = VcardCommonTools.ParsePosixDateTime(unprocessedRunTime); int repeat = 0; if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat)) throw new ArgumentException("Invalid repeat times"); diff --git a/VisualCard.Calendar/Parts/Implementations/RecDateInfo.cs b/VisualCard.Calendar/Parts/Implementations/RecDateInfo.cs index b8e0eee..2a8b1cf 100644 --- a/VisualCard.Calendar/Parts/Implementations/RecDateInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/RecDateInfo.cs @@ -67,7 +67,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, var recDateStrings = Regex.Unescape(value).Split(';'); recDates = recDateStrings.Select((date) => { - var parsedDate = VcardCommonTools.ParsePosixDate(date); + var parsedDate = VcardCommonTools.ParsePosixDateTime(date); return new TimePeriod(parsedDate, parsedDate); }).ToArray(); } @@ -82,7 +82,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, catch { // Not a period. Continue using normal date and time - var parsedDate = VcardCommonTools.ParsePosixDate(value); + var parsedDate = VcardCommonTools.ParsePosixDateTime(value); recDates = [new TimePeriod(parsedDate, parsedDate)]; } } diff --git a/VisualCard.Calendar/Parts/Implementations/Todo/DateCompletedInfo.cs b/VisualCard.Calendar/Parts/Implementations/Todo/DateCompletedInfo.cs index cc259e2..e01d2fb 100644 --- a/VisualCard.Calendar/Parts/Implementations/Todo/DateCompletedInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Todo/DateCompletedInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset completed = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset completed = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information DateCompletedInfo _time = new(finalArgs, elementTypes, valueType, completed); diff --git a/VisualCard.Calendar/Parts/Implementations/Todo/DueDateInfo.cs b/VisualCard.Calendar/Parts/Implementations/Todo/DueDateInfo.cs index 089d026..33f5beb 100644 --- a/VisualCard.Calendar/Parts/Implementations/Todo/DueDateInfo.cs +++ b/VisualCard.Calendar/Parts/Implementations/Todo/DueDateInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcalendarInternal(Version cardVersion) => internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset completed = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset completed = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information DueDateInfo _time = new(finalArgs, elementTypes, valueType, completed); diff --git a/VisualCard/Parsers/Recurrence/RecurrenceParserV1.cs b/VisualCard/Parsers/Recurrence/RecurrenceParserV1.cs index 49f2f10..798f299 100644 --- a/VisualCard/Parsers/Recurrence/RecurrenceParserV1.cs +++ b/VisualCard/Parsers/Recurrence/RecurrenceParserV1.cs @@ -140,7 +140,7 @@ public static RecurrenceRule[] ParseRuleV1(string rule) } // Is this designator an optional enddate? - if (VcardCommonTools.TryParsePosixDate(filtered, out DateTimeOffset endDate) && i == designators.Length - 1) + if (VcardCommonTools.TryParsePosixDateTime(filtered, out DateTimeOffset endDate) && i == designators.Length - 1) { // Check to see if this rule is the only rule if (rules.Count == 0) diff --git a/VisualCard/Parsers/Recurrence/RecurrenceParserV2.cs b/VisualCard/Parsers/Recurrence/RecurrenceParserV2.cs index 3473478..338f711 100644 --- a/VisualCard/Parsers/Recurrence/RecurrenceParserV2.cs +++ b/VisualCard/Parsers/Recurrence/RecurrenceParserV2.cs @@ -95,7 +95,7 @@ public static RecurrenceRule ParseRuleV2(string rule) case "UNTIL": // ( "UNTIL" "=" enddate ) // enddate = date / date-time - DateTimeOffset dateTime = VcardCommonTools.ParsePosixDate(valueRepresentation); + DateTimeOffset dateTime = VcardCommonTools.ParsePosixDateTime(valueRepresentation); recurrenceRule.endDate = dateTime; break; case "COUNT": diff --git a/VisualCard/Parsers/VcardCommonTools.cs b/VisualCard/Parsers/VcardCommonTools.cs index 4a98164..7890aa0 100644 --- a/VisualCard/Parsers/VcardCommonTools.cs +++ b/VisualCard/Parsers/VcardCommonTools.cs @@ -35,6 +35,11 @@ public static class VcardCommonTools [ @"yyyyMMdd", @"yyyy-MM-dd", + @"yyyyMM", + @"yyyy-MM", + @"yyyy", + @"--MMdd", + @"----dd", @"yyyyMMdd\THHmmss\Z", @"yyyyMMdd\THHmmss", @"yyyy-MM-dd\THH\:mm\:ss\Z", @@ -45,6 +50,11 @@ public static class VcardCommonTools [ @"yyyyMMdd", @"yyyy-MM-dd", + @"yyyyMM", + @"yyyy-MM", + @"yyyy", + @"--MMdd", + @"----dd", ]; private static readonly string[] supportedTimeFormats = @@ -54,40 +64,175 @@ public static class VcardCommonTools @"hh\:mm", @"hhmmss", @"hh\:mm\:ss", + @"-mmss", + @"--ss", + @"\Thh", + @"\Thhmm", + @"\Thh\:mm", + @"\Thhmmss", + @"\Thh\:mm\:ss", + @"\T-mmss", + @"\T--ss", + @"hh\Z", + @"hhmm\Z", + @"hh\:mm\Z", + @"hhmmss\Z", + @"hh\:mm\:ss\Z", + @"-mmss\Z", + @"--ss\Z", + @"\Thh\Z", + @"\Thhmm\Z", + @"\Thh\:mm\Z", + @"\Thhmmss\Z", + @"\Thh\:mm\:ss\Z", + @"\T-mmss\Z", + @"\T--ss\Z", + @"hhzz", + @"hhmmzz", + @"hh\:mmzz", + @"hhmmsszz", + @"hh\:mm\:sszz", + @"-mmsszz", + @"--sszz", + @"\Thhzz", + @"\Thhmmzz", + @"\Thh\:mmzz", + @"\Thhmmsszz", + @"\Thh\:mm\:sszz", + @"\T-mmsszz", + @"\T--sszz", + @"hhzzz", + @"hhmmzzz", + @"hh\:mmzzz", + @"hhmmsszzz", + @"hh\:mm\:sszzz", + @"-mmsszzz", + @"--sszzz", + @"\Thhzzz", + @"\Thhmmzzz", + @"\Thh\:mmzzz", + @"\Thhmmsszzz", + @"\Thh\:mm\:sszzz", + @"\T-mmsszzz", + @"\T--sszzz", + ]; + + private static readonly string[] supportedTimestampFormats = + [ + @"yyyyMMdd\THHmmsszz", + @"yyyyMMdd\THHmmsszzz", + @"yyyyMMdd\THHmmss\Z", + @"yyyyMMdd\THHmmss", + @"yyyy-MM-dd\THH\:mm\:sszz", + @"yyyy-MM-dd\THH\:mm\:sszzz", + @"yyyy-MM-dd\THH\:mm\:ss\Z", + @"yyyy-MM-dd\THH\:mm\:ss", ]; /// /// Parses the POSIX date formatted with the representation according to the vCard and vCalendar specifications /// /// Date representation in basic or extended format of ISO 8601 - /// Whether to accept only date /// An instance of that matches the representation /// - public static DateTimeOffset ParsePosixDate(string posixDateRepresentation, bool dateOnly = false) + public static DateTimeOffset ParsePosixDateTime(string posixDateRepresentation) => + ParsePosixRepresentation(posixDateRepresentation, supportedDateTimeFormats); + + /// + /// Tries to parse the POSIX date formatted with the representation according to the vCard and vCalendar specifications + /// + /// Date representation in basic or extended format of ISO 8601 + /// [] Date output parsed from the representation + /// True if parsed successfully; false otherwise. + public static bool TryParsePosixDateTime(string posixDateRepresentation, out DateTimeOffset date) { - // Check for sanity - if (string.IsNullOrEmpty(posixDateRepresentation)) - throw new ArgumentException($"Date representation is not provided."); + try + { + date = ParsePosixDateTime(posixDateRepresentation); + return true; + } + catch + { + return false; + } + } + + /// + /// Parses the POSIX date formatted with the representation according to the vCard and vCalendar specifications + /// + /// Date representation in basic or extended format of ISO 8601 + /// An instance of that matches the representation + /// + public static DateTimeOffset ParsePosixDate(string posixDateRepresentation) => + ParsePosixRepresentation(posixDateRepresentation, supportedDateFormats); - // Now, check the representation - bool assumeUtc = posixDateRepresentation[posixDateRepresentation.Length - 1] == 'Z'; - if (DateTimeOffset.TryParseExact(posixDateRepresentation, dateOnly ? supportedDateFormats : supportedDateTimeFormats, CultureInfo.InvariantCulture, assumeUtc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal, out var date)) - return date; - throw new ArgumentException($"Can't parse date {posixDateRepresentation}"); + /// + /// Tries to parse the POSIX date formatted with the representation according to the vCard and vCalendar specifications + /// + /// Date representation in basic or extended format of ISO 8601 + /// [] Date output parsed from the representation + /// True if parsed successfully; false otherwise. + public static bool TryParsePosixDate(string posixDateRepresentation, out DateTimeOffset date) + { + try + { + date = ParsePosixDate(posixDateRepresentation); + return true; + } + catch + { + return false; + } + } + + /// + /// Parses the POSIX date formatted with the representation according to the vCard and vCalendar specifications + /// + /// Date representation in basic or extended format of ISO 8601 + /// An instance of that matches the representation + /// + public static DateTimeOffset ParsePosixTime(string posixDateRepresentation) => + ParsePosixRepresentation(posixDateRepresentation, supportedTimeFormats); + + /// + /// Tries to parse the POSIX date formatted with the representation according to the vCard and vCalendar specifications + /// + /// Date representation in basic or extended format of ISO 8601 + /// [] Date output parsed from the representation + /// True if parsed successfully; false otherwise. + public static bool TryParsePosixTime(string posixDateRepresentation, out DateTimeOffset date) + { + try + { + date = ParsePosixTime(posixDateRepresentation); + return true; + } + catch + { + return false; + } } + /// + /// Parses the POSIX date formatted with the representation according to the vCard and vCalendar specifications + /// + /// Date representation in basic or extended format of ISO 8601 + /// An instance of that matches the representation + /// + public static DateTimeOffset ParsePosixTimestamp(string posixDateRepresentation) => + ParsePosixRepresentation(posixDateRepresentation, supportedTimestampFormats); + /// /// Tries to parse the POSIX date formatted with the representation according to the vCard and vCalendar specifications /// /// Date representation in basic or extended format of ISO 8601 - /// Whether to accept only date /// [] Date output parsed from the representation /// True if parsed successfully; false otherwise. - public static bool TryParsePosixDate(string posixDateRepresentation, out DateTimeOffset date, bool dateOnly = false) + public static bool TryParsePosixTimestamp(string posixDateRepresentation, out DateTimeOffset date) { try { - date = ParsePosixDate(posixDateRepresentation, dateOnly); + date = ParsePosixTime(posixDateRepresentation); return true; } catch @@ -276,9 +421,9 @@ public static TimePeriod GetTimePeriod(string period) string endStr = splits[1]; // Now, parse them - if (!TryParsePosixDate(startStr, out DateTimeOffset start)) + if (!TryParsePosixDateTime(startStr, out DateTimeOffset start)) throw new ArgumentException($"Invalid start date {startStr}: {period}"); - if (!TryParsePosixDate(endStr, out DateTimeOffset end)) + if (!TryParsePosixDateTime(endStr, out DateTimeOffset end)) end = GetDurationSpan(endStr, source: start).result; // Return a new object @@ -430,5 +575,18 @@ internal static Stream GetBlobData(string[]? args, string? keyEncoded) else throw new InvalidOperationException("Not a blob. You should somehow handle it."); } + + internal static DateTimeOffset ParsePosixRepresentation(string posixDateRepresentation, string[] formats) + { + // Check for sanity + if (string.IsNullOrEmpty(posixDateRepresentation)) + throw new ArgumentException($"Date representation is not provided."); + + // Now, check the representation + bool assumeUtc = posixDateRepresentation[posixDateRepresentation.Length - 1] == 'Z'; + if (DateTimeOffset.TryParseExact(posixDateRepresentation, formats, CultureInfo.InvariantCulture, assumeUtc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal, out var date)) + return date; + throw new ArgumentException($"Can't parse date {posixDateRepresentation}"); + } } } diff --git a/VisualCard/Parsers/VcardParserTools.cs b/VisualCard/Parsers/VcardParserTools.cs index f162937..847a21b 100644 --- a/VisualCard/Parsers/VcardParserTools.cs +++ b/VisualCard/Parsers/VcardParserTools.cs @@ -272,29 +272,28 @@ internal static string ProcessStringValue(string value, string valueType) break; case "DATE": // Check the date - if (!VcardCommonTools.TryParsePosixDate(finalValue, out _, true)) + if (!VcardCommonTools.TryParsePosixDate(finalValue, out _)) throw new InvalidDataException($"Date {finalValue} is invalid"); break; case "TIME": // Check the time - // TODO: Implement TryParsePosixDate with time only support - if (!VcardCommonTools.TryParsePosixDate(finalValue, out _)) + if (!VcardCommonTools.TryParsePosixTime(finalValue, out _)) throw new InvalidDataException($"Time {finalValue} is invalid"); break; case "DATE-TIME": // Check the date and time - if (!VcardCommonTools.TryParsePosixDate(finalValue, out _)) + if (!VcardCommonTools.TryParsePosixDateTime(finalValue, out _)) throw new InvalidDataException($"Date and time {finalValue} is invalid"); break; case "DATE-AND-OR-TIME": // Check the date and/or time - if (!VcardCommonTools.TryParsePosixDate(finalValue, out _)) + if (!VcardCommonTools.TryParsePosixDateTime(finalValue, out _) && + !VcardCommonTools.TryParsePosixTime(finalValue, out _)) throw new InvalidDataException($"Date and/or time {finalValue} is invalid"); break; case "TIMESTAMP": // Check the timestamp - // TODO: Implement TryParsePosixDate with timestamp support - if (!VcardCommonTools.TryParsePosixDate(finalValue, out _)) + if (!VcardCommonTools.TryParsePosixTimestamp(finalValue, out _)) throw new InvalidDataException($"Timestamp {finalValue} is invalid"); break; case "BOOLEAN": diff --git a/VisualCard/Parts/Implementations/AnniversaryInfo.cs b/VisualCard/Parts/Implementations/AnniversaryInfo.cs index 6801e59..2bc14b4 100644 --- a/VisualCard/Parts/Implementations/AnniversaryInfo.cs +++ b/VisualCard/Parts/Implementations/AnniversaryInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcardInternal(Version cardVersion) => internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) { // Populate the fields - DateTimeOffset anniversary = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset anniversary = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information AnniversaryInfo _time = new(-1, [], [], valueType, group, anniversary); diff --git a/VisualCard/Parts/Implementations/BirthDateInfo.cs b/VisualCard/Parts/Implementations/BirthDateInfo.cs index 1d7e101..8ad0f6d 100644 --- a/VisualCard/Parts/Implementations/BirthDateInfo.cs +++ b/VisualCard/Parts/Implementations/BirthDateInfo.cs @@ -43,7 +43,7 @@ internal override string ToStringVcardInternal(Version cardVersion) => internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) { // Populate field - DateTimeOffset bday = VcardCommonTools.ParsePosixDate(value); + DateTimeOffset bday = VcardCommonTools.ParsePosixDateTime(value); // Add the fetched information BirthDateInfo _time = new(altId, finalArgs, elementTypes, valueType, group, bday); diff --git a/VisualCard/Parts/Implementations/RevisionInfo.cs b/VisualCard/Parts/Implementations/RevisionInfo.cs index c122b33..7fc2d42 100644 --- a/VisualCard/Parts/Implementations/RevisionInfo.cs +++ b/VisualCard/Parts/Implementations/RevisionInfo.cs @@ -46,7 +46,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[ string revValue = value.Substring(VcardConstants._revSpecifier.Length + 1); // Populate the fields - DateTimeOffset rev = VcardCommonTools.ParsePosixDate(revValue); + DateTimeOffset rev = VcardCommonTools.ParsePosixDateTime(revValue); // Add the fetched information RevisionInfo _time = new(altId, finalArgs, elementTypes, valueType, group, rev);