Merge pull request #3185 from leigh-pointer/SchedularTimeControls
Fix for Schedular Allows incorrect Time format #3184
This commit is contained in:
commit
73c4bcee30
|
@ -56,7 +56,7 @@
|
|||
<input id="starting" type="date" class="form-control" @bind="@_startDate" />
|
||||
</div>
|
||||
<div class="col">
|
||||
<input id="starting" type="text" class="form-control" placeholder="hh:mm" @bind="@_startTime" />
|
||||
<input id="starting" type="time" class="form-control" placeholder="hh:mm" @bind="@_startTime" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -69,7 +69,7 @@
|
|||
<input id="ending" type="date" class="form-control" @bind="@_endDate" />
|
||||
</div>
|
||||
<div class="col">
|
||||
<input id="ending" type="text" class="form-control" placeholder="hh:mm" @bind="@_endTime" />
|
||||
<input id="ending" type="time" class="form-control" placeholder="hh:mm" @bind="@_endTime" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -82,7 +82,7 @@
|
|||
<input id="next" type="date" class="form-control" @bind="@_nextDate" />
|
||||
</div>
|
||||
<div class="col">
|
||||
<input id="next" type="text" class="form-control" placeholder="hh:mm" @bind="@_nextTime" />
|
||||
<input id="next" type="time" class="form-control" placeholder="hh:mm" @bind="@_nextTime" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -97,22 +97,22 @@
|
|||
</form>
|
||||
|
||||
@code {
|
||||
private ElementReference form;
|
||||
private bool validated = false;
|
||||
private int _jobId;
|
||||
private string _name = string.Empty;
|
||||
private string _jobType = string.Empty;
|
||||
private string _isEnabled = "True";
|
||||
private string _interval = string.Empty;
|
||||
private string _frequency = string.Empty;
|
||||
private DateTime? _startDate = null;
|
||||
private string _startTime = string.Empty;
|
||||
private DateTime? _endDate = null;
|
||||
private string _endTime = string.Empty;
|
||||
private string _retentionHistory = string.Empty;
|
||||
private DateTime? _nextDate = null;
|
||||
private string _nextTime = string.Empty;
|
||||
private string createdby;
|
||||
private ElementReference form;
|
||||
private bool validated = false;
|
||||
private int _jobId;
|
||||
private string _name = string.Empty;
|
||||
private string _jobType = string.Empty;
|
||||
private string _isEnabled = "True";
|
||||
private string _interval = string.Empty;
|
||||
private string _frequency = string.Empty;
|
||||
private DateTime? _startDate = null;
|
||||
private DateTime? _startTime = null;
|
||||
private DateTime? _endDate = null;
|
||||
private DateTime? _endTime = null;
|
||||
private string _retentionHistory = string.Empty;
|
||||
private DateTime? _nextDate = null;
|
||||
private DateTime? _nextTime = null;
|
||||
private string createdby;
|
||||
private DateTime createdon;
|
||||
private string modifiedby;
|
||||
private DateTime modifiedon;
|
||||
|
@ -132,11 +132,14 @@
|
|||
_isEnabled = job.IsEnabled.ToString();
|
||||
_interval = job.Interval.ToString();
|
||||
_frequency = job.Frequency;
|
||||
(_startDate, _startTime) = Utilities.UtcAsLocalDateAndTime(job.StartDate);
|
||||
(_endDate, _endTime) = Utilities.UtcAsLocalDateAndTime(job.EndDate);
|
||||
_retentionHistory = job.RetentionHistory.ToString();
|
||||
(_nextDate, _nextTime) = Utilities.UtcAsLocalDateAndTime(job.NextExecution);
|
||||
createdby = job.CreatedBy;
|
||||
_startDate = Utilities.UtcAsLocalDateAndTimeToDate(job.StartDate);
|
||||
_startTime = Utilities.UtcAsLocalDateAndTimeToTime(job.StartDate);
|
||||
_endDate = Utilities.UtcAsLocalDateAndTimeToDate(job.EndDate);
|
||||
_endTime = Utilities.UtcAsLocalDateAndTimeToTime(job.EndDate);
|
||||
_retentionHistory = job.RetentionHistory.ToString();
|
||||
_nextDate = Utilities.UtcAsLocalDateAndTimeToDate(job.NextExecution);
|
||||
_nextTime = Utilities.UtcAsLocalDateAndTimeToTime(job.NextExecution);
|
||||
createdby = job.CreatedBy;
|
||||
createdon = job.CreatedOn;
|
||||
modifiedby = job.ModifiedBy;
|
||||
modifiedon = job.ModifiedOn;
|
||||
|
|
|
@ -490,17 +490,21 @@ namespace Oqtane.Shared
|
|||
return $"[{@class.GetType()}] {message}";
|
||||
}
|
||||
|
||||
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, string time, TimeZoneInfo localTimeZone = null)
|
||||
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, DateTime? time, TimeZoneInfo localTimeZone = null)
|
||||
{
|
||||
localTimeZone ??= TimeZoneInfo.Local;
|
||||
|
||||
if (date != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(time))
|
||||
if (time != null)
|
||||
{
|
||||
return TimeZoneInfo.ConvertTime(DateTime.Parse(date.Value.Date.ToShortDateString() + " " + time), localTimeZone, TimeZoneInfo.Utc);
|
||||
DateTime localDateTime = date.Value.Date.Add(time.Value.TimeOfDay);
|
||||
return TimeZoneInfo.ConvertTimeToUtc(localDateTime, localTimeZone);
|
||||
}
|
||||
return TimeZoneInfo.ConvertTime(date.Value.Date, localTimeZone, TimeZoneInfo.Utc);
|
||||
|
||||
return TimeZoneInfo.ConvertTimeToUtc(date.Value.Date, localTimeZone);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -534,6 +538,49 @@ namespace Oqtane.Shared
|
|||
return (localDateTime?.Date, localTime);
|
||||
}
|
||||
|
||||
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, string time, TimeZoneInfo localTimeZone = null)
|
||||
{
|
||||
localTimeZone ??= TimeZoneInfo.Local;
|
||||
if (date != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(time))
|
||||
{
|
||||
return TimeZoneInfo.ConvertTime(DateTime.Parse(date.Value.Date.ToShortDateString() + " " + time), localTimeZone, TimeZoneInfo.Utc);
|
||||
}
|
||||
return TimeZoneInfo.ConvertTime(date.Value.Date, localTimeZone, TimeZoneInfo.Utc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static DateTime? UtcAsLocalDateAndTimeToDate(DateTime? dateTime, TimeZoneInfo timeZone = null)
|
||||
{
|
||||
var result = UtcAsLocalDateAndTime(dateTime, timeZone);
|
||||
return result.date;
|
||||
}
|
||||
|
||||
public static DateTime? UtcAsLocalDateAndTimeToTime(DateTime? dateTime, TimeZoneInfo timeZone = null)
|
||||
{
|
||||
var result = UtcAsLocalDateAndTime(dateTime, timeZone);
|
||||
|
||||
if (string.IsNullOrEmpty(result.time))
|
||||
{
|
||||
return result.date;
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeParts = result.time.Split(':');
|
||||
if (timeParts.Length == 2 && int.TryParse(timeParts[0], out int hours) && int.TryParse(timeParts[1], out int minutes))
|
||||
{
|
||||
TimeSpan timeOfDay = new TimeSpan(hours, minutes, 0);
|
||||
return result.date?.Date + timeOfDay;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle parsing error
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
|
||||
public static string ContentUrl(Alias alias, int fileId)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user