-
QuestionIf I create a new sportsevent...:
and I serialize it...:
the startDate is serialized like this:
Notice the time is excluded. According to schema.org, it is valid to include time in a startdate: How can I force Schema.NET to output the time as well? |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
...I will answer it myself, because (as it often happens), while typing my problem I had an idea.... If you create a DateTimeOffset like this (if the DateTime value is already UTC)...:
it serializes as expected. or like this if you already have the correct DateTime.Kind set.:
I still think it would be nice if just adding a DateTime would include the time, but maybe there is a good reason for this I am just not seeing. :) |
Beta Was this translation helpful? Give feedback.
-
Hey @kjlibsol! At the core of it, we map schema Technically, C# This is the thing though, we really treat dates as two categories:
However there is a third category we aren't handling directly:
In theory, we don't need to ever write the a C# It should be a matter of tweaking this line to avoid our custom converter if the property is both schema Schema.NET/Tools/Schema.NET.Tool/ViewModels/Property.cs Lines 64 to 67 in 963ce4f Alternatively, instead of removing the converter altogether, we could make it smarter where cases of both schema types it would only ever output C# |
Beta Was this translation helpful? Give feedback.
-
The .NET docs say that you should prefer This makes me personally happy because I never use |
Beta Was this translation helpful? Give feedback.
-
Thinking about this a little more - maybe it would be appropriate to just dynamically include something extra in the IntelliSense to identify what is going on in cases where we have both eg. Imagine a line like this: /// Use <see cref="DateTime" /> for Schema Date precision. Use <see cref="DateTimeOffset" /> for Schema DateTime precision. Would keep the original intent for accuracy when potentially referring to schema |
Beta Was this translation helpful? Give feedback.
-
We could add this in the |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if the remarks section actually shows up in IntelliSense? If it does, that would be a good place to put it. |
Beta Was this translation helpful? Give feedback.
-
@iJoris - out of curiousity, why can't you use a new WhateverYourSchemaObjectIs
{
WhateverTheDatePropertyIs = new DateTimeOffset(myDateTime)
} To completely avoid any reference to |
Beta Was this translation helpful? Give feedback.
-
@Turnerj - Sorry I've made a mistake at writing my message. I think my IDE cached the wrong parameters for the package. It works now with using: |
Beta Was this translation helpful? Give feedback.
-
@kjlibsol Are you happy to use |
Beta Was this translation helpful? Give feedback.
-
Yeah, sure. 👍 |
Beta Was this translation helpful? Give feedback.
Hey @kjlibsol!
At the core of it, we map schema
Date
to C#int/DateTime
and schemaDateTime
to C#DateTimeOffset
. If you supply a C#DateTime
, we write that as a schemaDate
. If you supply a C#DateTimeOffset
, we write that as a schemaDateTime
.Technically, C#
DateTime
is compatible with schemaDateTime
however some properties may imply a requirement for timezone information. For example, anarrivalDate
(https://schema.org/arrivalTime) can be quite critical information to potentially get wrong if someone doesn't pass timezone information.This is the thing though, we really treat dates as two categories:
Date
(date precision via C#DateTime
)DateTime
(dat…