Skip to content

Commit

Permalink
add - doc - Added COMPLETED property
Browse files Browse the repository at this point in the history
---

For to-dos, we've added the date of completion property.

---

Type: add
Breaking: False
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 11, 2024
1 parent 8868de4 commit f967668
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
1 change: 1 addition & 0 deletions VisualCard.Calendar/Parsers/VCalendarConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal static class VCalendarConstants
internal const string _tzUrlSpecifier = "TZURL";
internal const string _recurseSpecifier = "RRULE";
internal const string _recDateSpecifier = "RDATE";
internal const string _dateCompletedSpecifier = "COMPLETED";
internal const string _xSpecifier = "X-";
internal const string _typeArgumentSpecifier = "TYPE=";
internal const string _valueArgumentSpecifier = "VALUE=";
Expand Down
7 changes: 7 additions & 0 deletions VisualCard.Calendar/Parsers/VCalendarParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
using VisualCard.Calendar.Parts.Implementations.Event;
using VisualCard.Parts.Enums;
using System.Linq;
using VisualCard.Calendar.Parts.Implementations.TimeZone;
using VisualCard.Calendar.Parts.Implementations.Todo;

namespace VisualCard.Calendar.Parsers
{
Expand Down Expand Up @@ -77,6 +79,7 @@ internal static bool EnumArrayTypeSupported(CalendarPartsArrayEnum partsArrayEnu
CalendarPartsArrayEnum.DateCreatedAlt => TypeMatch(componentType, typeof(CalendarEvent), typeof(CalendarTodo)),
CalendarPartsArrayEnum.DateStart => TypeMatch(componentType, typeof(CalendarEvent), typeof(CalendarTodo), typeof(CalendarFreeBusy), typeof(CalendarStandard), typeof(CalendarDaylight)),
CalendarPartsArrayEnum.DateEnd => TypeMatch(componentType, typeof(CalendarEvent), typeof(CalendarFreeBusy)),
CalendarPartsArrayEnum.DateCompleted => TypeMatch(componentType, typeof(CalendarTodo)),
CalendarPartsArrayEnum.DateStamp => calendarVersion.Major == 2 && TypeMatch(componentType, typeof(CalendarEvent), typeof(CalendarTodo), typeof(CalendarJournal), typeof(CalendarFreeBusy)),
CalendarPartsArrayEnum.TimeZoneName => calendarVersion.Major == 2 && TypeMatch(componentType, typeof(CalendarTimeZone)),
CalendarPartsArrayEnum.RecDate => calendarVersion.Major == 2 && TypeMatch(componentType, typeof(CalendarEvent), typeof(CalendarTodo), typeof(CalendarJournal), typeof(CalendarStandard), typeof(CalendarDaylight)),
Expand Down Expand Up @@ -133,6 +136,7 @@ internal static string GetPrefixFromPartsArrayEnum(CalendarPartsArrayEnum partsA
CalendarPartsArrayEnum.DateCreatedAlt => VCalendarConstants._created1Specifier,
CalendarPartsArrayEnum.DateStart => VCalendarConstants._dateStartSpecifier,
CalendarPartsArrayEnum.DateEnd => VCalendarConstants._dateEndSpecifier,
CalendarPartsArrayEnum.DateCompleted => VCalendarConstants._dateCompletedSpecifier,
CalendarPartsArrayEnum.DateStamp => VCalendarConstants._dateStampSpecifier,
CalendarPartsArrayEnum.TimeZoneName => VCalendarConstants._tzNameSpecifier,
CalendarPartsArrayEnum.RecDate => VCalendarConstants._recDateSpecifier,
Expand Down Expand Up @@ -167,6 +171,8 @@ internal static (CalendarPartsArrayEnum, PartCardinality) GetPartsArrayEnumFromT
return (CalendarPartsArrayEnum.DateStart, PartCardinality.ShouldBeOne);
else if (partsArrayType == typeof(DateEndInfo))
return (CalendarPartsArrayEnum.DateEnd, PartCardinality.MayBeOne);
else if (partsArrayType == typeof(DateCompletedInfo))
return (CalendarPartsArrayEnum.DateCompleted, PartCardinality.MayBeOne);
else if (partsArrayType == typeof(DateStampInfo))
return (CalendarPartsArrayEnum.DateStamp, PartCardinality.MayBeOne);
else if (partsArrayType == typeof(TimeZoneNameInfo))
Expand All @@ -192,6 +198,7 @@ internal static (PartType type, object enumeration, Type? enumType, Func<string,
VCalendarConstants._created1Specifier => (PartType.PartsArray, CalendarPartsArrayEnum.DateCreatedAlt, typeof(DateCreatedInfo), DateCreatedInfo.FromStringVcalendarStatic, "", "", []),
VCalendarConstants._dateStartSpecifier => (PartType.PartsArray, CalendarPartsArrayEnum.DateStart, typeof(DateStartInfo), DateStartInfo.FromStringVcalendarStatic, "", "", []),
VCalendarConstants._dateEndSpecifier => (PartType.PartsArray, CalendarPartsArrayEnum.DateEnd, typeof(DateEndInfo), DateEndInfo.FromStringVcalendarStatic, "", "", []),
VCalendarConstants._dateCompletedSpecifier => (PartType.PartsArray, CalendarPartsArrayEnum.DateCompleted, typeof(DateCompletedInfo), DateCompletedInfo.FromStringVcalendarStatic, "", "", []),
VCalendarConstants._dateStampSpecifier => (PartType.PartsArray, CalendarPartsArrayEnum.DateStamp, typeof(DateStampInfo), DateStampInfo.FromStringVcalendarStatic, "", "", []),
VCalendarConstants._tzNameSpecifier => (PartType.PartsArray, CalendarPartsArrayEnum.TimeZoneName, typeof(TimeZoneNameInfo), TimeZoneNameInfo.FromStringVcalendarStatic, "", "", []),
VCalendarConstants._recDateSpecifier => (PartType.PartsArray, CalendarPartsArrayEnum.RecDate, typeof(RecDateInfo), RecDateInfo.FromStringVcalendarStatic, "", "", []),
Expand Down
4 changes: 4 additions & 0 deletions VisualCard.Calendar/Parts/Enums/CalendarPartsArrayEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,9 @@ public enum CalendarPartsArrayEnum
/// Recurrence date and time (event, todo, journal, or standard/daylight timezone components)
/// </summary>
RecDate,
/// <summary>
/// To-do date completion
/// </summary>
DateCompleted,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace VisualCard.Calendar.Parts.Implementations
namespace VisualCard.Calendar.Parts.Implementations.TimeZone
{
/// <summary>
/// Calendar time zone name info
Expand Down
111 changes: 111 additions & 0 deletions VisualCard.Calendar/Parts/Implementations/Todo/DateCompletedInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// VisualCard Copyright (C) 2021-2024 Aptivi
//
// This file is part of VisualCard
//
// VisualCard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// VisualCard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using System.Diagnostics;
using VisualCard.Parsers;

namespace VisualCard.Calendar.Parts.Implementations.Todo
{
/// <summary>
/// Card date completed info
/// </summary>
[DebuggerDisplay("Date Completed = {DateCompleted}")]
public class DateCompletedInfo : BaseCalendarPartInfo, IEquatable<DateCompletedInfo>
{
/// <summary>
/// The to-do completion date
/// </summary>
public DateTime DateCompleted { get; }

internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion) =>
new DateCompletedInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DateCompleted)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTime completed = VcardParserTools.ParsePosixDate(value);

// Add the fetched information
DateCompletedInfo _time = new(finalArgs, elementTypes, valueType, completed);
return _time;
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
Equals((DateCompletedInfo)obj);

/// <summary>
/// Checks to see if both the parts are equal
/// </summary>
/// <param name="other">The target <see cref="DateCompletedInfo"/> instance to check to see if they equal</param>
/// <returns>True if all the part elements are equal. Otherwise, false.</returns>
public bool Equals(DateCompletedInfo other) =>
Equals(this, other);

/// <summary>
/// Checks to see if both the parts are equal
/// </summary>
/// <param name="source">The source <see cref="DateCompletedInfo"/> instance to check to see if they equal</param>
/// <param name="target">The target <see cref="DateCompletedInfo"/> instance to check to see if they equal</param>
/// <returns>True if all the part elements are equal. Otherwise, false.</returns>
public bool Equals(DateCompletedInfo source, DateCompletedInfo target)
{
// We can't perform this operation on null.
if (source is null || target is null)
return false;

// Check all the properties
return
source.DateCompleted == target.DateCompleted
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 47832270;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + DateCompleted.GetHashCode();
return hashCode;
}

/// <inheritdoc/>
public static bool operator ==(DateCompletedInfo left, DateCompletedInfo right) =>
left.Equals(right);

/// <inheritdoc/>
public static bool operator !=(DateCompletedInfo left, DateCompletedInfo right) =>
!(left == right);

internal override bool EqualsInternal(BaseCalendarPartInfo source, BaseCalendarPartInfo target) =>
(DateCompletedInfo)source == (DateCompletedInfo)target;

internal DateCompletedInfo() { }

internal DateCompletedInfo(string[] arguments, string[] elementTypes, string valueType, DateTime rev) :
base(arguments, elementTypes, valueType)
{
DateCompleted = rev;
}
}
}

0 comments on commit f967668

Please sign in to comment.