Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using MudExtensions.Utilities;
using Microsoft.AspNetCore.Components;
using MudBlazor;
Expand DownExpand Up@@ -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)
{
Expand DownExpand Up@@ -76,13 +76,13 @@ public TimeSpan Value

TimeSpan _interval = TimeSpan.FromSeconds(1);
/// <summary>
///
///
/// </summary>
[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public TimeSpan Interval
{
get => _interval;
public TimeSpan Interval
{
get => _interval;
set
{
if (_interval == value)
Expand All@@ -94,6 +94,13 @@ public TimeSpan Interval
}
}

/// <summary>
/// The timezone of the watch. If null, DateTime.Now will be used.
/// </summary>
[Parameter]
[Category(CategoryTypes.FormComponent.Behavior)]
public TimeZoneInfo? TimeZone { get; set; }

WatchMode _watchMode = WatchMode.Watch;
/// <summary>
///
Expand DownExpand Up@@ -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)
{
Expand DownExpand Up@@ -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;
Expand DownExpand Up@@ -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;
}

/// <summary>
///
/// </summary>
Expand Down
Loading