[GH-ISSUE #99] Support for .NET DateTime type in Qml. #58

Closed
opened 2026-05-05 11:02:45 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @MaxMommersteeg on GitHub (Dec 25, 2018).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/99

Now I have to convert it to string using a helper function on another .NET type: https://github.com/MaxMommersteeg/Qml.Net.Chat/blob/master/src/Qml.Net.Chat.Client/Controllers/ChatController.cs#L66

Can we build native support for this type, do I have to register the DateTime type or can we make this possible with the [Date Qml type] (http://doc.qt.io/qt-5/qml-qtqml-date.html)?

Originally created by @MaxMommersteeg on GitHub (Dec 25, 2018). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/99 Now I have to convert it to string using a helper function on another .NET type: https://github.com/MaxMommersteeg/Qml.Net.Chat/blob/master/src/Qml.Net.Chat.Client/Controllers/ChatController.cs#L66 Can we build native support for this type, do I have to register the DateTime type or can we make this possible with the [Date Qml type] (http://doc.qt.io/qt-5/qml-qtqml-date.html)?
Author
Owner

@pauldotknopf commented on GitHub (Dec 25, 2018):

In .NET, System.DateTime is horrible. Mainly because it doesn't contain the actual UTC offset. That means a date time value with LocalKind could literally be any time.

Because of this, System.DateTime doesn't translate well to other languages due to the missing precision.

Instead, use System.DateTimeOffset. It get's represeted perfectly in .NET and JS as fully featured and native date types.

<!-- gh-comment-id:449871561 --> @pauldotknopf commented on GitHub (Dec 25, 2018): In .NET, ```System.DateTime``` is horrible. Mainly because it doesn't contain the actual UTC offset. That means a date time value with ```LocalKind``` could literally be any time. Because of this, ```System.DateTime``` doesn't translate well to other languages due to the missing precision. Instead, use ```System.DateTimeOffset```. It get's represeted perfectly in .NET and JS as fully featured and native date types.
Author
Owner

@MaxMommersteeg commented on GitHub (Dec 25, 2018):

Alright, you are definitely right about the System.DateTime type in .NET.

I can't directly use DateTimeOffset in Qml right? So do I need to register it like I register other types (as done in Program.cs), can I convert it to a javascript date or else?

<!-- gh-comment-id:449872226 --> @MaxMommersteeg commented on GitHub (Dec 25, 2018): Alright, you are definitely right about the System.DateTime type in .NET. I can't directly use DateTimeOffset in Qml right? So do I need to register it like I register other types (as done in Program.cs), can I convert it to a javascript date or else?
Author
Owner

@pauldotknopf commented on GitHub (Dec 25, 2018):

It gets automatically converted back-and-forth, it's a built-in supported data type in qmlnet.

Check the unit tests.

<!-- gh-comment-id:449872320 --> @pauldotknopf commented on GitHub (Dec 25, 2018): It gets automatically converted back-and-forth, it's a built-in supported data type in qmlnet. Check the unit tests.
Author
Owner

@MaxMommersteeg commented on GitHub (Dec 25, 2018):

Ah check, found it here: https://github.com/qmlnet/qmlnet/blob/develop/src/net/Qml.Net.Tests/Qml/DateTimeOffsetTests.cs

Perhaps I can focus on writing down features based on unittests and add them to the Github.io pages later this week.

I will close this issue, thanks!

<!-- gh-comment-id:449872944 --> @MaxMommersteeg commented on GitHub (Dec 25, 2018): Ah check, found it here: https://github.com/qmlnet/qmlnet/blob/develop/src/net/Qml.Net.Tests/Qml/DateTimeOffsetTests.cs Perhaps I can focus on writing down features based on unittests and add them to the Github.io pages later this week. I will close this issue, thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#58
No description provided.