Skip to content

Commit

Permalink
ref - Refactored type equality in info classes
Browse files Browse the repository at this point in the history
---

Type: ref
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 3, 2024
1 parent d94fd51 commit e203a5b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ internal override string ToStringVcalendarInternal(Version cardVersion)
internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, ArgumentInfo[] finalArgs, string[] elementTypes, string group, string valueType, Version cardVersion)
{
// Populate the fields
string type = valueType ?? "";
DateTimeOffset end =
type.Equals("date", StringComparison.OrdinalIgnoreCase) ?
valueType.Equals("date", StringComparison.OrdinalIgnoreCase) ?
VcardCommonTools.ParsePosixDate(value) :
VcardCommonTools.ParsePosixDateTime(value);

// Add the fetched information
DateEndInfo _time = new(finalArgs, elementTypes, group, valueType ?? "", end);
DateEndInfo _time = new(finalArgs, elementTypes, group, valueType, end);
return _time;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ internal override string ToStringVcalendarInternal(Version cardVersion)
internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, ArgumentInfo[] finalArgs, string[] elementTypes, string group, string valueType, Version cardVersion)
{
// Populate the fields
string type = valueType ?? "";
DateTimeOffset start =
type.Equals("date", StringComparison.OrdinalIgnoreCase) ?
valueType.Equals("date", StringComparison.OrdinalIgnoreCase) ?
VcardCommonTools.ParsePosixDate(value) :
VcardCommonTools.ParsePosixDateTime(value);

// Add the fetched information
DateStartInfo _time = new(finalArgs, elementTypes, group, valueType ?? "", start);
DateStartInfo _time = new(finalArgs, elementTypes, group, valueType, start);
return _time;
}

Expand Down
5 changes: 2 additions & 3 deletions VisualCard.Calendar/Parts/Implementations/ExDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,19 @@ internal override string ToStringVcalendarInternal(Version cardVersion)
internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, ArgumentInfo[] finalArgs, string[] elementTypes, string group, string valueType, Version cardVersion)
{
// Populate the fields
string type = valueType ?? "";
var exDates = Regex.Unescape(value).Split(cardVersion.Major == 1 ? ';' : ',');
List<DateTimeOffset> dates = [];
foreach (var exDate in exDates)
{
DateTimeOffset date =
type.Equals("date", StringComparison.OrdinalIgnoreCase) ?
valueType.Equals("date", StringComparison.OrdinalIgnoreCase) ?
VcardCommonTools.ParsePosixDate(exDate) :
VcardCommonTools.ParsePosixDateTime(exDate);
dates.Add(date);
}

// Add the fetched information
ExDateInfo _time = new([], elementTypes, group, valueType ?? "", [.. dates]);
ExDateInfo _time = new([], elementTypes, group, valueType, [.. dates]);
return _time;
}

Expand Down
7 changes: 3 additions & 4 deletions VisualCard.Calendar/Parts/Implementations/RecDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
else
{
// Check to see if it's a period
string type = valueType ?? "";
if (type.Equals("period", StringComparison.OrdinalIgnoreCase))
if (valueType.Equals("period", StringComparison.OrdinalIgnoreCase))
{
var parsedPeriod = VcardCommonTools.GetTimePeriod(value);
recDates = [parsedPeriod];
}
else if (type.Equals("date", StringComparison.OrdinalIgnoreCase))
else if (valueType.Equals("date", StringComparison.OrdinalIgnoreCase))
{
// Not a period. Use date
var parsedDate = VcardCommonTools.ParsePosixDate(value);
Expand All @@ -97,7 +96,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
}

// Add the fetched information
RecDateInfo _time = new([], elementTypes, group, valueType ?? "", recDates);
RecDateInfo _time = new([], elementTypes, group, valueType, recDates);
return _time;
}

Expand Down
5 changes: 2 additions & 3 deletions VisualCard.Calendar/Parts/Implementations/Todo/DueDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ internal override string ToStringVcalendarInternal(Version cardVersion)
internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, ArgumentInfo[] finalArgs, string[] elementTypes, string group, string valueType, Version cardVersion)
{
// Populate the fields
string type = valueType ?? "";
DateTimeOffset completed =
type.Equals("date", StringComparison.OrdinalIgnoreCase) ?
valueType.Equals("date", StringComparison.OrdinalIgnoreCase) ?
VcardCommonTools.ParsePosixDate(value) :
VcardCommonTools.ParsePosixDateTime(value);

// Add the fetched information
DueDateInfo _time = new(finalArgs, elementTypes, group, valueType ?? "", completed);
DueDateInfo _time = new(finalArgs, elementTypes, group, valueType, completed);
return _time;
}

Expand Down

0 comments on commit e203a5b

Please sign in to comment.