Skip to content

Commit

Permalink
feat: Add method extensions for TimeOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane ANDRE (E104915) committed Aug 31, 2024
1 parent 027834c commit e86eaa9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/MyNet.Utilities/Extensions/TimeOnlyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENSE file in the project root for more information.

using System;
using MyNet.Utilities.Localization;

namespace MyNet.Utilities
{
Expand All @@ -10,6 +11,10 @@ namespace MyNet.Utilities
/// </summary>
public static class TimeOnlyExtensions
{
public static TimeOnly ToTimeZone(this TimeOnly time, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone) => TimeZoneInfo.ConvertTime(DateTime.UtcNow.ToTimeZone(sourceTimeZone).At(time), sourceTimeZone, destinationTimeZone).ToTime();

public static TimeOnly ToCurrentTime(this TimeOnly time, TimeZoneInfo sourceTimeZone) => time.ToTimeZone(sourceTimeZone, GlobalizationService.Current.TimeZone);

/// <summary>
/// Returns the Start of the given day (the first millisecond of the given <see cref="DateTime"/>).
/// </summary>
Expand Down

0 comments on commit e86eaa9

Please sign in to comment.