1- using System . Diagnostics ;
1+ using System . Diagnostics ;
22using MudExtensions . Utilities ;
33using Microsoft . AspNetCore . Components ;
44using MudBlazor ;
@@ -34,7 +34,7 @@ protected override void OnInitialized()
3434 _timer . Elapsed += Elapse ;
3535 if ( Mode == WatchMode . Watch )
3636 {
37- Value = DateTime . Now . TimeOfDay ;
37+ Value = GetCurrentTime ( ) ;
3838 }
3939 else if ( Mode == WatchMode . CountDown )
4040 {
@@ -76,13 +76,13 @@ public TimeSpan Value
7676
7777 TimeSpan _interval = TimeSpan . FromSeconds ( 1 ) ;
7878 /// <summary>
79- ///
79+ ///
8080 /// </summary>
8181 [ Parameter ]
8282 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
83- public TimeSpan Interval
84- {
85- get => _interval ;
83+ public TimeSpan Interval
84+ {
85+ get => _interval ;
8686 set
8787 {
8888 if ( _interval == value )
@@ -94,6 +94,13 @@ public TimeSpan Interval
9494 }
9595 }
9696
97+ /// <summary>
98+ /// The timezone of the watch. If null, DateTime.Now will be used.
99+ /// </summary>
100+ [ Parameter ]
101+ [ Category ( CategoryTypes . FormComponent . Behavior ) ]
102+ public TimeZoneInfo ? TimeZone { get ; set ; }
103+
97104 WatchMode _watchMode = WatchMode . Watch ;
98105 /// <summary>
99106 ///
@@ -254,7 +261,7 @@ public async void Elapse(object sender, System.Timers.ElapsedEventArgs args)
254261 int oldSecond = ( ( int ) Value . TotalSeconds ) ;
255262 if ( Mode == WatchMode . Watch )
256263 {
257- Value = DateTime . Now . TimeOfDay ;
264+ Value = GetCurrentTime ( ) ;
258265 }
259266 else if ( Mode == WatchMode . CountDown )
260267 {
@@ -389,7 +396,7 @@ protected async Task SetWatchMode(WatchMode mode)
389396 if ( mode == WatchMode . Watch )
390397 {
391398 Interval = TimeSpan . FromSeconds ( 1 ) ;
392- Value = DateTime . Now . TimeOfDay ;
399+ Value = GetCurrentTime ( ) ;
393400 ShowHour = true ;
394401 ShowMinute = true ;
395402 ShowSecond = true ;
@@ -429,6 +436,15 @@ protected void SetInternalValues()
429436 _milliSecond = Value . Milliseconds ;
430437 }
431438
439+ protected TimeSpan GetCurrentTime ( )
440+ {
441+ if ( TimeZone != null )
442+ {
443+ return TimeZoneInfo . ConvertTimeFromUtc ( DateTime . UtcNow , TimeZone ) . TimeOfDay ;
444+ }
445+ return DateTime . Now . TimeOfDay ;
446+ }
447+
432448 /// <summary>
433449 ///
434450 /// </summary>
0 commit comments