Skip to content
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

Ajust YearWeek EndDate to midnight and adjust tests #11

Merged
merged 1 commit into from
Jan 8, 2024
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
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/YearWeek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public sealed class YearWeek : YearWeekBase, IComparable<YearWeek>
{
public YearWeek(int? week = null, int? year = null)
: base(GetStartDate(week, year), GetStartDate(week, year).AddDays(6))
: base(GetStartDate(week, year), GetStartDate(week, year).AddDays(6).ToMidnight())
{
Week = StartDate.GetWeekOfYear();
}
Expand Down Expand Up @@ -60,7 +60,7 @@
if (string.IsNullOrWhiteSpace(value))
return false;

var parts = value.Split('-', 'W');

Check warning on line 63 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)

Check warning on line 63 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)

Check warning on line 63 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)

Check warning on line 63 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)

Check warning on line 63 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 Down
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/YearWeekIso.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public sealed class YearWeekIso : YearWeekBase, IComparable<YearWeekIso>
{
public YearWeekIso(int week, int year)
: base(ISOWeek.ToDateTime(year, week, DayOfWeek.Monday), ISOWeek.ToDateTime(year, week, DayOfWeek.Sunday))
: base(ISOWeek.ToDateTime(year, week, DayOfWeek.Monday), ISOWeek.ToDateTime(year, week, DayOfWeek.Sunday).ToMidnight())
{
}

Expand Down Expand Up @@ -56,7 +56,7 @@
if (string.IsNullOrWhiteSpace(value))
return false;

var parts = value.Split('-', 'W');

Check warning on line 59 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)

Check warning on line 59 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)

Check warning on line 59 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)

Check warning on line 59 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)

Check warning on line 59 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void WithNullableDate_ToFormattedString()
public void WithDate_ToUTC()
{
Assert.Equal(new(2022, 6, 1, 5, 0, 0), new DateTime(2022, 6, 1, 0, 0, 0).ToUtc("Central Standard Time (Mexico)"));
Assert.Equal(new(2022, 6, 1, 5, 0, 0), new DateTime(2022, 6, 1, 0, 0, 0).ToUtc("Invalid Timezone Id"));
Assert.Equal(new(2022, 6, 1, 4, 0, 0), new DateTime(2022, 6, 1, 0, 0, 0).ToUtc("Invalid Timezone Id"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void WithWeek_Deconstruct()
yearMonth.Deconstruct(out DateTime startDate, out var endDate);

Assert.Equal(new(2022, 1, 2), startDate);
Assert.Equal(new(2022, 1, 8), endDate);
Assert.Equal(new DateTime(2022, 1, 8).ToMidnight(), endDate);
}

[Fact]
Expand All @@ -27,7 +27,7 @@ public void WithWeek_DateRange()
var yearMonth = new YearWeek(1, 2022);

Assert.Equal(new(2022, 1, 2), yearMonth.StartDate);
Assert.Equal(new(2022, 1, 8), yearMonth.EndDate);
Assert.Equal(new DateTime(2022, 1, 8).ToMidnight(), yearMonth.EndDate);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void WithWeek_Deconstruct()
yearMonth.Deconstruct(out DateTime startDate, out var endDate);

Assert.Equal(new(2022, 1, 3), startDate);
Assert.Equal(new(2022, 1, 9), endDate);
Assert.Equal(new DateTime(2022, 1, 9).ToMidnight(), endDate);
}

[Fact]
Expand All @@ -27,7 +27,7 @@ public void WithWeek_DateRange()
var yearMonth = new YearWeekIso(1, 2022);

Assert.Equal(new(2022, 1, 3), yearMonth.StartDate);
Assert.Equal(new(2022, 1, 9), yearMonth.EndDate);
Assert.Equal(new DateTime(2022, 1, 9).ToMidnight(), yearMonth.EndDate);
}

[Fact]
Expand Down