Breeze dates are not materialized correctly for mapped entities
-
21-12-2019 - |
Question
I have a date property coming into Breeze from my server. It looks like this in the JSON
"CreateTime":"2014-05-22T00:00:00.000"
The property is mapped in the metadata like this:
{
"name":"CreateTime",
"type":"Edm.DateTime",
"nullable":"false",
"precision":"7"
}
In the query results, however, the date always ends up as the epoch (Jan 1, 1970). However, this only happens when the entity is mapped in Breeze. If I select
against the entity so that I am returning an unmapped type the date is sent across the wire identically, but it works fine.
How can I get dates to materialize correctly for mapped entities?
Using Breeze v1.4.11
Update
Here is the result of calling getEntityType
on my entity:
{
"shortName":"VDisplayEvent",
"namespace":"Model",
"autoGeneratedKeyType":"None",
"defaultResourceName":"VDisplayEvents1",
"dataProperties":[
// Other properties...
{
"name":"createTime",
"dataType":"DateTime",
"isNullable":false,
"defaultValue":"1900-01-01T08:00:00.000Z",
"validators":[
{
"name":"required"
},
{
"name":"date"
}
]
},
// Other properties...
]
}
Solution
Found the problem, and it's not an issue with Breeze. My application is using a theme, which had a dependency on date.js. Apparently, date.js overrides Javascript's Date.parse()
function, which is used by Breeze's DataType.parseDateAsUTC()
.
Date.js's Date.parse()
function just returns null when confronted with parsing a date string like the one above, which was causing the issue.