Skip to content

Commit

Permalink
Revert record ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Nov 14, 2023
1 parent e0fc085 commit 6a1a2f2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/DateRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DateRange(DateTime startDate, DateTime? endDate = null)

public bool Contains(DateTime date) => StartDate <= date && EndDate >= date;

public DateRangeRecord ToRecord() => new(StartDate, EndDate);
public DateRangeRecord ToRecord() => new() { StartDate = StartDate, EndDate = EndDate };

public override string ToString() => $"{StartDate.ToShortDateString()} - {EndDate.ToShortDateString()}";

Expand Down
24 changes: 20 additions & 4 deletions src/Unosquare.DateTimeExt/Record-Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

namespace Unosquare.DateTimeExt;

public record DateRangeRecord(DateTime StartDate, DateTime EndDate) : IReadOnlyDateRange;
public record DateRangeRecord : IReadOnlyDateRange
{
public DateTime StartDate { get; init; }
public DateTime EndDate { get; init; }
}

public record YearMonthRecord(int Year, int Month) : IYearMonth;
public record YearMonthRecord : IYearMonth
{
public int Year { get; init; }
public int Month { get; init; }
}

public record YearQuarterRecord(int Year, int Quarter) : IYearQuarter;
public record YearQuarterRecord : IYearQuarter
{
public int Year { get; init; }
public int Quarter { get; init; }
}

public record YearWeekRecord(int Year, int Week) : IYearWeek;
public record YearWeekRecord : IYearWeek
{
public int Year { get; init; }
public int Week { get; init; }
}
4 changes: 2 additions & 2 deletions src/Unosquare.DateTimeExt/Unosquare.DateTimeExt.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<Version>1.1.28</Version>
<Version>1.2.0</Version>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/YearMonth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static bool TryParse(string? value, out YearMonth range)

public DateOnly DayOnly(int day) => new(Year, Month, day);

public new YearMonthRecord ToRecord() => new(Year, Month);
public new YearMonthRecord ToRecord() => new() { Year = Year, Month = Month };

public void Deconstruct(out int year, out int month)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/YearQuarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public YearQuarter(DateTime? dateTime)

public YearQuarter ToQuarter(int? quarter) => new(quarter, Year);

public new YearQuarterRecord ToRecord() => new(Year, Quarter);
public new YearQuarterRecord ToRecord() => new() { Year = Year, Quarter = Quarter };

public void Deconstruct(out int year, out int quarter)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.DateTimeExt/YearWeek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static DateTime GetStartDate(int? week = null, int? year = null) =>

public YearWeek ToWeek(int? week) => new(week, Year);

public new YearWeekRecord ToRecord() => new(Year, Week);
public new YearWeekRecord ToRecord() => new() { Year = Year, Week = Week };

public void Deconstruct(out int year, out int week)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void DateRangeRecord_ShouldCreateInstance_WithValidDates()
var endDate = new DateTime(2022, 1, 31);

// Act
var dateRange = new DateRangeRecord(startDate, endDate);
var dateRange = new DateRangeRecord { StartDate = startDate, EndDate = endDate};

// Assert
Assert.Equal(startDate, dateRange.StartDate);
Expand All @@ -21,11 +21,11 @@ public void DateRangeRecord_ShouldCreateInstance_WithValidDates()
public void YearMonthRecord_ShouldCreateInstance_WithValidYearAndMonth()
{
// Arrange
var year = 2022;
var month = 1;
const int year = 2022;
const int month = 1;

// Act
var yearMonth = new YearMonthRecord(year, month);
var yearMonth = new YearMonthRecord { Year = year, Month = month };

// Assert
Assert.Equal(year, yearMonth.Year);
Expand All @@ -36,11 +36,11 @@ public void YearMonthRecord_ShouldCreateInstance_WithValidYearAndMonth()
public void YearQuarterRecord_ShouldCreateInstance_WithValidYearAndQuarter()
{
// Arrange
var year = 2022;
var quarter = 1;
const int year = 2022;
const int quarter = 1;

// Act
var yearQuarter = new YearQuarterRecord(year, quarter);
var yearQuarter = new YearQuarterRecord { Year = year, Quarter = quarter };

// Assert
Assert.Equal(year, yearQuarter.Year);
Expand All @@ -51,11 +51,11 @@ public void YearQuarterRecord_ShouldCreateInstance_WithValidYearAndQuarter()
public void YearWeekRecord_ShouldCreateInstance_WithValidYearAndWeek()
{
// Arrange
var year = 2022;
var week = 1;
const int year = 2022;
const int week = 1;

// Act
var yearWeek = new YearWeekRecord(year, week);
var yearWeek = new YearWeekRecord { Year = year, Week = week };

// Assert
Assert.Equal(year, yearWeek.Year);
Expand Down

0 comments on commit 6a1a2f2

Please sign in to comment.