Skip to content

Commit

Permalink
feat: add extensions to convert Timespan to Local or Universal time
Browse files Browse the repository at this point in the history
  • Loading branch information
sandre58 committed Jul 5, 2024
1 parent a888e25 commit 7c26c2a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/MyNet.Utilities/Extensions/TimeSpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public static class TimeSpanExtensions
public const double DaysInAYear = 365.2425; // see https://en.wikipedia.org/wiki/Gregorian_calendar
public const double DaysInAMonth = DaysInAYear / 12;

public static TimeSpan ToUniversalTime(this TimeSpan timespan) => DateTime.Now.Date.Add(timespan).ToUniversalTime().TimeOfDay;

public static TimeSpan ToLocalTime(this TimeSpan timespan) => DateTime.UtcNow.Date.Add(timespan).ToLocalTime().TimeOfDay;

/// <summary>
/// Adds the given <see cref="FluentTimeSpan"/> from a <see cref="TimeSpan"/> and returns resulting <see cref="FluentTimeSpan"/>.
/// </summary>
Expand Down

0 comments on commit 7c26c2a

Please sign in to comment.