-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor methods to improve code #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,9 @@ protected YearAbstract(DateTime startDate, DateTime endDate) | |
|
|
||
| public IReadOnlyCollection<int> Quarters { get; } | ||
|
|
||
| public abstract T Previous { get; } | ||
| public abstract T Previous(int offset = 1); | ||
|
|
||
| public abstract T Next { get; } | ||
| public abstract T Next(int offset = 1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| public abstract bool IsCurrent { get; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,9 @@ public YearEntity(DateTime? dateTime) | |
|
|
||
| public static YearEntity Current => new(); | ||
|
|
||
| public override YearEntity Next => new(StartDate.AddYears(1)); | ||
| public override YearEntity Next(int offset = 1) => new(StartDate.AddYears(offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of years to move forward.</param>
public override YearEntity Next(int offset = 1) => new(StartDate.AddYears(offset)); |
||
|
|
||
| public override YearEntity Previous => new(StartDate.AddYears(-1)); | ||
| public override YearEntity Previous(int offset = 1) => new(StartDate.AddYears(-offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of years to move backward.</param>
public override YearEntity Previous(int offset = 1) => new(StartDate.AddYears(-offset)); |
||
|
|
||
| public override bool IsCurrent => IsCurrentYear; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,9 +34,9 @@ public YearMonth(IYearWeek yearWeek) | |
|
|
||
| public YearEntity YearEntity => new(Year); | ||
|
|
||
| public override YearMonth Next => new(StartDate.AddMonths(1)); | ||
| public override YearMonth Next(int offset = 1) => new(StartDate.AddMonths(offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of months to move forward.</param>
public override YearMonth Next(int offset = 1) => new(StartDate.AddMonths(offset)); |
||
|
|
||
| public override YearMonth Previous => new(StartDate.AddMonths(-1)); | ||
| public override YearMonth Previous(int offset = 1) => new(StartDate.AddMonths(-offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of months to move backward.</param>
public override YearMonth Previous(int offset = 1) => new(StartDate.AddMonths(-offset)); |
||
|
|
||
| public override bool IsCurrent => Month == DateTime.UtcNow.Month && IsCurrentYear; | ||
|
|
||
|
|
@@ -97,4 +97,4 @@ public int CompareTo(YearMonth? other) | |
|
|
||
| return other is null ? 1 : base.CompareTo(other); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,9 +34,9 @@ | |
|
|
||
| public YearEntity YearEntity => new(Year); | ||
|
|
||
| public override YearQuarter Next => new(StartDate.AddMonths(QuarterMonths)); | ||
| public override YearQuarter Next(int offset = 1) => new(StartDate.AddMonths(QuarterMonths * offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of quarters to move forward.</param>
public override YearQuarter Next(int offset = 1) => new(StartDate.AddMonths(QuarterMonths * offset)); |
||
|
|
||
| public override YearQuarter Previous => new(StartDate.AddMonths(-QuarterMonths)); | ||
| public override YearQuarter Previous(int offset = 1) => new(StartDate.AddMonths(-QuarterMonths * offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of quarters to move backward.</param>
public override YearQuarter Previous(int offset = 1) => new(StartDate.AddMonths(-QuarterMonths * offset)); |
||
|
|
||
| public override bool IsCurrent => Quarter == DateTime.UtcNow.GetQuarter() && IsCurrentYear; | ||
|
|
||
|
|
@@ -71,7 +71,7 @@ | |
| if (string.IsNullOrWhiteSpace(value)) | ||
| return false; | ||
|
|
||
| var parts = value.Split('-', 'Q'); | ||
|
Check warning on line 74 in src/Unosquare.DateTimeExt/YearQuarter.cs
|
||
|
|
||
| if (parts.Length != 3 || !int.TryParse(parts[0], out var year) || !int.TryParse(parts[2], out var quarter)) | ||
| return false; | ||
|
|
@@ -92,4 +92,4 @@ | |
| year ?? DateTime.UtcNow.Year, | ||
| ((quarter ?? DateTime.UtcNow.GetQuarter()) - 1) * QuarterMonths + 1, | ||
| 1); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,9 @@ public YearToDate(int? year = null) | |
|
|
||
| public IReadOnlyCollection<YearQuarter> YearQuarters { get; } | ||
|
|
||
| public override YearToDate Previous => new(StartDate.AddYears(-1).Year); | ||
| public override YearToDate Previous(int offset = 1) => new(StartDate.AddYears(-offset).Year); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of years to move backward.</param>
public override YearToDate Previous(int offset = 1) => new(StartDate.AddYears(-offset).Year); |
||
|
|
||
| public override YearToDate Next => new(StartDate.AddYears(1).Year); | ||
| public override YearToDate Next(int offset = 1) => new(StartDate.AddYears(offset).Year); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of years to move forward.</param>
public override YearToDate Next(int offset = 1) => new(StartDate.AddYears(offset).Year); |
||
|
|
||
| public override bool IsCurrent => IsCurrentYear; | ||
|
|
||
|
|
@@ -42,4 +42,4 @@ public YearToDate(int? year = null) | |
| private static DateTime CalculateEndDate(int? year) => CalculateStartDate(year).AddYears(1).AddDays(-1).OrUtcNow(); | ||
|
|
||
| private static DateTime CalculateStartDate(int? year) => new(year ?? DateTime.UtcNow.Year, 1, 1); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,9 @@ | |
| public override int Week { get; } | ||
| public override int Year => StartDate.Year; | ||
|
|
||
| public override YearWeek Next => new(StartDate.AddDays(WeekDays)); | ||
| public override YearWeek Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of weeks to move forward.</param>
public override YearWeek Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset)); |
||
|
|
||
| public override YearWeek Previous => new(StartDate.AddDays(-WeekDays)); | ||
| public override YearWeek Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of weeks to move backward.</param>
public override YearWeek Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset)); |
||
|
|
||
| public override bool IsCurrent => IsCurrentYear && Week == DateTime.UtcNow.GetWeekOfYear(); | ||
|
|
||
|
|
@@ -61,7 +61,7 @@ | |
| if (string.IsNullOrWhiteSpace(value)) | ||
| return false; | ||
|
|
||
| var parts = value.Split('-', 'W'); | ||
|
Check warning on line 64 in src/Unosquare.DateTimeExt/YearWeek.cs
|
||
|
|
||
| if (parts.Length != 3 || !int.TryParse(parts[0], out var year) || !int.TryParse(parts[2], out var week)) | ||
| { | ||
|
|
@@ -75,4 +75,4 @@ | |
| private static int WeekYear => DateTime.UtcNow.Month == 1 && DateTime.UtcNow.GetWeekOfYear() > 5 | ||
| ? DateTime.UtcNow.Year - 1 | ||
| : DateTime.UtcNow.Year; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ public abstract class YearWeekBase<T>(DateTime startDate, DateTime endDate) | |
| { | ||
| protected const int WeekDays = 7; | ||
|
|
||
| public abstract T Previous { get; } | ||
| public abstract T Next { get; } | ||
| public abstract T Previous(int offset = 1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public abstract T Next(int offset = 1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public abstract bool IsCurrent { get; } | ||
| public abstract int Year { get; } | ||
| public abstract int Week { get; } | ||
|
|
@@ -25,4 +25,4 @@ public void Deconstruct(out int year, out int week) | |
| } | ||
|
|
||
| public override string ToString() => $"{Year}-W{Week.ToString().PadLeft(2, '0')}"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,9 +26,9 @@ | |
| public override int Week => ISOWeek.GetWeekOfYear(StartDate); | ||
| public override int Year => ISOWeek.GetYear(StartDate); | ||
|
|
||
| public override YearWeekIso Next => new(StartDate.AddDays(WeekDays)); | ||
| public override YearWeekIso Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of weeks to move forward.</param>
public override YearWeekIso Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset)); |
||
|
|
||
| public override YearWeekIso Previous => new(StartDate.AddDays(-WeekDays)); | ||
| public override YearWeekIso Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding XML documentation to describe the purpose of the /// <param name="offset">The number of weeks to move backward.</param>
public override YearWeekIso Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset)); |
||
|
|
||
| public override bool IsCurrent => IsCurrentYear && Week == ISOWeek.GetWeekOfYear(DateTime.UtcNow); | ||
|
|
||
|
|
@@ -53,7 +53,7 @@ | |
| if (string.IsNullOrWhiteSpace(value)) | ||
| return false; | ||
|
|
||
| var parts = value.Split('-', 'W'); | ||
|
Check warning on line 56 in src/Unosquare.DateTimeExt/YearWeekIso.cs
|
||
|
|
||
| if (parts.Length != 3 || !int.TryParse(parts[0], out var year) || !int.TryParse(parts[2], out var week)) | ||
| { | ||
|
|
@@ -63,4 +63,4 @@ | |
| result = new(week, year); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding XML documentation to describe the purpose of the
offsetparameter. This will improve the discoverability and usability of the method.