|
1 | | -namespace BlazorLocalTime; |
| 1 | +using System.Diagnostics.CodeAnalysis; |
| 2 | + |
| 3 | +namespace BlazorLocalTime; |
2 | 4 |
|
3 | 5 | /// <summary> |
4 | 6 | /// Provides an interface for a local time service. |
@@ -33,6 +35,7 @@ public interface ILocalTimeService |
33 | 35 | /// <summary> |
34 | 36 | /// Is the local time zone set? |
35 | 37 | /// </summary> |
| 38 | + [MemberNotNullWhen(true, nameof(TimeZoneInfo))] |
36 | 39 | public bool IsTimeZoneInfoAvailable => TimeZoneInfo != null; |
37 | 40 |
|
38 | 41 | /// <summary> |
@@ -94,14 +97,14 @@ public DateTimeOffset ToLocalTimeOffset(DateTimeOffset dateTimeOffset) |
94 | 97 | /// <returns>The <see cref="TimeZoneInfo"/> representing the browser's time zone.</returns> |
95 | 98 | public TimeZoneInfo GetBrowserTimeZone() |
96 | 99 | { |
97 | | - if (TimeZoneInfo == null || !IsTimeZoneInfoAvailable) |
| 100 | + if (!IsTimeZoneInfoAvailable) |
98 | 101 | { |
99 | 102 | throw new InvalidOperationException( |
100 | 103 | """ |
101 | 104 | Failed to obtain the browser's time zone information. |
102 | 105 | Possible causes: |
103 | | - 1) The `<BrowserLocalTimeProvider />` component has not been added. |
104 | | - In this case, please add `<BrowserLocalTimeProvider />` to a root component such as `Routes.razor`. |
| 106 | + 1) The `<BlazorLocalTimeProvider />` component has not been added. |
| 107 | + In this case, please add `<BlazorLocalTimeProvider />` to a root component such as `Routes.razor`. |
105 | 108 | 2) You are trying to use `ILocalTimeService` in `OnInitialized(Async)`. |
106 | 109 | In this case, you need to subscribe to the `ILocalTimeService.OnLocalTimeZoneChanged` event |
107 | 110 | and perform processing after the time zone information has been set. |
|
0 commit comments