File tree Expand file tree Collapse file tree 3 files changed +45
-5
lines changed
samples/SampleWebApplication/Pages
src/Serilog.Sinks.AzureTableStorage/Sinks/AzureTableStorage/Extensions Expand file tree Collapse file tree 3 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 182182 asp-page =" /Logs"
183183 asp-route-z =" @Model.PageSize"
184184 asp-route-l =" @Model.Level"
185- asp-route-d =" @Model.Date.Date "
185+ asp-route-d =" @Model.Date"
186186 asp-route-t =" " >First </a >
187187 </li >
188188 }
199199 asp-page =" /Logs"
200200 asp-route-z =" @Model.PageSize"
201201 asp-route-l =" @Model.Level"
202- asp-route-d =" @Model.Date.Date "
202+ asp-route-d =" @Model.Date"
203203 asp-route-t =" @Model.NextToken" >Next </a >
204204 </li >
205205 }
Original file line number Diff line number Diff line change 66using SampleWebApplication . Models ;
77
88using Serilog . Sinks . AzureTableStorage ;
9- using Serilog . Sinks . AzureTableStorage . Extensions ;
109
1110namespace SampleWebApplication . Pages ;
1211
@@ -26,7 +25,7 @@ public LogsModel(TableServiceClient tableServiceClient)
2625 public string ? Level { get ; set ; } = string . Empty ;
2726
2827 [ BindProperty ( Name = "d" , SupportsGet = true ) ]
29- public DateTime Date { get ; set ; } = DateTime . Today ;
28+ public DateOnly Date { get ; set ; } = DateOnly . FromDateTime ( DateTime . Today ) ;
3029
3130 [ BindProperty ( Name = "t" , SupportsGet = true ) ]
3231 public string ContinuationToken { get ; set ; } = string . Empty ;
@@ -39,7 +38,7 @@ public async Task<IActionResult> OnGetAsync(CancellationToken cancellationToken)
3938 {
4039 var logTable = _tableServiceClient . GetTableClient ( "SampleLog" ) ;
4140
42- var filter = DefaultKeyGenerator . GeneratePartitionKeyQuery ( Date . Date ) ;
41+ var filter = DefaultKeyGenerator . GeneratePartitionKeyQuery ( Date ) ;
4342
4443 if ( ! string . IsNullOrWhiteSpace ( Level ) )
4544 filter += $ " and ({ nameof ( LogEventModel . Level ) } eq '{ Level } ')";
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace Serilog . Sinks . AzureTableStorage . Extensions ;
4+
5+ #if NET6_0_OR_GREATER
6+ /// <summary>
7+ /// Extension methods for <see cref="DateOnly"/>
8+ /// </summary>
9+ public static class DateOnlyExtensions
10+ {
11+ /// <summary>
12+ /// Converts the <see cref="DateOnly"/> to a <see cref="DateTimeOffset"/> in the specified timezone.
13+ /// </summary>
14+ /// <param name="dateOnly">The date to convert.</param>
15+ /// <param name="zone">The time zone the date is in.</param>
16+ /// <returns>The converted <see cref="DateTimeOffset"/></returns>
17+ public static DateTimeOffset ToDateTimeOffset ( this DateOnly dateOnly , TimeZoneInfo zone = null )
18+ {
19+ zone ??= TimeZoneInfo . Local ;
20+
21+ var dateTime = dateOnly . ToDateTime ( TimeOnly . MinValue ) ;
22+ var offset = zone . GetUtcOffset ( dateTime ) ;
23+
24+ return new DateTimeOffset ( dateTime , offset ) ;
25+ }
26+
27+ /// <summary>
28+ /// Converts the <see cref="DateTimeOffset"/> to a <see cref="DateOnly"/> in the specified timezone.
29+ /// </summary>
30+ /// <param name="dateTime">The <see cref="DateTimeOffset"/> to convert.</param>
31+ /// <param name="zone">The time zone the date is in.</param>
32+ /// <returns>The converted <see cref="DateOnly"/></returns>
33+ public static DateOnly ToDateOnly ( this DateTimeOffset dateTime , TimeZoneInfo zone = null )
34+ {
35+ zone ??= TimeZoneInfo . Local ;
36+
37+ var targetZone = TimeZoneInfo . ConvertTime ( dateTime , zone ) ;
38+ return DateOnly . FromDateTime ( targetZone . Date ) ;
39+ }
40+ }
41+ #endif
You can’t perform that action at this time.
0 commit comments