Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the format of all date times by properly converting them to local time #428

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
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 number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
<div class="row mb-3">
<div class="col-md-12 col-lg-4">
<div class="label">Start Time</div>
@(TaskInstance.StartedAt?.DateTime.RelativeFormat() ?? "-")
@(TaskInstance.StartedAt?.RelativeFormat() ?? "-")
</div>
<div class="col-md-12 col-lg-4">
<div class="label">End Time</div>
@(TaskInstance.EndedAt?.DateTime.RelativeFormat() ?? "-")
@(TaskInstance.EndedAt?.RelativeFormat() ?? "-")
</div>
<div class="col-md-12 col-lg-4">
<div class="label">Duration</div>
Expand Down Expand Up @@ -117,8 +117,8 @@
@foreach (var run in TaskInstance.Runs)
{
<tr>
<td>@run.StartedAt.DateTime.RelativeFormat()</td>
<td class="text-center">@(run.EndedAt?.DateTime.RelativeFormat() ?? "-")</td>
<td>@run.StartedAt.RelativeFormat()</td>
<td class="text-center">@(run.EndedAt?.RelativeFormat() ?? "-")</td>
<td class="text-center">@(run.EndedAt.HasValue ? run.EndedAt.Value.Subtract(run.StartedAt).ToString("hh\\:mm\\:ss\\.fff") : "-")</td>
<td class="text-center"><span class="badge rounded-pill badge rounded-pill border border-@run.Outcome.GetColorClass() text-@run.Outcome.GetColorClass()">@(run.Outcome ?? TaskInstanceStatus.Pending)</span></td>
</tr>
Expand All @@ -145,7 +145,7 @@
@foreach (var retry in TaskInstance.Retries)
{
<tr>
<td>@retry.Time.DateTime.RelativeFormat()</td>
<td>@retry.Time.RelativeFormat()</td>
<td class="text-center">@retry.Number</td>
<td class="text-center">
<DocumentDetails Label="Cause" Document="@retry.Cause" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<tr @onclick="async _ => await OnToggleRow()" class="cursor-pointer">
<td>@TaskInstance.Reference</td>
<td class="text-center"><span class="badge rounded-pill badge rounded-pill border border-@TaskInstance.Status.GetColorClass() text-@TaskInstance.Status.GetColorClass()">@(TaskInstance.Status ?? TaskInstanceStatus.Pending)</span></td>
<td class="text-center">@(TaskInstance.StartedAt?.DateTime.RelativeFormat() ?? "-")</td>
<td class="text-center">@(TaskInstance.EndedAt?.DateTime.RelativeFormat() ?? "-")</td>
<td class="text-center">@(TaskInstance.StartedAt?.RelativeFormat() ?? "-")</td>
<td class="text-center">@(TaskInstance.EndedAt?.RelativeFormat() ?? "-")</td>
<td class="text-center">
@if (TaskInstance.StartedAt.HasValue == true && TaskInstance.EndedAt.HasValue == true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
<div class="row mb-3">
<div class="col-md-12 col-lg-4">
<div class="label">Start Time</div>
@(workflowInstance.Status?.StartedAt?.DateTime.RelativeFormat() ?? "-")
@(workflowInstance.Status?.StartedAt?.RelativeFormat() ?? "-")
</div>
<div class="col-md-12 col-lg-4">
<div class="label">End Time</div>
@(workflowInstance.Status?.EndedAt?.DateTime.RelativeFormat() ?? "-")
@(workflowInstance.Status?.EndedAt?.RelativeFormat() ?? "-")
</div>
<div class="col-md-12 col-lg-4">
<div class="label">Duration</div>
Expand Down Expand Up @@ -112,8 +112,8 @@
@foreach (var run in workflowInstance.Status.Runs)
{
<tr>
<td>@run.StartedAt.DateTime.RelativeFormat()</td>
<td class="text-center">@(run.EndedAt?.DateTime.RelativeFormat() ?? "-")</td>
<td>@run.StartedAt.RelativeFormat()</td>
<td class="text-center">@(run.EndedAt?.RelativeFormat() ?? "-")</td>
<td class="text-center">@(run.EndedAt.HasValue ? run.EndedAt.Value.Subtract(run.StartedAt).ToString("hh\\:mm\\:ss\\.fff") : "-")</td>
</tr>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@
<span class="badge rounded-pill badge rounded-pill border border-@instance.Status?.Phase.GetColorClass() text-@instance.Status?.Phase.GetColorClass()">@(instance.Status?.Phase ?? WorkflowInstanceStatusPhase.Pending)</span>
break;
case "Creation Time":
@instance.Metadata.CreationTimestamp?.DateTime.RelativeFormat()
@instance.Metadata.CreationTimestamp?.RelativeFormat()
break;
case "Start Time":
@(instance.Status?.StartedAt?.DateTime.RelativeFormat() ?? "-")
@(instance.Status?.StartedAt?.RelativeFormat() ?? "-")
break;
case "End Time":
@(instance.Status?.EndedAt?.DateTime.RelativeFormat() ?? "-")
@(instance.Status?.EndedAt?.RelativeFormat() ?? "-")
break;
case "Duration":
@(instance.Status?.StartedAt.HasValue == true && instance.Status?.EndedAt.HasValue == true ? instance.Status.EndedAt.Value.Subtract(instance.Status.StartedAt.Value).ToString("hh\\:mm\\:ss\\.fff") : "-")
Expand Down
23 changes: 9 additions & 14 deletions src/dashboard/Synapse.Dashboard/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ namespace Synapse.Dashboard.Extensions;
/// </summary>
public static class DateTimeExtensions
{

/// <summary>
/// Formats the provided <see cref="DateTime"/> in a relative fashion (e.g.: 3 minutes ago, Yesterday at 1:00pm...)
/// Formats the provided <see cref="DateTimeOffset"/> in a relative fashion (e.g.: 3 minutes ago, Yesterday at 1:00pm...)
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static string RelativeFormat(this DateTime dateTime)
/// <param name="dateTime">The extended <see cref="DateTimeOffset"/></param>
/// <returns>The <see cref="DateTimeOffset"/>, formatted in a relative fashion</returns>
public static string RelativeFormat(this DateTimeOffset dateTime)
{
var now = DateTime.Now;
var now = DateTimeOffset.Now;
var delta = now.Subtract(dateTime);
if (Math.Abs(delta.Days) >= 1)
{
Expand All @@ -43,15 +44,9 @@ public static string RelativeFormat(this DateTime dateTime)
defaults.LastWeek,
$"{cultureFormats.ShortDatePattern} {cultureFormats.ShortTimePattern}"
);
return now.CalendarTime(dateTime, formats);
}
else if (delta < TimeSpan.Zero)
{
return dateTime.ToNow();
}
else
{
return dateTime.FromNow();
return now.DateTime.CalendarTime(dateTime.DateTime, formats);
}
else if (delta < TimeSpan.Zero) return dateTime.DateTime.ToNow();
else return dateTime.DateTime.FromNow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<tr @onclick="async _ => await OnShowResourceDetailsAsync(correlation)" class="cursor-pointer">
<td class="text-start" title="The namespace the correlation belongs to">@correlation.Metadata.Namespace</td>
<td class="text-start" title="The correlation's name">@correlation.Metadata.Name</td>
<td class="text-center" title="The date and time at which the correlation has been created">@correlation.Metadata.CreationTimestamp?.DateTime.RelativeFormat()</td>
<td class="text-center" title="The date and time at which the correlation was last modified">@correlation.Status?.LastModified?.DateTime.RelativeFormat()</td>
<td class="text-center" title="The date and time at which the correlation has been created">@correlation.Metadata.CreationTimestamp?.RelativeFormat()</td>
<td class="text-center" title="The date and time at which the correlation was last modified">@correlation.Status?.LastModified?.RelativeFormat()</td>
<td class="text-center" title="@GetStatusPhaseTitle(correlation.Status?.Phase)"><span class="badge rounded-pill border border-@GetStatusPhaseClass(correlation) text-@GetStatusPhaseClass(correlation)">@correlation.Status?.Phase</span></td>
<td class="text-center" title="@GetLifetimeTitle(correlation.Spec.Lifetime)"><span class="badge rounded-pill border border-secondary text-secondary">@correlation.Spec.Lifetime</span></td>
<td class="text-center" title="@GetEventConsumptionStrategyTitle(correlation)"><span class="badge rounded-pill border border-secondary text-secondary">@GetEventConsumptionStrategy(correlation)</span></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<tr @onclick="async _ => await OnShowResourceDetailsAsync(resource)" class="cursor-pointer">
<td class="text-start">@resource.Metadata.Namespace</td>
<td class="text-start">@resource.Metadata.Name</td>
<td class="text-center">@resource.Metadata.CreationTimestamp?.DateTime.RelativeFormat()</td>
<td class="text-center">@resource.Metadata.CreationTimestamp?.RelativeFormat()</td>
<td class="text-center"><span class="badge rounded-pill border border-@resource.Status?.Phase.GetColorClass() text-@resource.Status?.Phase.GetColorClass()">@resource.Status?.Phase</span></td>
<td class="text-end">
<button class="btn btn-sm btn-dark" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false" title="" @onclick:stopPropagation="true"><i class="bi bi-three-dots-vertical"></i></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<tr @onclick="async _ => await OnShowResourceDetailsAsync(resource)" class="cursor-pointer">
<td class="text-start">@resource.Metadata.Namespace</td>
<td class="text-start">@resource.Metadata.Name</td>
<td class="text-center">@resource.Metadata.CreationTimestamp?.DateTime.RelativeFormat()</td>
<td class="text-center">@resource.Metadata.CreationTimestamp?.RelativeFormat()</td>
<td class="text-center"><span class="badge rounded-pill border border-@resource.Status?.Phase.GetColorClass() text-@resource.Status?.Phase.GetColorClass()">@resource.Status?.Phase</span></td>
<td class="text-end">
<button class="btn btn-sm btn-dark" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false" title="" @onclick:stopPropagation="true"><i class="bi bi-three-dots-vertical"></i></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@
<a href="#" @onclick="_ => Store.SetNamespace(resource.Metadata.Namespace)" @onclick:preventDefault="true" @onclick:stopPropagation="true">@resource.Metadata.Namespace</a>
<a href="/namespaces/@resource.Metadata.Namespace" @onclick:stopPropagation="true"><Icon Name="IconName.BoxArrowUpRight" Class="small" /></a>
</td>
<td class="text-center">@resource.Metadata.CreationTimestamp?.DateTime.RelativeFormat()</td>
<td class="text-center">@(resource.Status?.Versions.Where(v => v.Value.LastStartedAt.HasValue).Select(v => v.Value.LastStartedAt).Order().LastOrDefault()?.DateTime.RelativeFormat() ?? "-")</td>
<td class="text-center">@(resource.Status?.Versions.Where(v => v.Value.LastEndedAt.HasValue).Select(v => v.Value.LastEndedAt).Order().LastOrDefault()?.DateTime.RelativeFormat() ?? "-")</td>
<td class="text-center">@resource.Metadata.CreationTimestamp?.RelativeFormat()</td>
<td class="text-center">@(resource.Status?.Versions.Where(v => v.Value.LastStartedAt.HasValue).Select(v => v.Value.LastStartedAt).Order().LastOrDefault()?.RelativeFormat() ?? "-")</td>
<td class="text-center">@(resource.Status?.Versions.Where(v => v.Value.LastEndedAt.HasValue).Select(v => v.Value.LastEndedAt).Order().LastOrDefault()?.RelativeFormat() ?? "-")</td>
<td class="text-center">@resource.Spec.Versions.Count</td>
<td class="text-center">@resource.Spec.Versions.GetLatest().Document.Version</td>
<td class="text-center">@resource.Status?.Versions.Values.Sum(s => s.TotalInstances)</td>
Expand Down
Loading