-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from serilog-contrib/dev
update with latest
- Loading branch information
Showing
12 changed files
with
1,034 additions
and
657 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Serilog.Sinks.AzureTableStorage/Sinks/AzureTableStorage/Extensions/DateOnlyExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
|
||
namespace Serilog.Sinks.AzureTableStorage.Extensions; | ||
|
||
#if NET6_0_OR_GREATER | ||
/// <summary> | ||
/// Extension methods for <see cref="DateOnly"/> | ||
/// </summary> | ||
public static class DateOnlyExtensions | ||
{ | ||
/// <summary> | ||
/// Converts the <see cref="DateOnly"/> to a <see cref="DateTimeOffset"/> in the specified timezone. | ||
/// </summary> | ||
/// <param name="dateOnly">The date to convert.</param> | ||
/// <param name="zone">The time zone the date is in.</param> | ||
/// <returns>The converted <see cref="DateTimeOffset"/></returns> | ||
public static DateTimeOffset ToDateTimeOffset(this DateOnly dateOnly, TimeZoneInfo zone = null) | ||
{ | ||
zone ??= TimeZoneInfo.Local; | ||
|
||
var dateTime = dateOnly.ToDateTime(TimeOnly.MinValue); | ||
var offset = zone.GetUtcOffset(dateTime); | ||
|
||
return new DateTimeOffset(dateTime, offset); | ||
} | ||
|
||
/// <summary> | ||
/// Converts the <see cref="DateTimeOffset"/> to a <see cref="DateOnly"/> in the specified timezone. | ||
/// </summary> | ||
/// <param name="dateTime">The <see cref="DateTimeOffset"/> to convert.</param> | ||
/// <param name="zone">The time zone the date is in.</param> | ||
/// <returns>The converted <see cref="DateOnly"/></returns> | ||
public static DateOnly ToDateOnly(this DateTimeOffset dateTime, TimeZoneInfo zone = null) | ||
{ | ||
zone ??= TimeZoneInfo.Local; | ||
|
||
var targetZone = TimeZoneInfo.ConvertTime(dateTime, zone); | ||
return DateOnly.FromDateTime(targetZone.Date); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.