本文整理汇总了C#中IDateTimeHelper.ConvertToUserTime方法的典型用法代码示例。如果您正苦于以下问题:C# IDateTimeHelper.ConvertToUserTime方法的具体用法?C# IDateTimeHelper.ConvertToUserTime怎么用?C# IDateTimeHelper.ConvertToUserTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDateTimeHelper
的用法示例。
在下文中一共展示了IDateTimeHelper.ConvertToUserTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToScheduleTaskModel
public static ScheduleTaskModel ToScheduleTaskModel(this ScheduleTask task, ILocalizationService localization, IDateTimeHelper dateTimeHelper, UrlHelper urlHelper)
{
var now = DateTime.UtcNow;
TimeSpan? dueIn = null;
if (task.NextRunUtc.HasValue)
{
dueIn = task.NextRunUtc.Value - now;
}
var nextRunPretty = "";
bool isOverdue = false;
if (dueIn.HasValue)
{
if (dueIn.Value.TotalSeconds > 0)
{
nextRunPretty = dueIn.Value.Prettify();
}
else
{
nextRunPretty = localization.GetResource("Common.Waiting") + "...";
isOverdue = true;
}
}
var isRunning = task.IsRunning;
var lastStartOn = task.LastStartUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastStartUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var lastEndOn = task.LastEndUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastEndUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var lastSuccessOn = task.LastSuccessUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastSuccessUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var nextRunOn = task.NextRunUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.NextRunUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var model = new ScheduleTaskModel
{
Id = task.Id,
Name = task.Name,
CronExpression = task.CronExpression,
CronDescription = CronExpression.GetFriendlyDescription(task.CronExpression),
Enabled = task.Enabled,
StopOnError = task.StopOnError,
LastStart = lastStartOn,
LastStartPretty = task.LastStartUtc.HasValue ? task.LastStartUtc.Value.RelativeFormat(true, "f") : "",
LastEnd = lastEndOn,
LastEndPretty = lastEndOn.HasValue ? lastEndOn.Value.ToString("G") : "",
LastSuccess = lastSuccessOn,
LastSuccessPretty = lastSuccessOn.HasValue ? lastSuccessOn.Value.ToString("G") : "",
NextRun = nextRunOn,
NextRunPretty = nextRunPretty,
LastError = task.LastError.EmptyNull(),
IsRunning = isRunning,
CancelUrl = urlHelper.Action("CancelJob", "ScheduleTask", new { id = task.Id }),
ExecuteUrl = urlHelper.Action("RunJob", "ScheduleTask", new { id = task.Id }),
EditUrl = urlHelper.Action("Edit", "ScheduleTask", new { id = task.Id }),
ProgressPercent = task.ProgressPercent,
ProgressMessage = task.ProgressMessage,
IsOverdue = isOverdue,
Duration = ""
};
var span = TimeSpan.Zero;
if (task.LastStartUtc.HasValue)
{
span = model.IsRunning ? now - task.LastStartUtc.Value : task.LastEndUtc.Value - task.LastStartUtc.Value;
if (span > TimeSpan.Zero)
{
model.Duration = span.ToString("g");
}
}
return model;
}