diff --git a/.gitignore b/.gitignore index 5df951d..5fe45c7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ local.properties .settings/ .loadpath +.vs + *.DotSettings *.ncrunchsolution @@ -32,7 +34,7 @@ local.properties .buildpath -NuGetBuild* +nugets* ################# diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..391a133 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,9 @@ + + + + + 7.1 + true + + + \ No newline at end of file diff --git a/FluentDateTime.sln b/FluentDateTime.sln new file mode 100644 index 0000000..765997f --- /dev/null +++ b/FluentDateTime.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.10 +MinimumVisualStudioVersion = 15.0.26730.10 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentDateTime", "FluentDateTime\FluentDateTime.csproj", "{D31AB307-F3A1-4F77-AC42-7077D822ED72}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|x86.ActiveCfg = Debug|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Any CPU.Build.0 = Release|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|x86.ActiveCfg = Release|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Debug|x86.ActiveCfg = Debug|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Debug|x86.Build.0 = Debug|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Release|Any CPU.Build.0 = Release|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Release|x86.ActiveCfg = Release|Any CPU + {D31AB307-F3A1-4F77-AC42-7077D822ED72}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {760A050D-CBB3-446F-9BC9-4484C9A51A5B} + EndGlobalSection +EndGlobal diff --git a/FluentDateTime/AssemblyInfo.cs b/FluentDateTime/AssemblyInfo.cs deleted file mode 100644 index faa8d38..0000000 --- a/FluentDateTime/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Reflection; - -[assembly: AssemblyTitle("FluentDateTime")] -[assembly: AssemblyProduct("FluentDateTime")] -[assembly: AssemblyVersion("1.13.0")] -[assembly: AssemblyFileVersion("1.13.0")] -[assembly: AssemblyCopyright("http://www.apache.org/licenses/LICENSE-2.0.html")] - diff --git a/FluentDateTime/DateTime/DateTimeExtensions.cs b/FluentDateTime/DateTime/DateTimeExtensions.cs index 12a2af4..cca4122 100644 --- a/FluentDateTime/DateTime/DateTimeExtensions.cs +++ b/FluentDateTime/DateTime/DateTimeExtensions.cs @@ -1,8 +1,9 @@ -namespace FluentDateTime +using System; +using System.Globalization; +using FluentDate; + +namespace FluentDateTime { - using System; - using System.Threading; - using FluentDate; /// /// Static class containing Fluent extension methods. @@ -220,7 +221,7 @@ public static DateTime SetMillisecond(this DateTime originalDate, int millisecon } /// - /// Returns original value with time part set to midnight (alias for method). + /// Returns original value with time part set to midnight (alias for method). /// public static DateTime Midnight(this DateTime value) { @@ -360,8 +361,8 @@ public static DateTime At(this DateTime current, int hour, int minute, int secon /// given with the day part set to the first day in the quarter. public static DateTime FirstDayOfQuarter(this DateTime current) { - var currentQuarter = (current.Month - 1)/3 + 1; - var firstDay = new DateTime(current.Year, 3*currentQuarter - 2, 1); + var currentQuarter = (current.Month - 1) / 3 + 1; + var firstDay = new DateTime(current.Year, 3 * currentQuarter - 2, 1); return current.SetDate(firstDay.Year, firstDay.Month, firstDay.Day); } @@ -384,8 +385,8 @@ public static DateTime FirstDayOfMonth(this DateTime current) /// given with the day part set to the last day in the quarter. public static DateTime LastDayOfQuarter(this DateTime current) { - var currentQuarter = (current.Month - 1)/3 + 1; - var firstDay = current.SetDate(current.Year, 3*currentQuarter - 2, 1); + var currentQuarter = (current.Month - 1) / 3 + 1; + var firstDay = current.SetDate(current.Year, 3 * currentQuarter - 2, 1); return firstDay.SetMonth(firstDay.Month + 2).LastDayOfMonth(); } @@ -454,6 +455,10 @@ public static bool IsInPast(this DateTime dateTime) return dateTime < DateTime.Now; } + /// + /// Rounds to the newarest . + /// + /// The rounded . public static DateTime Round(this DateTime dateTime, RoundTo rt) { DateTime rounded; @@ -461,45 +466,45 @@ public static DateTime Round(this DateTime dateTime, RoundTo rt) switch (rt) { case RoundTo.Second: - { - rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind); - if (dateTime.Millisecond >= 500) { - rounded = rounded.AddSeconds(1); + rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind); + if (dateTime.Millisecond >= 500) + { + rounded = rounded.AddSeconds(1); + } + break; } - break; - } case RoundTo.Minute: - { - rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0, dateTime.Kind); - if (dateTime.Second >= 30) { - rounded = rounded.AddMinutes(1); + rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0, dateTime.Kind); + if (dateTime.Second >= 30) + { + rounded = rounded.AddMinutes(1); + } + break; } - break; - } case RoundTo.Hour: - { - rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0, dateTime.Kind); - if (dateTime.Minute >= 30) { - rounded = rounded.AddHours(1); + rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0, dateTime.Kind); + if (dateTime.Minute >= 30) + { + rounded = rounded.AddHours(1); + } + break; } - break; - } case RoundTo.Day: - { - rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Kind); - if (dateTime.Hour >= 12) { - rounded = rounded.AddDays(1); + rounded = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Kind); + if (dateTime.Hour >= 12) + { + rounded = rounded.AddDays(1); + } + break; } - break; - } default: - { - throw new ArgumentOutOfRangeException("rt"); - } + { + throw new ArgumentOutOfRangeException("rt"); + } } return rounded; @@ -513,7 +518,7 @@ public static DateTime Round(this DateTime dateTime, RoundTo rt) /// the beginning of the week is controlled by the current Culture public static DateTime FirstDayOfWeek(this DateTime dateTime) { - var currentCulture = Thread.CurrentThread.CurrentCulture; + var currentCulture = CultureInfo.CurrentCulture; var firstDayOfWeek = currentCulture.DateTimeFormat.FirstDayOfWeek; var offset = dateTime.DayOfWeek - firstDayOfWeek < 0 ? 7 : 0; var numberOfDaysSinceBeginningOfTheWeek = dateTime.DayOfWeek + offset - firstDayOfWeek; diff --git a/FluentDateTime/DateTime/TimeSpanExtensions.cs b/FluentDateTime/DateTime/TimeSpanExtensions.cs index 8ee11b0..a2d8da5 100644 --- a/FluentDateTime/DateTime/TimeSpanExtensions.cs +++ b/FluentDateTime/DateTime/TimeSpanExtensions.cs @@ -3,213 +3,210 @@ using System; using FluentDate; - /// - /// Static class containing Fluent extension methods. - /// - public static class TimeSpanExtensions - { - - /// - /// Subtracts given from current date () and returns resulting in the past. - /// - public static DateTime Ago(this TimeSpan from) - { - return from.Before(DateTime.Now); - } - - /// - /// Subtracts given from current date () and returns resulting in the past. - /// - public static DateTime Ago(this FluentTimeSpan from) - { - return from.Before(DateTime.Now); - } - - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTime Ago(this TimeSpan from, DateTime originalValue) - { - return from.Before(originalValue); - } - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTime Ago(this FluentTimeSpan from, DateTime originalValue) - { - return from.Before(originalValue); - } - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTime Before(this TimeSpan from, DateTime originalValue) - { - return originalValue - from; - } - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTime Before(this FluentTimeSpan from, DateTime originalValue) - { - return originalValue.AddMonths(-from.Months).AddYears(-from.Years).Add(-from.TimeSpan); - } - - - /// - /// Adds given to current and returns resulting in the future. - /// - public static DateTime FromNow(this TimeSpan from) - { - return from.From(DateTime.Now); - } - - /// - /// Adds given to current and returns resulting in the future. - /// - public static DateTime FromNow(this FluentTimeSpan from) - { - return from.From(DateTime.Now); - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - public static DateTime From(this TimeSpan from, DateTime originalValue) - { - return originalValue + from; - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - public static DateTime From(this FluentTimeSpan from, DateTime originalValue) - { - return originalValue.AddMonths(from.Months).AddYears(from.Years).Add(from.TimeSpan); - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - /// - /// - /// Synonym of method. - /// - public static DateTime Since(this TimeSpan from, DateTime originalValue) - { - return From(from, originalValue); - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - /// - /// - /// Synonym of method. - /// - public static DateTime Since(this FluentTimeSpan from, DateTime originalValue) - { - return From(from, originalValue); - } - - - /// - /// Convert a to a human readable string. - /// - /// The to convert - /// A human readable string for - public static string ToDisplayString(this FluentTimeSpan timeSpan) - { - return ((TimeSpan)timeSpan).ToDisplayString(); - } - - /// - /// Convert a to a human readable string. - /// - /// The to convert - /// A human readable string for - public static string ToDisplayString(this TimeSpan timeSpan) - { - if (timeSpan.TotalDays > 1) - { - var round = timeSpan.Round(RoundTo.Hour); - return $"{round.Days} days and {round.Hours} hours"; - } - if (timeSpan.TotalHours > 1) - { - var round = timeSpan.Round(RoundTo.Minute); - return $"{round.Hours} hours and {round.Minutes} minutes"; - } - if (timeSpan.TotalMinutes > 1) - { - var round = timeSpan.Round(RoundTo.Second); - return $"{round.Minutes} minutes and {round.Seconds} seconds"; - } - if (timeSpan.TotalSeconds > 1) - { - return $"{timeSpan.TotalSeconds} seconds"; - } - return $"{timeSpan.Milliseconds} milliseconds"; - } - - - public static TimeSpan Round(this TimeSpan timeSpan, RoundTo rt) - { - TimeSpan rounded; - - switch (rt) - { - case RoundTo.Second: - { - rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); - if (timeSpan.Milliseconds >= 500) - { - rounded = rounded + 1.Seconds(); - } - break; - } - case RoundTo.Minute: - { - rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, 0); - if (timeSpan.Seconds >= 30) - { - rounded = rounded + 1.Minutes(); - } - break; - } - case RoundTo.Hour: - { - rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, 0, 0); - if (timeSpan.Minutes >= 30) - { - rounded = rounded + 1.Hours(); - } - break; - } - case RoundTo.Day: - { - rounded = new TimeSpan(timeSpan.Days, 0, 0, 0); - if (timeSpan.Hours >= 12) - { - rounded = rounded + 1.Days(); - } - break; - } - default: - { - throw new NotImplementedException(); - } - } - - return rounded; - } - - - - - //TODO: equality tests: DateIsEqual() TimeIsEqual() - } + /// + /// Static class containing Fluent extension methods. + /// + public static class TimeSpanExtensions + { + + /// + /// Subtracts given from current date () and returns resulting in the past. + /// + public static DateTime Ago(this TimeSpan from) + { + return from.Before(DateTime.Now); + } + + /// + /// Subtracts given from current date () and returns resulting in the past. + /// + public static DateTime Ago(this FluentTimeSpan from) + { + return from.Before(DateTime.Now); + } + + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTime Ago(this TimeSpan from, DateTime originalValue) + { + return from.Before(originalValue); + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTime Ago(this FluentTimeSpan from, DateTime originalValue) + { + return from.Before(originalValue); + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTime Before(this TimeSpan from, DateTime originalValue) + { + return originalValue - from; + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTime Before(this FluentTimeSpan from, DateTime originalValue) + { + return originalValue.AddMonths(-from.Months).AddYears(-from.Years).Add(-from.TimeSpan); + } + + + /// + /// Adds given to current and returns resulting in the future. + /// + public static DateTime FromNow(this TimeSpan from) + { + return from.From(DateTime.Now); + } + + /// + /// Adds given to current and returns resulting in the future. + /// + public static DateTime FromNow(this FluentTimeSpan from) + { + return from.From(DateTime.Now); + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + public static DateTime From(this TimeSpan from, DateTime originalValue) + { + return originalValue + from; + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + public static DateTime From(this FluentTimeSpan from, DateTime originalValue) + { + return originalValue.AddMonths(from.Months).AddYears(from.Years).Add(from.TimeSpan); + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + /// + /// + /// Synonym of method. + /// + public static DateTime Since(this TimeSpan from, DateTime originalValue) + { + return From(from, originalValue); + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + /// + /// + /// Synonym of method. + /// + public static DateTime Since(this FluentTimeSpan from, DateTime originalValue) + { + return From(from, originalValue); + } + + + /// + /// Convert a to a human readable string. + /// + /// The to convert + /// A human readable string for + public static string ToDisplayString(this FluentTimeSpan timeSpan) + { + return ((TimeSpan) timeSpan).ToDisplayString(); + } + + /// + /// Convert a to a human readable string. + /// + /// The to convert + /// A human readable string for + public static string ToDisplayString(this TimeSpan timeSpan) + { + if (timeSpan.TotalDays > 1) + { + var round = timeSpan.Round(RoundTo.Hour); + return $"{round.Days} days and {round.Hours} hours"; + } + if (timeSpan.TotalHours > 1) + { + var round = timeSpan.Round(RoundTo.Minute); + return $"{round.Hours} hours and {round.Minutes} minutes"; + } + if (timeSpan.TotalMinutes > 1) + { + var round = timeSpan.Round(RoundTo.Second); + return $"{round.Minutes} minutes and {round.Seconds} seconds"; + } + if (timeSpan.TotalSeconds > 1) + { + return $"{timeSpan.TotalSeconds} seconds"; + } + return $"{timeSpan.Milliseconds} milliseconds"; + } + + public static TimeSpan Round(this TimeSpan timeSpan, RoundTo rt) + { + TimeSpan rounded; + + switch (rt) + { + case RoundTo.Second: + { + rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); + if (timeSpan.Milliseconds >= 500) + { + rounded = rounded + 1.Seconds(); + } + break; + } + case RoundTo.Minute: + { + rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, 0); + if (timeSpan.Seconds >= 30) + { + rounded = rounded + 1.Minutes(); + } + break; + } + case RoundTo.Hour: + { + rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, 0, 0); + if (timeSpan.Minutes >= 30) + { + rounded = rounded + 1.Hours(); + } + break; + } + case RoundTo.Day: + { + rounded = new TimeSpan(timeSpan.Days, 0, 0, 0); + if (timeSpan.Hours >= 12) + { + rounded = rounded + 1.Days(); + } + break; + } + default: + { + throw new NotImplementedException(); + } + } + + return rounded; + } + + + //TODO: equality tests: DateIsEqual() TimeIsEqual() + } } \ No newline at end of file diff --git a/FluentDateTime/DateTimeOffset/DateTimeOffsetExtensions.cs b/FluentDateTime/DateTimeOffset/DateTimeOffsetExtensions.cs index 02db871..10f0519 100644 --- a/FluentDateTime/DateTimeOffset/DateTimeOffsetExtensions.cs +++ b/FluentDateTime/DateTimeOffset/DateTimeOffsetExtensions.cs @@ -1,8 +1,9 @@ -namespace FluentDateTimeOffset +using System.Globalization; +using System; +using FluentDate; + +namespace FluentDateTimeOffset { - using System; - using System.Threading; - using FluentDate; /// /// Static class containing Fluent extension methods. @@ -26,7 +27,7 @@ public static DateTimeOffset BeginningOfDay(this DateTimeOffset date) } /// - /// Returns the same date (same Day, Month, Hour, Minute, Second etc) in the next calendar year. + /// Returns the same date (same Day, Month, Hour, Minute, Second etc) in the next calendar year. /// If that day does not exist in next year in same month, number of missing days is added to the last day in same month next year. /// public static DateTimeOffset NextYear(this DateTimeOffset start) @@ -338,8 +339,8 @@ public static DateTimeOffset At(this DateTimeOffset current, int hour, int minut /// given with the day part set to the first day in the quarter. public static DateTimeOffset FirstDayOfQuarter(this DateTimeOffset current) { - var currentQuarter = (current.Month - 1)/3 + 1; - return current.SetDate(current.Year, 3*currentQuarter - 2, 1); + var currentQuarter = (current.Month - 1) / 3 + 1; + return current.SetDate(current.Year, 3 * currentQuarter - 2, 1); } /// @@ -360,8 +361,8 @@ public static DateTimeOffset FirstDayOfMonth(this DateTimeOffset current) /// given with the day part set to the last day in the quarter. public static DateTimeOffset LastDayOfQuarter(this DateTimeOffset current) { - var currentQuarter = (current.Month - 1)/3 + 1; - var firstDay = current.SetDate(current.Year, 3*currentQuarter - 2, 1); + var currentQuarter = (current.Month - 1) / 3 + 1; + var firstDay = current.SetDate(current.Year, 3 * currentQuarter - 2, 1); return firstDay.SetMonth(firstDay.Month + 2).LastDayOfMonth(); } @@ -375,7 +376,6 @@ public static DateTimeOffset LastDayOfMonth(this DateTimeOffset current) return current.SetDay(DateTime.DaysInMonth(current.Year, current.Month)); } - /// /// Adds the given number of business days to the . /// @@ -419,7 +419,6 @@ public static bool IsInFuture(this DateTimeOffset dateTime) return dateTime > DateTimeOffset.Now; } - /// /// Determine if a is in the past. /// @@ -430,6 +429,10 @@ public static bool IsInPast(this DateTimeOffset dateTime) return dateTime < DateTimeOffset.Now; } + /// + /// Rounds to the newarest . + /// + /// The rounded . public static DateTimeOffset Round(this DateTimeOffset dateTime, RoundTo rt) { DateTimeOffset rounded; @@ -437,45 +440,45 @@ public static DateTimeOffset Round(this DateTimeOffset dateTime, RoundTo rt) switch (rt) { case RoundTo.Second: - { - rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Offset); - if (dateTime.Millisecond >= 500) { - rounded = rounded.AddSeconds(1); + rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Offset); + if (dateTime.Millisecond >= 500) + { + rounded = rounded.AddSeconds(1); + } + break; } - break; - } case RoundTo.Minute: - { - rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0, dateTime.Offset); - if (dateTime.Second >= 30) { - rounded = rounded.AddMinutes(1); + rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0, dateTime.Offset); + if (dateTime.Second >= 30) + { + rounded = rounded.AddMinutes(1); + } + break; } - break; - } case RoundTo.Hour: - { - rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0, dateTime.Offset); - if (dateTime.Minute >= 30) { - rounded = rounded.AddHours(1); + rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0, dateTime.Offset); + if (dateTime.Minute >= 30) + { + rounded = rounded.AddHours(1); + } + break; } - break; - } case RoundTo.Day: - { - rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Offset); - if (dateTime.Hour >= 12) { - rounded = rounded.AddDays(1); + rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Offset); + if (dateTime.Hour >= 12) + { + rounded = rounded.AddDays(1); + } + break; } - break; - } default: - { - throw new ArgumentOutOfRangeException("rt"); - } + { + throw new ArgumentOutOfRangeException("rt"); + } } return rounded; @@ -489,13 +492,12 @@ public static DateTimeOffset Round(this DateTimeOffset dateTime, RoundTo rt) /// the beginning of the week is controlled by the current Culture public static DateTimeOffset FirstDayOfWeek(this DateTimeOffset dateTime) { - var currentCulture = Thread.CurrentThread.CurrentCulture; + var currentCulture = CultureInfo.CurrentCulture; var firstDayOfWeek = currentCulture.DateTimeFormat.FirstDayOfWeek; var offset = dateTime.DayOfWeek - firstDayOfWeek < 0 ? 7 : 0; var numberOfDaysSinceBeginningOfTheWeek = dateTime.DayOfWeek + offset - firstDayOfWeek; return dateTime.AddDays(-numberOfDaysSinceBeginningOfTheWeek); - } /// @@ -599,7 +601,7 @@ public static bool SameDay(this DateTimeOffset current, DateTimeOffset date) } /// - /// Determines whether the specified value is exactly the same month (month + year) then current. Eg, 2015-12-01 and 2014-12-01 => False + /// Determines whether the specified value is exactly the same month (month + year) then current. Eg, 2015-12-01 and 2014-12-01 => False /// /// The current value /// Value to compare with diff --git a/FluentDateTime/DateTimeOffset/TimeSpanExtensions.cs b/FluentDateTime/DateTimeOffset/TimeSpanExtensions.cs index 8b1aa6d..8c0704c 100644 --- a/FluentDateTime/DateTimeOffset/TimeSpanExtensions.cs +++ b/FluentDateTime/DateTimeOffset/TimeSpanExtensions.cs @@ -1,217 +1,214 @@ -namespace FluentDateTimeOffset -{ - - using System; - using FluentDate; +using System; +using FluentDate; +namespace FluentDateTimeOffset +{ - /// - /// Static class containing Fluent extension methods. - /// - public static class TimeSpanOffsetExtensions - { + /// + /// Static class containing Fluent extension methods. + /// + public static class TimeSpanOffsetExtensions + { - /// - /// Subtracts given from current date () and returns resulting in the past. - /// + /// + /// Subtracts given from current date () and returns resulting in the past. + /// public static DateTimeOffset Ago(this TimeSpan from) - { + { return from.Before(DateTimeOffset.Now); - } + } - /// + /// /// Subtracts given from current date () and returns resulting in the past. - /// + /// public static DateTimeOffset Ago(this FluentTimeSpan from) - { + { return from.Before(DateTimeOffset.Now); - } - - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTimeOffset Ago(this TimeSpan from, DateTimeOffset originalValue) - { - return from.Before(originalValue); - } - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTimeOffset Ago(this FluentTimeSpan from, DateTimeOffset originalValue) - { - return from.Before(originalValue); - } - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTimeOffset Before(this TimeSpan from, DateTimeOffset originalValue) - { - return originalValue - from; - } - - /// - /// Subtracts given from and returns resulting in the past. - /// - public static DateTimeOffset Before(this FluentTimeSpan from, DateTimeOffset originalValue) - { - return originalValue.AddMonths(-from.Months).AddYears(-from.Years).Add(-from.TimeSpan); - } - - - /// - /// Adds given to current and returns resulting in the future. - /// - public static DateTimeOffset FromNow(this TimeSpan from) - { + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTimeOffset Ago(this TimeSpan from, DateTimeOffset originalValue) + { + return from.Before(originalValue); + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTimeOffset Ago(this FluentTimeSpan from, DateTimeOffset originalValue) + { + return from.Before(originalValue); + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTimeOffset Before(this TimeSpan from, DateTimeOffset originalValue) + { + return originalValue - from; + } + + /// + /// Subtracts given from and returns resulting in the past. + /// + public static DateTimeOffset Before(this FluentTimeSpan from, DateTimeOffset originalValue) + { + return originalValue.AddMonths(-from.Months).AddYears(-from.Years).Add(-from.TimeSpan); + } + + /// + /// Adds given to current and returns resulting in the future. + /// + public static DateTimeOffset FromNow(this TimeSpan from) + { return from.From(DateTimeOffset.Now); - } + } - /// - /// Adds given to current and returns resulting in the future. - /// - public static DateTimeOffset FromNow(this FluentTimeSpan from) - { + /// + /// Adds given to current and returns resulting in the future. + /// + public static DateTimeOffset FromNow(this FluentTimeSpan from) + { return from.From(DateTimeOffset.Now); - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - public static DateTimeOffset From(this TimeSpan from, DateTimeOffset originalValue) - { - return originalValue + from; - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - public static DateTimeOffset From(this FluentTimeSpan from, DateTimeOffset originalValue) - { - return originalValue.AddMonths(from.Months).AddYears(from.Years).Add(from.TimeSpan); - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - /// - /// - /// Synonym of method. - /// - public static DateTimeOffset Since(this TimeSpan from, DateTimeOffset originalValue) - { - return From(from, originalValue); - } - - /// - /// Adds given to supplied and returns resulting in the future. - /// - /// - /// - /// Synonym of method. - /// - public static DateTimeOffset Since(this FluentTimeSpan from, DateTimeOffset originalValue) - { - return From(from, originalValue); - } - - - /// - /// Convert a to a human readable string. - /// - /// The to convert - /// A human readable string for - public static string ToDisplayString(this FluentTimeSpan timeSpan) - { - return ((TimeSpan)timeSpan).ToDisplayString(); - } - - /// - /// Convert a to a human readable string. - /// - /// The to convert - /// A human readable string for - public static string ToDisplayString(this TimeSpan timeSpan) - { - if (timeSpan.TotalDays > 1) - { - var round = timeSpan.Round(RoundTo.Hour); - return $"{round.Days} days and {round.Hours} hours"; - } - if (timeSpan.TotalHours > 1) - { - var round = timeSpan.Round(RoundTo.Minute); - return $"{round.Hours} hours and {round.Minutes} minutes"; - } - if (timeSpan.TotalMinutes > 1) - { - var round = timeSpan.Round(RoundTo.Second); - return $"{round.Minutes} minutes and {round.Seconds} seconds"; - } - if (timeSpan.TotalSeconds > 1) - { - return $"{timeSpan.TotalSeconds} seconds"; - } - return $"{timeSpan.Milliseconds} milliseconds"; - } - - - public static TimeSpan Round(this TimeSpan timeSpan, RoundTo rt) - { - TimeSpan rounded; - - switch (rt) - { - case RoundTo.Second: - { - rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); - if (timeSpan.Milliseconds >= 500) - { - rounded = rounded + 1.Seconds(); - } - break; - } - case RoundTo.Minute: - { - rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, 0); - if (timeSpan.Seconds >= 30) - { - rounded = rounded + 1.Minutes(); - } - break; - } - case RoundTo.Hour: - { - rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, 0, 0); - if (timeSpan.Minutes >= 30) - { - rounded = rounded + 1.Hours(); - } - break; - } - case RoundTo.Day: - { - rounded = new TimeSpan(timeSpan.Days, 0, 0, 0); - if (timeSpan.Hours >= 12) - { - rounded = rounded + 1.Days(); - } - break; - } - default: - { - throw new NotImplementedException(); - } - } - - return rounded; - } - - - - - //TODO: equality tests: DateIsEqual() TimeIsEqual() - } + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + public static DateTimeOffset From(this TimeSpan from, DateTimeOffset originalValue) + { + return originalValue + from; + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + public static DateTimeOffset From(this FluentTimeSpan from, DateTimeOffset originalValue) + { + return originalValue.AddMonths(from.Months).AddYears(from.Years).Add(from.TimeSpan); + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + /// + /// + /// Synonym of method. + /// + public static DateTimeOffset Since(this TimeSpan from, DateTimeOffset originalValue) + { + return From(from, originalValue); + } + + /// + /// Adds given to supplied and returns resulting in the future. + /// + /// + /// + /// Synonym of method. + /// + public static DateTimeOffset Since(this FluentTimeSpan from, DateTimeOffset originalValue) + { + return From(from, originalValue); + } + + /// + /// Convert a to a human readable string. + /// + /// The to convert + /// A human readable string for + public static string ToDisplayString(this FluentTimeSpan timeSpan) + { + return ((TimeSpan) timeSpan).ToDisplayString(); + } + + /// + /// Convert a to a human readable string. + /// + /// The to convert + /// A human readable string for + public static string ToDisplayString(this TimeSpan timeSpan) + { + if (timeSpan.TotalDays > 1) + { + var round = timeSpan.Round(RoundTo.Hour); + return $"{round.Days} days and {round.Hours} hours"; + } + if (timeSpan.TotalHours > 1) + { + var round = timeSpan.Round(RoundTo.Minute); + return $"{round.Hours} hours and {round.Minutes} minutes"; + } + if (timeSpan.TotalMinutes > 1) + { + var round = timeSpan.Round(RoundTo.Second); + return $"{round.Minutes} minutes and {round.Seconds} seconds"; + } + if (timeSpan.TotalSeconds > 1) + { + return $"{timeSpan.TotalSeconds} seconds"; + } + return $"{timeSpan.Milliseconds} milliseconds"; + } + + /// + /// Rounds to the newarest . + /// + /// The rounded . + public static TimeSpan Round(this TimeSpan timeSpan, RoundTo rt) + { + TimeSpan rounded; + + switch (rt) + { + case RoundTo.Second: + { + rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); + if (timeSpan.Milliseconds >= 500) + { + rounded = rounded + 1.Seconds(); + } + break; + } + case RoundTo.Minute: + { + rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, 0); + if (timeSpan.Seconds >= 30) + { + rounded = rounded + 1.Minutes(); + } + break; + } + case RoundTo.Hour: + { + rounded = new TimeSpan(timeSpan.Days, timeSpan.Hours, 0, 0); + if (timeSpan.Minutes >= 30) + { + rounded = rounded + 1.Hours(); + } + break; + } + case RoundTo.Day: + { + rounded = new TimeSpan(timeSpan.Days, 0, 0, 0); + if (timeSpan.Hours >= 12) + { + rounded = rounded + 1.Days(); + } + break; + } + default: + { + throw new NotImplementedException(); + } + } + + return rounded; + } + + + //TODO: equality tests: DateIsEqual() TimeIsEqual() + } } \ No newline at end of file diff --git a/FluentDateTime/FluentDateTime.csproj b/FluentDateTime/FluentDateTime.csproj new file mode 100644 index 0000000..c6d2057 --- /dev/null +++ b/FluentDateTime/FluentDateTime.csproj @@ -0,0 +1,25 @@ + + + netstandard1.4;net452 + Slobodan Pavkov, Tom Pester, Simon Cropp + http://www.apache.org/licenses/LICENSE-2.0.html + false + Copyright $([System.DateTime]::UtcNow.ToString(yyyy)) Slobodan Pavkov, Tom Pester, Simon Cropp. All rights reserved + DateTime + https://raw.github.com/FluentDateTime/FluentDateTime/master/Icons/package_icon.png + https://github.com/FluentDateTime/FluentDateTime + true + true + ..\nugets + 1591 + $(TargetsForTfmSpecificContentInPackage);IncludePDBsInPackage + + + + + + + + + + \ No newline at end of file diff --git a/FluentDateTime/FluentDateTimeNet35.csproj b/FluentDateTime/FluentDateTimeNet35.csproj deleted file mode 100644 index acc0eab..0000000 --- a/FluentDateTime/FluentDateTimeNet35.csproj +++ /dev/null @@ -1,70 +0,0 @@ - - - - obj\DotNet35 - Debug - AnyCPU - 9.0.30729 - 2.0 - {E999EA36-1B17-4EDA-A536-82D519F94C3B} - Library - Properties - FluentDateTime - FluentDateTime - v3.5 - 512 - true - ..\key.snk - Client - - - true - full - false - bin\DebugNet35\ - DEBUG;TRACE - prompt - 4 - bin\DebugNet35\FluentDateTime.xml - false - AllRules.ruleset - AnyCPU - - - pdbonly - true - bin\ReleaseNet35\ - TRACE - prompt - 4 - bin\ReleaseNet35\FluentDateTime.xml - AllRules.ruleset - AnyCPU - - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/FluentDateTime/FluentDateTimePCL.csproj b/FluentDateTime/FluentDateTimePCL.csproj deleted file mode 100644 index c7f4366..0000000 --- a/FluentDateTime/FluentDateTimePCL.csproj +++ /dev/null @@ -1,86 +0,0 @@ - - - - - obj\PCL - Debug - AnyCPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A} - Library - Properties - FluentDateTime - FluentDateTime - v4.0 - Profile328 - 512 - true - ..\key.snk - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - - - - - 4.0 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - bin\DebugPCL\ - DEBUG;TRACE - prompt - 4 - bin\DebugPCL\FluentDateTime.XML - - - pdbonly - true - bin\ReleasePCL\ - TRACE - prompt - 4 - bin\ReleasePCL\FluentDateTime.XML - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - - \ No newline at end of file diff --git a/FluentDateTime/FluentTimeSpan.cs b/FluentDateTime/FluentTimeSpan.cs index cafedfa..36c9af2 100644 --- a/FluentDateTime/FluentTimeSpan.cs +++ b/FluentDateTime/FluentTimeSpan.cs @@ -5,12 +5,12 @@ namespace FluentDate [StructLayout(LayoutKind.Sequential)] public struct FluentTimeSpan : IEquatable, IComparable, IComparable - { - public const int daysPerYear = 365; - public int Months { get; set; } - public int Years { get; set; } - public TimeSpan TimeSpan { get; set; } - + { + public const int daysPerYear = 365; + public int Months { get; set; } + public int Years { get; set; } + public TimeSpan TimeSpan { get; set; } + /// /// Indicates whether the current object is equal to another object of the same type. /// @@ -23,8 +23,6 @@ public bool Equals(FluentTimeSpan other) return this == other; } - - /// /// Adds two fluentTimeSpan according operator +. /// @@ -35,7 +33,6 @@ public FluentTimeSpan Add(FluentTimeSpan number) return AddInternal(this, number); } - /// /// Subtracts the number according -. /// @@ -46,9 +43,8 @@ public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) return SubtractInternal(this, fluentTimeSpan); } - /// - /// Overload of the operator + + /// Overload of the operator + /// /// The left hand fluentTimeSpan. /// The right hand fluentTimeSpan. @@ -57,20 +53,19 @@ public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) { return AddInternal(left, right); } + public static FluentTimeSpan operator +(FluentTimeSpan left, TimeSpan right) { return AddInternal(left, right); } - public static FluentTimeSpan operator +(TimeSpan left, FluentTimeSpan right) { return AddInternal(left, right); } - /// - /// Overload of the operator - + /// Overload of the operator - /// /// The left hand fluentTimeSpan. /// The right hand fluentTimeSpan. @@ -79,15 +74,16 @@ public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) { return SubtractInternal(left, right); } + public static FluentTimeSpan operator -(TimeSpan left, FluentTimeSpan right) { return SubtractInternal(left, right); } + public static FluentTimeSpan operator -(FluentTimeSpan left, TimeSpan right) { return SubtractInternal(left, right); } - /// /// Equals operator. @@ -99,13 +95,15 @@ public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) { return (left.Years == right.Years) && (left.Months == right.Months) && (left.TimeSpan == right.TimeSpan); } + public static bool operator ==(TimeSpan left, FluentTimeSpan right) { - return (FluentTimeSpan)left == right; + return (FluentTimeSpan) left == right; } + public static bool operator ==(FluentTimeSpan left, TimeSpan right) { - return left == (FluentTimeSpan)right; + return left == (FluentTimeSpan) right; } @@ -120,10 +118,12 @@ public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) { return !(left == right); } + public static bool operator !=(TimeSpan left, FluentTimeSpan right) { return !(left == right); } + public static bool operator !=(FluentTimeSpan left, TimeSpan right) { return !(left == right); @@ -134,85 +134,89 @@ public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) { return value.Negate(); } + public static bool operator <(FluentTimeSpan left, FluentTimeSpan right) { - return ((TimeSpan)left < (TimeSpan)right); + return ((TimeSpan) left < (TimeSpan) right); } + public static bool operator <(FluentTimeSpan left, TimeSpan right) { - return ((TimeSpan)left < right); + return ((TimeSpan) left < right); } + public static bool operator <(TimeSpan left, FluentTimeSpan right) { - return (left < (TimeSpan)right); + return (left < (TimeSpan) right); } public static bool operator <=(FluentTimeSpan left, FluentTimeSpan right) { - return ((TimeSpan)left <= (TimeSpan)right); + return ((TimeSpan) left <= (TimeSpan) right); } + public static bool operator <=(FluentTimeSpan left, TimeSpan right) { - return ((TimeSpan)left <= right); + return ((TimeSpan) left <= right); } public static bool operator <=(TimeSpan left, FluentTimeSpan right) { - return (left <= (TimeSpan)right); + return (left <= (TimeSpan) right); } public static bool operator >(FluentTimeSpan left, FluentTimeSpan right) { - return ((TimeSpan)left > (TimeSpan)right); + return ((TimeSpan) left > (TimeSpan) right); } + public static bool operator >(FluentTimeSpan left, TimeSpan right) { - return ((TimeSpan)left > right); + return ((TimeSpan) left > right); } + public static bool operator >(TimeSpan left, FluentTimeSpan right) { - return (left > (TimeSpan)right); + return (left > (TimeSpan) right); } public static bool operator >=(FluentTimeSpan left, FluentTimeSpan right) { - return ((TimeSpan)left >= (TimeSpan)right); + return ((TimeSpan) left >= (TimeSpan) right); } + public static bool operator >=(FluentTimeSpan left, TimeSpan right) { - return ((TimeSpan)left >= right); + return ((TimeSpan) left >= right); } + public static bool operator >=(TimeSpan left, FluentTimeSpan right) { - return (left >= (TimeSpan)right); + return (left >= (TimeSpan) right); } - /// /// Performs an explicit conversion from to . /// /// The FluentTimeSpan. /// The result of the conversion. - public static implicit operator TimeSpan(FluentTimeSpan fluentTimeSpan) + public static implicit operator TimeSpan(FluentTimeSpan fluentTimeSpan) { - var daysFromYears = daysPerYear*fluentTimeSpan.Years; - var daysFromMonths = 30*fluentTimeSpan.Months; - var days = daysFromMonths + daysFromYears; - return new TimeSpan(days, 0, 0, 0) + fluentTimeSpan.TimeSpan; + var daysFromYears = daysPerYear * fluentTimeSpan.Years; + var daysFromMonths = 30 * fluentTimeSpan.Months; + var days = daysFromMonths + daysFromYears; + return new TimeSpan(days, 0, 0, 0) + fluentTimeSpan.TimeSpan; } - /// + /// /// Performs an implicit conversion from a to . /// /// The that will be converted. /// The result of the conversion. public static implicit operator FluentTimeSpan(TimeSpan timeSpan) { - return new FluentTimeSpan { TimeSpan = timeSpan }; + return new FluentTimeSpan {TimeSpan = timeSpan}; } - - - /// /// Creates a new object that is a copy of the current instance. @@ -223,21 +227,19 @@ public static implicit operator FluentTimeSpan(TimeSpan timeSpan) public object Clone() { return new FluentTimeSpan - { - TimeSpan = TimeSpan, - Months = Months, - Years = Years - }; + { + TimeSpan = TimeSpan, + Months = Months, + Years = Years + }; } - /// public override string ToString() { - return ((TimeSpan)this).ToString(); + return ((TimeSpan) this).ToString(); } - /// public override bool Equals(object obj) { @@ -248,23 +250,21 @@ public override bool Equals(object obj) var type = obj.GetType(); if (type == typeof(FluentTimeSpan)) { - return this == (FluentTimeSpan)obj; + return this == (FluentTimeSpan) obj; } if (type == typeof(TimeSpan)) { - return this == (TimeSpan)obj; + return this == (TimeSpan) obj; } return false; } - /// public override int GetHashCode() { return Months.GetHashCode() ^ Years.GetHashCode() ^ TimeSpan.GetHashCode(); } - static FluentTimeSpan AddInternal(FluentTimeSpan left, FluentTimeSpan right) { return new FluentTimeSpan @@ -277,7 +277,6 @@ static FluentTimeSpan AddInternal(FluentTimeSpan left, FluentTimeSpan right) static FluentTimeSpan SubtractInternal(FluentTimeSpan left, FluentTimeSpan right) { - return new FluentTimeSpan { Years = left.Years - right.Years, @@ -289,40 +288,43 @@ static FluentTimeSpan SubtractInternal(FluentTimeSpan left, FluentTimeSpan right /// /// Gets the number of ticks that represent the value of the current structure. /// - public long Ticks => ((TimeSpan)this).Ticks; + public long Ticks => ((TimeSpan) this).Ticks; - public int Days => ((TimeSpan)this).Days; + public int Days => ((TimeSpan) this).Days; - public int Hours => ((TimeSpan)this).Hours; + public int Hours => ((TimeSpan) this).Hours; - public int Milliseconds => ((TimeSpan)this).Milliseconds; + public int Milliseconds => ((TimeSpan) this).Milliseconds; - public int Minutes => ((TimeSpan)this).Minutes; + public int Minutes => ((TimeSpan) this).Minutes; - public int Seconds => ((TimeSpan)this).Seconds; + public int Seconds => ((TimeSpan) this).Seconds; - public double TotalDays => ((TimeSpan)this).TotalDays; - public double TotalHours => ((TimeSpan)this).TotalHours; - public double TotalMilliseconds => ((TimeSpan)this).TotalMilliseconds; - public double TotalMinutes => ((TimeSpan)this).TotalMinutes; - public double TotalSeconds => ((TimeSpan)this).TotalSeconds; + public double TotalDays => ((TimeSpan) this).TotalDays; + public double TotalHours => ((TimeSpan) this).TotalHours; + public double TotalMilliseconds => ((TimeSpan) this).TotalMilliseconds; + public double TotalMinutes => ((TimeSpan) this).TotalMinutes; + public double TotalSeconds => ((TimeSpan) this).TotalSeconds; public int CompareTo(TimeSpan other) { - return ((TimeSpan)this).CompareTo(other); + return ((TimeSpan) this).CompareTo(other); } + public int CompareTo(object value) { if (value is TimeSpan) { - return ((TimeSpan)this).CompareTo((TimeSpan) value); + return ((TimeSpan) this).CompareTo((TimeSpan) value); } throw new ArgumentException("Value must be a TimeSpan", "value"); } + public int CompareTo(FluentTimeSpan value) { - return ((TimeSpan)this).CompareTo(value); + return ((TimeSpan) this).CompareTo(value); } + public TimeSpan Negate() { return new FluentTimeSpan diff --git a/FluentDateTime/NumberExtensions.cs b/FluentDateTime/NumberExtensions.cs index 6564033..a8757bb 100644 --- a/FluentDateTime/NumberExtensions.cs +++ b/FluentDateTime/NumberExtensions.cs @@ -2,19 +2,18 @@ { using System; - /// + /// /// Static class containing Fluent extension methods. /// public static class NumberExtensions { - /// /// Generates value for given number of Years. /// public static FluentTimeSpan Years(this int years) { - return new FluentTimeSpan { Years = years }; + return new FluentTimeSpan {Years = years}; } /// @@ -24,7 +23,7 @@ public static FluentTimeSpan Years(this int years) /// public static FluentTimeSpan Quarters(this int quarters) { - return new FluentTimeSpan { Months = quarters * 3 }; + return new FluentTimeSpan {Months = quarters * 3}; } /// @@ -32,7 +31,7 @@ public static FluentTimeSpan Quarters(this int quarters) /// public static FluentTimeSpan Months(this int months) { - return new FluentTimeSpan { Months = months }; + return new FluentTimeSpan {Months = months}; } /// @@ -40,7 +39,7 @@ public static FluentTimeSpan Months(this int months) /// public static FluentTimeSpan Weeks(this int weeks) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromDays(weeks * 7) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromDays(weeks * 7)}; } /// @@ -48,7 +47,7 @@ public static FluentTimeSpan Weeks(this int weeks) /// public static FluentTimeSpan Weeks(this double weeks) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromDays(weeks * 7) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromDays(weeks * 7)}; } /// @@ -56,7 +55,7 @@ public static FluentTimeSpan Weeks(this double weeks) /// public static FluentTimeSpan Days(this int days) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromDays(days) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromDays(days)}; } /// @@ -64,7 +63,7 @@ public static FluentTimeSpan Days(this int days) /// public static FluentTimeSpan Days(this double days) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromDays(days) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromDays(days)}; } /// @@ -72,7 +71,7 @@ public static FluentTimeSpan Days(this double days) /// public static FluentTimeSpan Hours(this int hours) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromHours(hours) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromHours(hours)}; } /// @@ -80,7 +79,7 @@ public static FluentTimeSpan Hours(this int hours) /// public static FluentTimeSpan Hours(this double hours) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromHours(hours) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromHours(hours)}; } /// @@ -88,7 +87,7 @@ public static FluentTimeSpan Hours(this double hours) /// public static FluentTimeSpan Minutes(this int minutes) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromMinutes(minutes) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromMinutes(minutes)}; } /// @@ -96,7 +95,7 @@ public static FluentTimeSpan Minutes(this int minutes) /// public static FluentTimeSpan Minutes(this double minutes) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromMinutes(minutes) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromMinutes(minutes)}; } /// @@ -104,7 +103,7 @@ public static FluentTimeSpan Minutes(this double minutes) /// public static FluentTimeSpan Seconds(this int seconds) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromSeconds(seconds) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromSeconds(seconds)}; } /// @@ -112,7 +111,7 @@ public static FluentTimeSpan Seconds(this int seconds) /// public static FluentTimeSpan Seconds(this double seconds) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromSeconds(seconds) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromSeconds(seconds)}; } /// @@ -120,7 +119,7 @@ public static FluentTimeSpan Seconds(this double seconds) /// public static FluentTimeSpan Milliseconds(this int milliseconds) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromMilliseconds(milliseconds) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromMilliseconds(milliseconds)}; } /// @@ -128,25 +127,24 @@ public static FluentTimeSpan Milliseconds(this int milliseconds) /// public static FluentTimeSpan Milliseconds(this double milliseconds) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromMilliseconds(milliseconds) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromMilliseconds(milliseconds)}; } /// - /// Returns for given number of ticks. + /// Returns for given number of ticks. /// - public static FluentTimeSpan Ticks(this int ticks) + public static FluentTimeSpan Ticks(this int ticks) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromTicks(ticks) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromTicks(ticks)}; } /// - /// Returns for given number of ticks. + /// Returns for given number of ticks. /// - public static FluentTimeSpan Ticks(this long ticks) + public static FluentTimeSpan Ticks(this long ticks) { - return new FluentTimeSpan { TimeSpan = TimeSpan.FromTicks(ticks) }; + return new FluentTimeSpan {TimeSpan = TimeSpan.FromTicks(ticks)}; } - } } \ No newline at end of file diff --git a/FluentDateTime/RoundTo.cs b/FluentDateTime/RoundTo.cs index e079418..91cc8db 100644 --- a/FluentDateTime/RoundTo.cs +++ b/FluentDateTime/RoundTo.cs @@ -3,23 +3,26 @@ /// /// Used for rounding precision /// - public enum RoundTo - { + public enum RoundTo + { /// /// Second precision. /// - Second, + Second, + /// /// Minute precision. /// Minute, + /// /// Hour precision. /// Hour, + /// /// Day precision. /// Day - } + } } \ No newline at end of file diff --git a/FluentDateTimeSolution.sln b/FluentDateTimeSolution.sln deleted file mode 100644 index cf025df..0000000 --- a/FluentDateTimeSolution.sln +++ /dev/null @@ -1,78 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.22823.1 -MinimumVisualStudioVersion = 14.0.22823.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentDateTimeTests", "FluentDateTimeTests\FluentDateTimeTests.csproj", "{3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}" - ProjectSection(ProjectDependencies) = postProject - {E999EA36-1B17-4EDA-A536-82D519F94C3B} = {E999EA36-1B17-4EDA-A536-82D519F94C3B} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NugetProject", "NuGet\NugetProject.csproj", "{D0C113B0-6DB4-4018-AFFA-603151840372}" - ProjectSection(ProjectDependencies) = postProject - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92} = {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentDateTimeNet35", "FluentDateTime\FluentDateTimeNet35.csproj", "{E999EA36-1B17-4EDA-A536-82D519F94C3B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentDateTimePCL", "FluentDateTime\FluentDateTimePCL.csproj", "{F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Debug|x86.ActiveCfg = Debug|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Any CPU.Build.0 = Release|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92}.Release|x86.ActiveCfg = Release|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Debug|x86.ActiveCfg = Debug|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Release|Any CPU.Build.0 = Release|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {D0C113B0-6DB4-4018-AFFA-603151840372}.Release|x86.ActiveCfg = Release|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Debug|x86.ActiveCfg = Debug|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Release|Any CPU.Build.0 = Release|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {E999EA36-1B17-4EDA-A536-82D519F94C3B}.Release|x86.ActiveCfg = Release|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Debug|x86.ActiveCfg = Debug|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Release|Any CPU.Build.0 = Release|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {F1D8A4DB-B141-4E34-A24B-BA3650B54B0A}.Release|x86.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(SubversionScc) = preSolution - Manager = AnkhSVN - Subversion Support for Visual Studio - Svn-Managed = True - EndGlobalSection -EndGlobal diff --git a/FluentDateTimeTests/FluentDateTimeTests.csproj b/FluentDateTimeTests/FluentDateTimeTests.csproj deleted file mode 100644 index 9e8d365..0000000 --- a/FluentDateTimeTests/FluentDateTimeTests.csproj +++ /dev/null @@ -1,91 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {3ECB8653-5EE6-46AF-8BF3-35E2473A1A92} - Library - Properties - FluentDateTimeTests - FluentDateTimeTests - v4.0 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - x86 - - - - False - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - {f1d8a4db-b141-4e34-a24b-ba3650b54b0a} - FluentDateTimePCL - - - - - - - - - - \ No newline at end of file diff --git a/FluentDateTimeTests/packages.config b/FluentDateTimeTests/packages.config deleted file mode 100644 index 512ce05..0000000 --- a/FluentDateTimeTests/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..5d702a1 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,2 @@ +assembly-versioning-scheme: Major +next-version: 1.14 diff --git a/NuGet/FluentDateTime-CodeOnly.nuspec b/NuGet/FluentDateTime-CodeOnly.nuspec deleted file mode 100644 index 1c1489e..0000000 --- a/NuGet/FluentDateTime-CodeOnly.nuspec +++ /dev/null @@ -1,17 +0,0 @@ - - - - FluentDateTime-CodeOnly - $version$ - FluentDateTime-CodeOnly - Slobodan Pavkov, Tom Pester, Simon Cropp - Slobodan Pavkov, Tom Pester, Simon Cropp - http://www.apache.org/licenses/LICENSE-2.0.html - https://github.com/FluentDateTime/FluentDateTime - https://raw.github.com/FluentDateTime/FluentDateTime/master/Icons/package_icon.png - false - A set of (Ruby inspired) C# Extension Methods for easier and more natural DateTime handling and operations in .NET. - en-AU - DateTime - - \ No newline at end of file diff --git a/NuGet/FluentDateTime.nuspec b/NuGet/FluentDateTime.nuspec deleted file mode 100644 index dc908b6..0000000 --- a/NuGet/FluentDateTime.nuspec +++ /dev/null @@ -1,17 +0,0 @@ - - - - FluentDateTime - $version$ - FluentDateTime - Slobodan Pavkov, Tom Pester, Simon Cropp - Slobodan Pavkov, Tom Pester, Simon Cropp - http://www.apache.org/licenses/LICENSE-2.0.html - https://github.com/FluentDateTime/FluentDateTime - https://raw.github.com/FluentDateTime/FluentDateTime/master/Icons/package_icon.png - false - A set of (Ruby inspired) C# Extension Methods for easier and more natural DateTime handling and operations in .NET. - en-AU - DateTime - - \ No newline at end of file diff --git a/NuGet/NugetProject.csproj b/NuGet/NugetProject.csproj deleted file mode 100644 index 8cc77b3..0000000 --- a/NuGet/NugetProject.csproj +++ /dev/null @@ -1,71 +0,0 @@ - - - - Debug - AnyCPU - {D0C113B0-6DB4-4018-AFFA-603151840372} - Library - - - Debug - - - Release - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - - - false - - - false - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/NuGet/packages.config b/NuGet/packages.config deleted file mode 100644 index ef61eae..0000000 --- a/NuGet/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/FluentDateTimeTests/DateAssert.cs b/Tests/DateAssert.cs similarity index 100% rename from FluentDateTimeTests/DateAssert.cs rename to Tests/DateAssert.cs diff --git a/FluentDateTimeTests/DateTimeOffsetTests.cs b/Tests/DateTimeOffsetTests.cs similarity index 93% rename from FluentDateTimeTests/DateTimeOffsetTests.cs rename to Tests/DateTimeOffsetTests.cs index df44b0f..035c7d8 100644 --- a/FluentDateTimeTests/DateTimeOffsetTests.cs +++ b/Tests/DateTimeOffsetTests.cs @@ -79,11 +79,7 @@ public void From_FromFixedDateTime_Tests(int value) Assert.AreEqual(value.Ticks().From(originalPointInTime), originalPointInTime.AddTicks(value)); } - - [Test] - [TestCase(24, ExpectedException = typeof (ArgumentOutOfRangeException))] - [TestCase(-1, ExpectedException = typeof (ArgumentOutOfRangeException))] [TestCase(0)] [TestCase(1)] [TestCase(23)] @@ -97,13 +93,23 @@ public void ChangeTime_Hour_SimpleTests(int value) Assert.AreEqual(expected, result); } + [Test] + [TestCase(24)] + [TestCase(-1)] + public void ChangeTime_Hour_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); + + Assert.Throws(() => + { + toChange.SetTime(value); + }); + } [Test] [TestCase(0)] [TestCase(16)] [TestCase(59)] - [TestCase(-1, ExpectedException = typeof (ArgumentOutOfRangeException))] - [TestCase(60, ExpectedException = typeof (ArgumentOutOfRangeException))] public void ChangeTime_Minute_SimpleTests(int value) { var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); @@ -111,12 +117,23 @@ public void ChangeTime_Minute_SimpleTests(int value) Assert.AreEqual(new DateTimeOffset(2008, 10, 25, 0, value, 0, 0, TimeSpan.Zero), toChange.SetTime(0, value)); } + [Test] + [TestCase(-1)] + [TestCase(60)] + public void ChangeTime_Minute_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); + + Assert.Throws(() => + { + toChange.SetTime(0, value); + }); + } + [Test] [TestCase(0)] [TestCase(16)] [TestCase(59)] - [TestCase(-1, ExpectedException = typeof (ArgumentOutOfRangeException))] - [TestCase(60, ExpectedException = typeof (ArgumentOutOfRangeException))] public void ChangeTime_Second_SimpleTests(int value) { var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); @@ -129,12 +146,23 @@ public void ChangeTime_Second_SimpleTests(int value) Assert.AreEqual(expected, changed); } + [Test] + [TestCase(-1)] + [TestCase(60)] + public void ChangeTime_Second_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); + + Assert.Throws(() => + { + toChange.SetTime(0, 0, value); + }); + } + [Test] [TestCase(0)] [TestCase(100)] [TestCase(999)] - [TestCase(-1, ExpectedException = typeof (ArgumentOutOfRangeException))] - [TestCase(1000, ExpectedException = typeof (ArgumentOutOfRangeException))] public void ChangeTime_Millisecond_SimpleTests(int value) { var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); @@ -142,6 +170,18 @@ public void ChangeTime_Millisecond_SimpleTests(int value) Assert.AreEqual(new DateTimeOffset(2008, 10, 25, 0, 0, 0, value, TimeSpan.Zero), toChange.SetTime(0, 0, 0, value)); } + [Test] + [TestCase(-1)] + [TestCase(1000)] + public void ChangeTime_Millisecond_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTimeOffset(2008, 10, 25, 0, 0, 0, 0, TimeSpan.Zero); + Assert.Throws(() => + { + toChange.SetTime(0, 0, 0, value); + }); + } + [Test] public void BasicTests() { @@ -192,7 +232,6 @@ public void BasicTests() var nextYearSameDateAsTodayNoon = TimeSpanOffsetExtensions.FromNow(1.Years()).Noon(); var twoWeeksFromNow = TimeSpanOffsetExtensions.FromNow(2.Weeks()); - } [Test] @@ -211,7 +250,6 @@ public void PreviousYear_ReturnsTheSameDateButPreviousYear() Assert.AreEqual(new DateTimeOffset(1975, 12, 31, 17, 0, 0, 0, TimeSpan.Zero), previousYear); } - [Test] public void NextYear_IfNextYearDoesNotHaveTheSameDayInTheSameMonthThenCalculateHowManyDaysIsMissingAndAddThatToTheLastDayInTheSameMonthNextYear() { @@ -514,7 +552,6 @@ public void PreviousMonth_PreviousMonthDoesntHaveThatManyDays() Assert.AreEqual(new DateTimeOffset(2009, 2, 28, 06, 40, 20, 5, TimeSpan.Zero), new DateTimeOffset(2009, 3, 31, 06, 40, 20, 5, TimeSpan.Zero).PreviousMonth()); } - [Test] public void NextMonth_BasicTest() { diff --git a/FluentDateTimeTests/DateTimeTests.cs b/Tests/DateTimeTests.cs similarity index 94% rename from FluentDateTimeTests/DateTimeTests.cs rename to Tests/DateTimeTests.cs index 236fc62..16c4d39 100644 --- a/FluentDateTimeTests/DateTimeTests.cs +++ b/Tests/DateTimeTests.cs @@ -79,11 +79,7 @@ public void From_FromFixedDateTime_Tests(int value) DateAssert.AreEqual(value.Ticks().From(originalPointInTime), originalPointInTime.AddTicks(value)); } - - [Test] - [TestCase(24, ExpectedException = typeof(ArgumentOutOfRangeException))] - [TestCase(-1, ExpectedException = typeof(ArgumentOutOfRangeException))] [TestCase(0)] [TestCase(1)] [TestCase(23)] @@ -97,13 +93,23 @@ public void ChangeTime_Hour_SimpleTests(int value) DateAssert.AreEqual(expected, result); } + [Test] + [TestCase(24)] + [TestCase(-1)] + public void ChangeTime_Hour_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); + + Assert.Throws(() => + { + toChange.SetTime(value); + }); + } [Test] [TestCase(0)] [TestCase(16)] [TestCase(59)] - [TestCase(-1, ExpectedException = typeof(ArgumentOutOfRangeException))] - [TestCase(60, ExpectedException = typeof(ArgumentOutOfRangeException))] public void ChangeTime_Minute_SimpleTests(int value) { var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); @@ -112,12 +118,22 @@ public void ChangeTime_Minute_SimpleTests(int value) DateAssert.AreEqual(expected, toChange.SetTime(0, value)); } + [Test] + [TestCase(-1)] + [TestCase(60)] + public void ChangeTime_Minute_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); + Assert.Throws(() => + { + toChange.SetTime(0, value); + }); + } + [Test] [TestCase(0)] [TestCase(16)] [TestCase(59)] - [TestCase(-1, ExpectedException = typeof(ArgumentOutOfRangeException))] - [TestCase(60, ExpectedException = typeof(ArgumentOutOfRangeException))] public void ChangeTime_Second_SimpleTests(int value) { var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); @@ -129,12 +145,23 @@ public void ChangeTime_Second_SimpleTests(int value) DateAssert.AreEqual(expected, changed); } + [Test] + [TestCase(-1)] + [TestCase(60)] + public void ChangeTime_Second_SimpleTests_Arg_Checks(int value) + { + var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); + + Assert.Throws(() => + { + toChange.SetTime(0, 0, value); + }); + } + [Test] [TestCase(0)] [TestCase(100)] [TestCase(999)] - [TestCase(-1, ExpectedException = typeof(ArgumentOutOfRangeException))] - [TestCase(1000, ExpectedException = typeof(ArgumentOutOfRangeException))] public void ChangeTime_Millisecond_SimpleTests(int value) { var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); @@ -143,16 +170,28 @@ public void ChangeTime_Millisecond_SimpleTests(int value) DateAssert.AreEqual(expected, toChange.SetTime(0, 0, 0, value)); } + [Test] + [TestCase(-1)] + [TestCase(1000)] + public void ChangeTime_Millisecond_SimpleTests_Arg_Check(int value) + { + var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local); + Assert.Throws(() => + { + toChange.SetTime(0, 0, 0, value); + }); + } + [Test] public void TimeZoneTests() { /* story: * 1. a web client submits a request to the server for "today", * 2. a developer uses :BeginningOfDay and :EndOfDay to perform clamping server-side. - * + * * expected: - * 3. user expects a timezone-correct utc responses from the server, - * + * 3. user expects a timezone-correct utc responses from the server, + * * actual: * 4. user receives a utc response that is too early (:BeginningOfDay), or * 5. user receives a utc response that is too late (:EndOfDay) @@ -243,7 +282,6 @@ public void PreviousYear_ReturnsTheSameDateButPreviousYear() DateAssert.AreEqual(expected, previousYear); } - [Test] public void NextYear_IfNextYearDoesNotHaveTheSameDayInTheSameMonthThenCalculateHowManyDaysIsMissingAndAddThatToTheLastDayInTheSameMonthNextYear() { @@ -350,7 +388,7 @@ public void FirstDayOfMonth_SetsTheDayToOne() var expected = new DateTime(2002, 12, 1, 17, 05, 01, DateTimeKind.Local); DateAssert.AreEqual(expected, new DateTime(2002, 12, 17, 17, 05, 01, DateTimeKind.Local).FirstDayOfMonth()); } - + [Test] public void PreviousQuarter_FirstDay_SetsTheDayToOne() { diff --git a/FluentDateTimeTests/FluentTimeSpanTests.cs b/Tests/FluentTimeSpanTests.cs similarity index 99% rename from FluentDateTimeTests/FluentTimeSpanTests.cs rename to Tests/FluentTimeSpanTests.cs index c3c5e67..5b84bdc 100644 --- a/FluentDateTimeTests/FluentTimeSpanTests.cs +++ b/Tests/FluentTimeSpanTests.cs @@ -7,8 +7,6 @@ public class FluentTimeSpanTests { - - [Test] [TestCase(1)] [TestCase(32)] diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj new file mode 100644 index 0000000..e02e70d --- /dev/null +++ b/Tests/Tests.csproj @@ -0,0 +1,12 @@ + + + + netcoreapp2.0;net452 + + + + + + + + \ No newline at end of file diff --git a/Tools/MSBuild.Community.Tasks.dll b/Tools/MSBuild.Community.Tasks.dll deleted file mode 100644 index 1423bfe..0000000 Binary files a/Tools/MSBuild.Community.Tasks.dll and /dev/null differ diff --git a/Tools/MSBuild.Community.Tasks.targets b/Tools/MSBuild.Community.Tasks.targets deleted file mode 100644 index a1c9189..0000000 --- a/Tools/MSBuild.Community.Tasks.targets +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - $(MSBuildExtensionsPath)\MSBuildCommunityTasks - $(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/repositories.config b/packages/repositories.config deleted file mode 100644 index 9ce1a52..0000000 --- a/packages/repositories.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file