From 7a00481bc6d7896deec94e2398c31eace0eef173 Mon Sep 17 00:00:00 2001 From: Jake Soenneker Date: Tue, 14 May 2024 12:05:05 -0500 Subject: [PATCH] format methods --- ...r.Extensions.DateTime.Hour.sln.DotSettings | 8 +++- src/DateTimeHourExtension.cs | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Soenneker.Extensions.DateTime.Hour.sln.DotSettings b/Soenneker.Extensions.DateTime.Hour.sln.DotSettings index ca6ccef..501e5e0 100644 --- a/Soenneker.Extensions.DateTime.Hour.sln.DotSettings +++ b/Soenneker.Extensions.DateTime.Hour.sln.DotSettings @@ -1,4 +1,4 @@ - + False 0 0 @@ -15,10 +15,16 @@ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></Policy> + <Policy><Descriptor Staticness="Instance" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Instance fields (not private)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Constant fields (not private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Static fields (not private)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> True True True True + True True 9999 True diff --git a/src/DateTimeHourExtension.cs b/src/DateTimeHourExtension.cs index 3af0f4d..41b34e7 100644 --- a/src/DateTimeHourExtension.cs +++ b/src/DateTimeHourExtension.cs @@ -109,4 +109,45 @@ public static System.DateTime ToEndOfPreviousHour(this System.DateTime dateTime) System.DateTime result = dateTime.ToEndOfHour().AddHours(-1); return result; } + + /// + /// Converts the specified UTC to the specified time zone + /// and returns the time in "h:mmtt" format. + /// + /// The UTC to convert. + /// The representing the desired time zone. + /// A string representing the time in "h:mmtt" format. + [Pure] + public static string ToTzHourFormat(this System.DateTime utc, System.TimeZoneInfo tzInfo) + { + System.DateTime tz = utc.ToTz(tzInfo); + + return tz.ToHourFormat(); + } + + /// + /// Converts the specified UTC to the start of the hour + /// in the specified time zone and returns the time in "h:mmtt" format. + /// + /// The UTC to convert. + /// The representing the desired time zone. + /// A string representing the start of the hour in "h:mmtt" format. + [Pure] + public static string ToTzHourFormatWithTrim(this System.DateTime utc, System.TimeZoneInfo tzInfo) + { + System.DateTime tz = utc.ToTz(tzInfo).ToStartOfHour(); + + return tz.ToHourFormat(); + } + + /// + /// Converts the specified to a string in "h:mmtt" format. + /// + /// The to format. + /// A string representing the time in "h:mmtt" format. + [Pure] + public static string ToHourFormat(this System.DateTime dateTime) + { + return dateTime.ToString("h:mmtt"); + } }