simplified method names
This commit is contained in:
parent
73c4bcee30
commit
b4ab45d2e7
|
@ -132,13 +132,13 @@
|
||||||
_isEnabled = job.IsEnabled.ToString();
|
_isEnabled = job.IsEnabled.ToString();
|
||||||
_interval = job.Interval.ToString();
|
_interval = job.Interval.ToString();
|
||||||
_frequency = job.Frequency;
|
_frequency = job.Frequency;
|
||||||
_startDate = Utilities.UtcAsLocalDateAndTimeToDate(job.StartDate);
|
_startDate = Utilities.UtcAsLocalDate(job.StartDate);
|
||||||
_startTime = Utilities.UtcAsLocalDateAndTimeToTime(job.StartDate);
|
_startTime = Utilities.UtcAsLocalDateTime(job.StartDate);
|
||||||
_endDate = Utilities.UtcAsLocalDateAndTimeToDate(job.EndDate);
|
_endDate = Utilities.UtcAsLocalDate(job.EndDate);
|
||||||
_endTime = Utilities.UtcAsLocalDateAndTimeToTime(job.EndDate);
|
_endTime = Utilities.UtcAsLocalDateTime(job.EndDate);
|
||||||
_retentionHistory = job.RetentionHistory.ToString();
|
_retentionHistory = job.RetentionHistory.ToString();
|
||||||
_nextDate = Utilities.UtcAsLocalDateAndTimeToDate(job.NextExecution);
|
_nextDate = Utilities.UtcAsLocalDate(job.NextExecution);
|
||||||
_nextTime = Utilities.UtcAsLocalDateAndTimeToTime(job.NextExecution);
|
_nextTime = Utilities.UtcAsLocalDateTime(job.NextExecution);
|
||||||
createdby = job.CreatedBy;
|
createdby = job.CreatedBy;
|
||||||
createdon = job.CreatedOn;
|
createdon = job.CreatedOn;
|
||||||
modifiedby = job.ModifiedBy;
|
modifiedby = job.ModifiedBy;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
@ -490,24 +491,53 @@ namespace Oqtane.Shared
|
||||||
return $"[{@class.GetType()}] {message}";
|
return $"[{@class.GetType()}] {message}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, string time, TimeZoneInfo localTimeZone = null)
|
||||||
|
{
|
||||||
|
if (date != null && !string.IsNullOrEmpty(time) && TimeSpan.TryParse(time, out TimeSpan timespan))
|
||||||
|
{
|
||||||
|
return LocalDateAndTimeAsUtc(date.Value.Date.Add(timespan), localTimeZone);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, DateTime? time, TimeZoneInfo localTimeZone = null)
|
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, DateTime? time, TimeZoneInfo localTimeZone = null)
|
||||||
{
|
{
|
||||||
localTimeZone ??= TimeZoneInfo.Local;
|
|
||||||
|
|
||||||
if (date != null)
|
if (date != null)
|
||||||
{
|
{
|
||||||
if (time != null)
|
if (time != null)
|
||||||
{
|
{
|
||||||
DateTime localDateTime = date.Value.Date.Add(time.Value.TimeOfDay);
|
return LocalDateAndTimeAsUtc(date.Value.Date.Add(time.Value.TimeOfDay), localTimeZone);
|
||||||
return TimeZoneInfo.ConvertTimeToUtc(localDateTime, localTimeZone);
|
|
||||||
}
|
}
|
||||||
|
return LocalDateAndTimeAsUtc(date.Value.Date, localTimeZone);
|
||||||
return TimeZoneInfo.ConvertTimeToUtc(date.Value.Date, localTimeZone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DateTime? LocalDateAndTimeAsUtc(DateTime? date, TimeZoneInfo localTimeZone = null)
|
||||||
|
{
|
||||||
|
if (date != null)
|
||||||
|
{
|
||||||
|
localTimeZone ??= TimeZoneInfo.Local;
|
||||||
|
return TimeZoneInfo.ConvertTime(date.Value, localTimeZone, TimeZoneInfo.Utc);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateTime? UtcAsLocalDate(DateTime? dateTime, TimeZoneInfo timeZone = null)
|
||||||
|
{
|
||||||
|
return UtcAsLocalDateAndTime(dateTime, timeZone).date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateTime? UtcAsLocalDateTime(DateTime? dateTime, TimeZoneInfo timeZone = null)
|
||||||
|
{
|
||||||
|
var result = UtcAsLocalDateAndTime(dateTime, timeZone);
|
||||||
|
if (result.date != null && !string.IsNullOrEmpty(result.time) && TimeSpan.TryParse(result.time, out TimeSpan timespan))
|
||||||
|
{
|
||||||
|
result.date = result.date.Value.Add(timespan);
|
||||||
|
}
|
||||||
|
return result.date;
|
||||||
|
}
|
||||||
|
|
||||||
public static (DateTime? date, string time) UtcAsLocalDateAndTime(DateTime? dateTime, TimeZoneInfo timeZone = null)
|
public static (DateTime? date, string time) UtcAsLocalDateAndTime(DateTime? dateTime, TimeZoneInfo timeZone = null)
|
||||||
{
|
{
|
||||||
timeZone ??= TimeZoneInfo.Local;
|
timeZone ??= TimeZoneInfo.Local;
|
||||||
|
@ -538,49 +568,6 @@ namespace Oqtane.Shared
|
||||||
return (localDateTime?.Date, localTime);
|
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)]
|
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
|
||||||
public static string ContentUrl(Alias alias, int fileId)
|
public static string ContentUrl(Alias alias, int fileId)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user