Format date/time using .NET instead of JavaScript function#7
Open
y2k4life wants to merge 3 commits intodustout:masterfrom
Open
Format date/time using .NET instead of JavaScript function#7y2k4life wants to merge 3 commits intodustout:masterfrom
y2k4life wants to merge 3 commits intodustout:masterfrom
Conversation
added 3 commits
February 28, 2023 13:53
Create .NET methods to format date/time. Calling those functions from JavaScript. This replaces node-dateformat functions. Makes formatting exactly the same as .NET instead of a JavaScript library. 1. Change HTML to be semantic with HTML5 using data- and span instead of custom tags and attributes 2. Used OnAfterRenderAsync with a flag to indicate the component was created instead of using HTML observations
Owner
|
Hello Guy, In hindsight I should have named this library BlazorServerTime. The issue with calling DotNet.invokeMethodAsync for each html time node is that it can be a big hit when there are a lot of times on one page (for example in a table). |
Author
|
And I'm just now seeing that as I take this out of the lab and try it for real use. A column with date/times is all blank then the date time pops in after rendering. Something to work on. |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

If you are interested.
The thinking might be, "I'm working in .NET with Blazor why then date and time formatting done in some other fashion that is not congruent with .NET." At least it was for me. One less thing to learn when I know .NET formating.
This is to address that issue, make formatting similar to .NET
DateTime. My solution is to create .NET methods and call them from JavaScript. The challenge was having to create a date/time string that could be passed between JavaScript and .NET that would not assume the value as UTC and eliminate any type of conversion. The time zone offset also needs to be passed back to .NET methods for the same reason and to maintain the browser time without converting to server time. I used DateTimeOffset to solve some of these challenges along with formatting the time in JavaScript to ISO 8601 WITH the time zone of. One might exist but I could not find it, anything I found would convert to UTC.`Now that the converting a date/time to a string is using the
ToString()of theDateTimeall of the standard .NET formatting should work. Standard date and time format strings.I also incorporated a means to use the methods on the
DataTimeby way of reflections. For example,Format="ToShortDateString"to call theToShortDateStringof theDataTimeobject. You can call any of the methods,ToLongDateString,ToLongTimeString, or any other that returns a string. This is not completely tested and might need some work.I also did some updates to .NET 6.0 but not a complete project renaming.
If you are interested, I can continue to clean up the code for .NET 6.0 and test other
DataTimestring methods.