Skip to content

Commit

Permalink
Remove the redundant Calendar argument to CTORs
Browse files Browse the repository at this point in the history
  • Loading branch information
axunonb committed Nov 18, 2024
1 parent 82f5dba commit 80c2578
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Ical.Net.Tests/CalDateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public void Simple_PropertyAndMethod_HasTime_Tests()
var dt = new DateTime(2025, 1, 2, 10, 20, 30, DateTimeKind.Utc);
var c = new CalDateTime(dt, tzId: "Europe/Berlin");

var c2 = new CalDateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, c.TzId, null);
var c2 = new CalDateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, c.TzId);
var c3 = new CalDateTime(new DateOnly(dt.Year, dt.Month, dt.Day),
new TimeOnly(dt.Hour, dt.Minute, dt.Second), dt.Kind, c.TzId);
new TimeOnly(dt.Hour, dt.Minute, dt.Second), c.TzId);

Assert.Multiple(() =>
{
Expand Down
30 changes: 13 additions & 17 deletions Ical.Net/DataTypes/CalDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public CalDateTime() { }
public CalDateTime(IDateTime value)
{
if (value.HasTime)
Initialize(DateOnly.FromDateTime(value.Value), TimeOnly.FromDateTime(value.Value), value.TzId, value.Calendar);
Initialize(DateOnly.FromDateTime(value.Value), TimeOnly.FromDateTime(value.Value), value.TzId);
else
Initialize(DateOnly.FromDateTime(value.Value), null, value.TzId, value.Calendar);
Initialize(DateOnly.FromDateTime(value.Value), null, value.TzId);
}

/// <summary>
Expand Down Expand Up @@ -92,9 +92,9 @@ public CalDateTime(DateTime value, string? tzId, bool hasTime = true)
tzId = UtcTzId;

if (hasTime)
Initialize(DateOnly.FromDateTime(value), TimeOnly.FromDateTime(value), tzId, null);
Initialize(DateOnly.FromDateTime(value), TimeOnly.FromDateTime(value), tzId);
else
Initialize(DateOnly.FromDateTime(value), null, tzId, null);
Initialize(DateOnly.FromDateTime(value), null, tzId);
}

/// <summary>
Expand All @@ -112,10 +112,9 @@ public CalDateTime(DateTime value, string? tzId, bool hasTime = true)
/// <param name="hour"></param>
/// <param name="minute"></param>
/// <param name="second"></param>
/// <param name="cal"></param>
public CalDateTime(int year, int month, int day, int hour, int minute, int second, string? tzId = null, Calendar? cal = null) //NOSONAR - must keep this signature
public CalDateTime(int year, int month, int day, int hour, int minute, int second, string? tzId = null) //NOSONAR - must keep this signature
{
Initialize(new DateOnly(year, month, day), new TimeOnly(hour, minute, second), tzId, cal);
Initialize(new DateOnly(year, month, day), new TimeOnly(hour, minute, second), tzId);
}

/// <summary>
Expand All @@ -133,7 +132,7 @@ public CalDateTime(int year, int month, int day, int hour, int minute, int secon
/// <param name="day"></param>
public CalDateTime(int year, int month, int day, string? tzId = null)
{
Initialize(new DateOnly(year, month, day), null, tzId, null);
Initialize(new DateOnly(year, month, day), null, tzId);
}

/// <summary>
Expand All @@ -148,10 +147,9 @@ public CalDateTime(int year, int month, int day, string? tzId = null)
/// </param>
/// <param name="date"></param>
/// <param name="time"></param>
/// <param name="cal"></param>
public CalDateTime(DateOnly date, TimeOnly? time, DateTimeKind kind, string? tzId = null, Calendar? cal = null)
public CalDateTime(DateOnly date, TimeOnly? time, string? tzId = null)
{
Initialize(date, time, tzId, cal);
Initialize(date, time, tzId);
}

/// <summary>
Expand All @@ -173,16 +171,14 @@ public CalDateTime(string value, string? tzId = null)
TzId = tzId;
}

private void Initialize(DateOnly dateOnly, TimeOnly? timeOnly, string? tzId, Calendar? cal)
private void Initialize(DateOnly dateOnly, TimeOnly? timeOnly, string? tzId)
{
HasTime = timeOnly.HasValue;
HasDate = true;
_dateOnly = dateOnly;
_timeOnly = timeOnly ?? new TimeOnly();

_tzId = string.Equals(UtcTzId, tzId, StringComparison.OrdinalIgnoreCase) ? UtcTzId : tzId;

AssociatedObject = cal;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -363,9 +359,9 @@ public DateTime Value
{
// Initialize, keeping the HasTime setting
if (HasTime)
Initialize(DateOnly.FromDateTime(value), TimeOnly.FromDateTime(value), _tzId, Calendar);
Initialize(DateOnly.FromDateTime(value), TimeOnly.FromDateTime(value), _tzId);
else
Initialize(DateOnly.FromDateTime(value), null, _tzId, Calendar);
Initialize(DateOnly.FromDateTime(value), null, _tzId);
}
}

Expand Down Expand Up @@ -405,7 +401,7 @@ public string? TzId
return;
}

Initialize(_dateOnly, HasTime ? _timeOnly : null, value, Calendar);
Initialize(_dateOnly, HasTime ? _timeOnly : null, value);
}
}

Expand Down

0 comments on commit 80c2578

Please sign in to comment.