diff --git a/src/CodeBeam.MudBlazor.Extensions/Components/Watch/MudWatch.razor.cs b/src/CodeBeam.MudBlazor.Extensions/Components/Watch/MudWatch.razor.cs
index b3780746..84e4ba9c 100644
--- a/src/CodeBeam.MudBlazor.Extensions/Components/Watch/MudWatch.razor.cs
+++ b/src/CodeBeam.MudBlazor.Extensions/Components/Watch/MudWatch.razor.cs
@@ -1,4 +1,4 @@
-using System.Diagnostics;
+using System.Diagnostics;
using MudExtensions.Utilities;
using Microsoft.AspNetCore.Components;
using MudBlazor;
@@ -34,7 +34,7 @@ protected override void OnInitialized()
_timer.Elapsed += Elapse;
if (Mode == WatchMode.Watch)
{
- Value = DateTime.Now.TimeOfDay;
+ Value = GetCurrentTime();
}
else if (Mode == WatchMode.CountDown)
{
@@ -76,13 +76,13 @@ public TimeSpan Value
TimeSpan _interval = TimeSpan.FromSeconds(1);
///
- ///
+ ///
///
[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
- public TimeSpan Interval
- {
- get => _interval;
+ public TimeSpan Interval
+ {
+ get => _interval;
set
{
if (_interval == value)
@@ -94,6 +94,13 @@ public TimeSpan Interval
}
}
+ ///
+ /// The timezone of the watch. If null, DateTime.Now will be used.
+ ///
+ [Parameter]
+ [Category(CategoryTypes.FormComponent.Behavior)]
+ public TimeZoneInfo? TimeZone { get; set; }
+
WatchMode _watchMode = WatchMode.Watch;
///
///
@@ -254,7 +261,7 @@ public async void Elapse(object sender, System.Timers.ElapsedEventArgs args)
int oldSecond = ((int)Value.TotalSeconds);
if (Mode == WatchMode.Watch)
{
- Value = DateTime.Now.TimeOfDay;
+ Value = GetCurrentTime();
}
else if (Mode == WatchMode.CountDown)
{
@@ -389,7 +396,7 @@ protected async Task SetWatchMode(WatchMode mode)
if (mode == WatchMode.Watch)
{
Interval = TimeSpan.FromSeconds(1);
- Value = DateTime.Now.TimeOfDay;
+ Value = GetCurrentTime();
ShowHour = true;
ShowMinute = true;
ShowSecond = true;
@@ -429,6 +436,15 @@ protected void SetInternalValues()
_milliSecond = Value.Milliseconds;
}
+ protected TimeSpan GetCurrentTime()
+ {
+ if (TimeZone != null)
+ {
+ return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZone).TimeOfDay;
+ }
+ return DateTime.Now.TimeOfDay;
+ }
+
///
///
///