Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/Interfaces/ILinkedEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public interface ILinkedEntity<out T>
{
T Previous { get; }
T Next { get; }
T Previous(int offset = 1);
T Next(int offset = 1);

bool IsCurrent { get; }
}
}
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/Unosquare.DateTimeExt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<Version>1.5.4</Version>
<Version>2.0.0</Version>
</PropertyGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearAbstract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of periods to move forward or backward.</param>
    public abstract T Previous(int offset = 1);


public abstract T Next { get; }
public abstract T Next(int offset = 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of periods to move forward or backward.</param>
    public abstract T Next(int offset = 1);


public abstract bool IsCurrent { get; }
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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;
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearMonth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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;

Expand Down Expand Up @@ -97,4 +97,4 @@ public int CompareTo(YearMonth? other)

return other is null ? 1 : base.CompareTo(other);
}
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearQuarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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;

Expand Down Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / Build

Review this call, which partially matches an overload without 'params'. The partial match is 'string[] string.Split(char separator, int count, StringSplitOptions options = StringSplitOptions.None)'. (https://rules.sonarsource.com/csharp/RSPEC-3220)

if (parts.Length != 3 || !int.TryParse(parts[0], out var year) || !int.TryParse(parts[2], out var quarter))
return false;
Expand All @@ -92,4 +92,4 @@
year ?? DateTime.UtcNow.Year,
((quarter ?? DateTime.UtcNow.GetQuarter()) - 1) * QuarterMonths + 1,
1);
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearToDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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;

Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearWeek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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();

Expand Down Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / Build

Review this call, which partially matches an overload without 'params'. The partial match is 'string[] string.Split(char separator, int count, StringSplitOptions options = StringSplitOptions.None)'. (https://rules.sonarsource.com/csharp/RSPEC-3220)

if (parts.Length != 3 || !int.TryParse(parts[0], out var year) || !int.TryParse(parts[2], out var week))
{
Expand All @@ -75,4 +75,4 @@
private static int WeekYear => DateTime.UtcNow.Month == 1 && DateTime.UtcNow.GetWeekOfYear() > 5
? DateTime.UtcNow.Year - 1
: DateTime.UtcNow.Year;
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearWeekBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move backward.</param>
    public abstract T Previous(int offset = 1);

public abstract T Next(int offset = 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move forward.</param>
    public abstract T Next(int offset = 1);

public abstract bool IsCurrent { get; }
public abstract int Year { get; }
public abstract int Week { get; }
Expand All @@ -25,4 +25,4 @@ public void Deconstruct(out int year, out int week)
}

public override string ToString() => $"{Year}-W{Week.ToString().PadLeft(2, '0')}";
}
}
6 changes: 3 additions & 3 deletions src/Unosquare.DateTimeExt/YearWeekIso.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <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);

Expand All @@ -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

View workflow job for this annotation

GitHub Actions / Build

Review this call, which partially matches an overload without 'params'. The partial match is 'string[] string.Split(char separator, int count, StringSplitOptions options = StringSplitOptions.None)'. (https://rules.sonarsource.com/csharp/RSPEC-3220)

if (parts.Length != 3 || !int.TryParse(parts[0], out var year) || !int.TryParse(parts[2], out var week))
{
Expand All @@ -63,4 +63,4 @@
result = new(week, year);
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public void WithMonth_Next()
{
var yearMonth = new YearMonth(month: 1, year: 2022);

Assert.Equal(new(2022, 2, 1), yearMonth.Next.StartDate);
Assert.Equal(new(2022, 2, 1), yearMonth.Next().StartDate);
}

[Fact]
public void WithMonth_Previous()
{
var yearMonth = new YearMonth(month: 2, year: 2022);

Assert.Equal(new(2022, 1, 1), yearMonth.Previous.StartDate);
Assert.Equal(new(2022, 1, 1), yearMonth.Previous().StartDate);
}

[Fact]
Expand Down Expand Up @@ -145,4 +145,4 @@ public void YearMonth_Deconstruct()
Assert.Equal(2022, year);
Assert.Equal(1, month);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ public void YearToDate_YearMonths()
Assert.Equal(12, yearMonths.Count);
Assert.Equal(new(2021, 1, 1), yearMonths.First().StartDate);
}
}

[Fact]
public void YearToDate_Previous()
{
var yearToDate = new YearToDate(2021);
var previousYearToDate = yearToDate.Previous();

Assert.Equal(2020, previousYearToDate.Year);
}

[Fact]
public void YearToDate_Next()
{
var yearToDate = new YearToDate(2021);
var nextYearToDate = yearToDate.Next();

Assert.Equal(2022, nextYearToDate.Year);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void WithWeek_Previous()
{
var yearMonth = new YearWeek(2, 2022);

Assert.Equal(new(2022, 1, 2), yearMonth.Previous.StartDate);
Assert.Equal(new(2022, 1, 2), yearMonth.Previous().StartDate);
}

[Fact]
public void WithWeek_Next()
{
var yearMonth = new YearWeek(1, 2022);

Assert.Equal(new(2022, 1, 9), yearMonth.Next.StartDate);
Assert.Equal(new(2022, 1, 9), yearMonth.Next().StartDate);
}

[Fact]
Expand Down Expand Up @@ -173,4 +173,4 @@ public void YearWeek_CompareTo()
Assert.Equal(-1, yearWeek1.CompareTo(yearWeek3));
Assert.Equal(1, yearWeek3.CompareTo(yearWeek1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void WithWeek_Previous()
{
var yearMonth = new YearWeekIso(2, 2022);

Assert.Equal(new(2022, 1, 3), yearMonth.Previous.StartDate);
Assert.Equal(new(2022, 1, 3), yearMonth.Previous().StartDate);
}

[Fact]
public void WithWeek_Next()
{
var yearMonth = new YearWeekIso(1, 2022);

Assert.Equal(new(2022, 1, 10), yearMonth.Next.StartDate);
Assert.Equal(new(2022, 1, 10), yearMonth.Next().StartDate);
}

[Fact]
Expand Down Expand Up @@ -173,4 +173,4 @@ public void YearWeekIso_CompareTo()
Assert.Equal(-1, yearWeek1.CompareTo(yearWeek3));
Assert.Equal(1, yearWeek3.CompareTo(yearWeek1));
}
}
}
Loading