Skip to content

Commit a5b1bf5

Browse files
committed
Simplify CalDateTime AsSystemLocal and AsUtc by using AsDateTimeOffset
1 parent c1d4a13 commit a5b1bf5

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

Ical.Net/DataTypes/CalDateTime.cs

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -303,52 +303,12 @@ public override int GetHashCode()
303303
/// If the DateTimeKind is Unspecified, it's assumed that the underlying
304304
/// Value already represents the system's datetime.
305305
/// </summary>
306-
public DateTime AsSystemLocal
307-
{
308-
get
309-
{
310-
if (Value.Kind == DateTimeKind.Unspecified)
311-
{
312-
return HasTime
313-
? Value
314-
: Value.Date;
315-
}
316-
317-
return HasTime
318-
? Value.ToLocalTime()
319-
: Value.ToLocalTime().Date;
320-
}
321-
}
306+
public DateTime AsSystemLocal => AsDateTimeOffset.LocalDateTime;
322307

323308
/// <summary>
324309
/// Returns a representation of the <see cref="DateTime"/> in UTC.
325310
/// </summary>
326-
public DateTime AsUtc
327-
{
328-
get
329-
{
330-
// In order of weighting:
331-
// 1) Specified TzId
332-
// 2) Value having a DateTimeKind.Utc
333-
// 3) Use the OS's time zone
334-
DateTime asUtc;
335-
336-
if (!string.IsNullOrWhiteSpace(TzId))
337-
{
338-
var asLocal = DateUtil.ToZonedDateTimeLeniently(Value, TzId);
339-
return asLocal.ToDateTimeUtc();
340-
}
341-
342-
if (IsUtc || Value.Kind == DateTimeKind.Utc)
343-
{
344-
asUtc = DateTime.SpecifyKind(Value, DateTimeKind.Utc);
345-
return asUtc;
346-
}
347-
348-
asUtc = DateTime.SpecifyKind(Value, DateTimeKind.Local).ToUniversalTime();
349-
return asUtc;
350-
}
351-
}
311+
public DateTime AsUtc => AsDateTimeOffset.UtcDateTime;
352312

353313
/// <summary>
354314
/// Gets the underlying <see cref="DateOnlyValue"/> of <see cref="Value"/>.
@@ -533,7 +493,7 @@ public IDateTime ToTimeZone(string? tzId)
533493
/// </summary>
534494
public DateTimeOffset AsDateTimeOffset =>
535495
string.IsNullOrWhiteSpace(TzId)
536-
? new DateTimeOffset(AsSystemLocal)
496+
? new DateTimeOffset(Value)
537497
: DateUtil.ToZonedDateTimeLeniently(Value, TzId).ToDateTimeOffset();
538498

539499
/// <inheritdoc cref="DateTime.Add"/>

Ical.Net/Evaluation/RecurrencePatternEvaluator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private List<DateTime> GetYearDayVariants(List<DateTime> dates, RecurrencePatter
472472
}
473473
}
474474

475-
if (keepDate)
475+
if (!keepDate)
476476
{
477477
dates.RemoveAt(i);
478478
}

0 commit comments

Comments
 (0)