diff --git a/Oqtane.Client/Modules/Admin/Jobs/Edit.razor b/Oqtane.Client/Modules/Admin/Jobs/Edit.razor index 1d359f66..bcb500ff 100644 --- a/Oqtane.Client/Modules/Admin/Jobs/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Jobs/Edit.razor @@ -132,13 +132,13 @@ _isEnabled = job.IsEnabled.ToString(); _interval = job.Interval.ToString(); _frequency = job.Frequency; - _startDate = Utilities.UtcAsLocalDate(job.StartDate); - _startTime = Utilities.UtcAsLocalDateTime(job.StartDate); - _endDate = Utilities.UtcAsLocalDate(job.EndDate); - _endTime = Utilities.UtcAsLocalDateTime(job.EndDate); + _startDate = UtcToLocal(job.StartDate); + _startTime = UtcToLocal(job.StartDate); + _endDate = UtcToLocal(job.EndDate); + _endTime = UtcToLocal(job.EndDate); _retentionHistory = job.RetentionHistory.ToString(); - _nextDate = Utilities.UtcAsLocalDate(job.NextExecution); - _nextTime = Utilities.UtcAsLocalDateTime(job.NextExecution); + _nextDate = UtcToLocal(job.NextExecution); + _nextTime = UtcToLocal(job.NextExecution); createdby = job.CreatedBy; createdon = job.CreatedOn; modifiedby = job.ModifiedBy; @@ -176,10 +176,10 @@ { job.Interval = int.Parse(_interval); } - job.StartDate = Utilities.LocalDateAndTimeAsUtc(_startDate, _startTime); - job.EndDate = Utilities.LocalDateAndTimeAsUtc(_endDate, _endTime); + job.StartDate = LocalToUtc(_startDate.Value.Date.Add(_startTime.Value.TimeOfDay)); + job.EndDate = LocalToUtc(_endDate.Value.Date.Add(_endTime.Value.TimeOfDay)); job.RetentionHistory = int.Parse(_retentionHistory); - job.NextExecution = Utilities.LocalDateAndTimeAsUtc(_nextDate, _nextTime); + job.NextExecution = LocalToUtc(_nextDate.Value.Date.Add(_nextTime.Value.TimeOfDay)); try { diff --git a/Oqtane.Client/Modules/Admin/Jobs/Index.razor b/Oqtane.Client/Modules/Admin/Jobs/Index.razor index 4a2f5de6..033c3787 100644 --- a/Oqtane.Client/Modules/Admin/Jobs/Index.razor +++ b/Oqtane.Client/Modules/Admin/Jobs/Index.razor @@ -29,7 +29,7 @@ else @context.Name @DisplayStatus(context.IsEnabled, context.IsExecuting) @DisplayFrequency(context.Interval, context.Frequency) - @context.NextExecution?.ToLocalTime() + @UtcToLocal(context.NextExecution) @if (context.IsStarted) { diff --git a/Oqtane.Client/Modules/ModuleBase.cs b/Oqtane.Client/Modules/ModuleBase.cs index 5bbfc855..49d6b00b 100644 --- a/Oqtane.Client/Modules/ModuleBase.cs +++ b/Oqtane.Client/Modules/ModuleBase.cs @@ -487,6 +487,35 @@ namespace Oqtane.Modules return content; } + // date methods + public DateTime? UtcToLocal(DateTime? datetime) + { + TimeZoneInfo timezone = null; + if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); + } + else if (!string.IsNullOrEmpty(PageState.Site.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); + } + return Utilities.UtcAsLocalDateTime(datetime, timezone); + } + + public DateTime? LocalToUtc(DateTime? datetime) + { + TimeZoneInfo timezone = null; + if (PageState.User != null && !string.IsNullOrEmpty(PageState.User.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.User.TimeZoneId); + } + else if (!string.IsNullOrEmpty(PageState.Site.TimeZoneId)) + { + timezone = TimeZoneInfo.FindSystemTimeZoneById(PageState.Site.TimeZoneId); + } + return Utilities.LocalDateAndTimeAsUtc(datetime, timezone); + } + // logging methods public async Task Log(Alias alias, LogLevel level, string function, Exception exception, string message, params object[] args) {