Skip to content

Commit

Permalink
Date and times formats and conversions fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iwedaz committed Jan 24, 2024
1 parent 6e48630 commit 576268d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
Date = DateTime.Now,
DateOnly = DateOnly.FromDateTime(DateTime.Now),
TimeOnly = TimeOnly.FromDateTime(DateTime.Now),
TimeSpan = TimeSpan.FromHours(3),
TimeSpan = new TimeSpan(3, 2, 1, 44, 55555),
Price = Random.Shared.NextDouble()
});
}
Expand Down
35 changes: 22 additions & 13 deletions src/DotNetEd.CoreAdmin/Views/Shared/EditorTemplates/Date.cshtml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
@model object

@if (Model is DateTime?)
@switch (Model)
{
var date = (DateTime?)Model;
@Html.TextBox("", (date.HasValue ? date.Value.ToString("yyyy-MM-dd") : string.Empty), new { type = "date", @class = "datePicker form-control" })
}
case DateTime dateTimeValue:
{
@Html.TextBox("", dateTimeValue.ToString("yyyy-MM-dd"), new { type = "date", @class = "datePicker form-control" });
break;
}

@if (Model is DateTimeOffset?)
{
var date = (DateTimeOffset?)Model;
@Html.TextBox("", (date.HasValue ? date.Value.ToString("yyyy-MM-dd") : string.Empty), new { type = "date", @class = "datePicker form-control" })
}
case DateTimeOffset dateTimeOffsetValue:
{
@Html.TextBox("", dateTimeOffsetValue.ToString("yyyy-MM-dd"), new { type = "date", @class = "datePicker form-control" });
break;
}

@if (Model is DateOnly?)
{
var date = (DateOnly?)Model;
@Html.TextBox("", (date.HasValue ? date.Value.ToString("yyyy-MM-dd") : string.Empty), new { type = "date", @class = "datePicker form-control" })
case DateOnly dateOnlyValue:
{
@Html.TextBox("", dateOnlyValue.ToString("yyyy-MM-dd"), new { type = "date", @class = "datePicker form-control" });
break;
}

default:
{
@Html.TextBox("", null, new { type = "date", @class = "datePicker form-control" })
break;
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@model DateOnly?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToString("O") : string.Empty), new { type = "date", @class = "datePicker form-control" })
@Html.TextBox("", Model?.ToString("yyyy-MM-dd"), new { type = "date", @class = "datePicker form-control" })
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToString("s") : string.Empty), new { type = "datetime-local", @class = "datePicker form-control" })
@Html.TextBox("", Model?.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss.fff"), new { type = "datetime-local", @class = "datePicker form-control" })
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@model DateTimeOffset?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToString("s") : string.Empty), new { type = "datetime-local", @class = "datePicker form-control" })
@Html.TextBox("", Model?.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss.fff"), new { type = "datetime-local", @class = "datePicker form-control" })
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@model TimeOnly?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToString("HH:mm:ss") : string.Empty), new { type = "time", @class = "form-control" })
@Html.TextBox("", Model?.ToString("HH:mm:ss.fff"), new { type = "time", @class = "form-control" })
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@model TimeSpan?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToString("c") : string.Empty), new { type = "time", @class = "form-control" })
@Html.TextBox("", Model?.Ticks, new { type = "number", @class = "text-box single-line form-control number-form-control", max = Int64.MaxValue, min = Int64.MinValue })

0 comments on commit 576268d

Please sign in to comment.