From 1fb2d1d38330490d11cd35c4e4e1d6256b2c50c3 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 10 Feb 2023 09:32:50 -0800 Subject: [PATCH 1/2] Utilize DateTimeStyles.RoundtripKind https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip --- IntelliTect.Multitool/ReleaseDateAttribute.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IntelliTect.Multitool/ReleaseDateAttribute.cs b/IntelliTect.Multitool/ReleaseDateAttribute.cs index b054e37..75070e4 100644 --- a/IntelliTect.Multitool/ReleaseDateAttribute.cs +++ b/IntelliTect.Multitool/ReleaseDateAttribute.cs @@ -10,12 +10,12 @@ namespace IntelliTect.Multitool; public class ReleaseDateAttribute : Attribute { /// - /// Constructor called from csproj file + /// Constructor called from .targets file /// /// A utc O (round-trip date/time) format string public ReleaseDateAttribute(string utcDateString) { - ReleaseDate = DateTime.ParseExact(utcDateString, "O", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal); + ReleaseDate = DateTime.ParseExact(utcDateString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); } /// /// The date the assembly was built From 459b7a7d82151e050efbe2208180b877b4c9561c Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 10 Feb 2023 10:47:48 -0800 Subject: [PATCH 2/2] Update comments --- IntelliTect.Multitool/ReleaseDateAttribute.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/IntelliTect.Multitool/ReleaseDateAttribute.cs b/IntelliTect.Multitool/ReleaseDateAttribute.cs index 75070e4..e5ab34f 100644 --- a/IntelliTect.Multitool/ReleaseDateAttribute.cs +++ b/IntelliTect.Multitool/ReleaseDateAttribute.cs @@ -4,31 +4,34 @@ namespace IntelliTect.Multitool; /// -/// Information about the executing assembly. +/// The release date assembly attribute. /// [AttributeUsage(AttributeTargets.Assembly)] public class ReleaseDateAttribute : Attribute { /// - /// Constructor called from .targets file + /// Constructor that takes in a DateTime string /// - /// A utc O (round-trip date/time) format string + /// A DateTime 'O' (round-trip date/time) format string public ReleaseDateAttribute(string utcDateString) { ReleaseDate = DateTime.ParseExact(utcDateString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); } + /// /// The date the assembly was built /// public DateTime ReleaseDate { get; } + /// - /// Method to obtain the release date from the assembly attributes + /// Method to obtain the release date from the assembly attribute /// /// An assembly instance - /// The date time from compilation time + /// The date time from the assembly attribute public static DateTime? GetReleaseDate(Assembly? assembly = null) { object[]? attribute = (assembly ?? Assembly.GetEntryAssembly())?.GetCustomAttributes(typeof(ReleaseDateAttribute), false); return attribute?.Length >= 1 ? ((ReleaseDateAttribute)attribute[0]).ReleaseDate : null; } + } \ No newline at end of file