3

I encountered the following problem in a simple project with Breeze + Knockout + WebAPI + SQL Server Compact:

when I add a Breeze entity (with a DateTime ko.observable) and do Manager.SaveChanges() the row is correctly saved into SQL Server Compact, and the DateTime column is in this format: 23/12/2012 19.56.33.

When I subsequently do a Breeze query, I get the row back, but the DateTime value is not recognized:

Invalid Date

The date field is a ko observable so I can't debug the value/format, it's a method!

Before the SaveChanges it's in this format: Sun Dec 23 21:32:05 UTC+0100 2012

After the SaveChanges I find it in the SQL Server Compact table in this format: 23/12/2012 20.32.05

perhaps Breeze expects it also in UTC..?

Any help is greatly appreciated!

Thanks

EDIT:

here is the json returned from WebApi BreezeController:

[
   {
      "$id":"1",
      "$type":"MvcTask.Models.Task, MvcTask",
      "id":110,
      "text":"aaa",
      "done":false,
      "created":"2012-12-23T19.56.33.950"
   }
]
frenchfaso
  • 481
  • 5
  • 17
  • Can you post the json that you page receives from server? If your not using JSON.Net as your serializer, your issue is probably covered by this SO Question http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format – photo_tom Dec 23 '12 at 20:46
  • Hy photo_tom, I've edited the question to include the json, thank You for Your help! – frenchfaso Dec 23 '12 at 22:10

2 Answers2

1

There was a problem with this with earlier versions of breeze but it should be fixed in later versions. Can you try the current version v.80.1?

Jay Traband
  • 17,053
  • 1
  • 23
  • 44
  • already updated to version 80.1 but nothing changed... same error. – frenchfaso Dec 24 '12 at 00:52
  • In addition the time is not correct, 1 hour less (I'm in utc + 1 zone) javascript outputs it correctly, but Breeze saves it wrong in the Sql – frenchfaso Dec 24 '12 at 12:17
  • Also tried with the 80.2 "Todo" breeze sample, trying to output the "CreatedAt" value gives me the same "Invalid Date" error. Waiting for a fix :-) Thanks. – frenchfaso Dec 27 '12 at 16:13
  • I an unable to confirm this problem with the latest version of breeze (v 0.82.1), using IE9, Firefox and Chrome. What browser are you using? – Jay Traband Jan 04 '13 at 17:23
  • Sorry for the delay, updated Breeze to 0.84.4, same error. Downloaded latest Todo example, trying to change the "done" checkbox, get the same error (red alert bottom right of the screen "CreatedAt must be a date") – frenchfaso Jan 17 '13 at 14:25
  • PS: in the 0.84.4 ToDo example (above comment) adding and deleteing records is working fine, it's the update that fres the date error. My specs: Win8 enterp. ITA I tried with IE10 and Chrome 24.0.1312.52 m The Todo sample is the one with ko + ef + sql compact – frenchfaso Jan 17 '13 at 14:30
  • Have no idea how updating can cause the date error since the CreatedAt date is only ever touched when the Todo is created. Hate to suggest this but I suspect some form of corruption on your end. Simply cannot be reproduced on any of our machines. Just tried Todo again with v.0.85.2. No problem. You could zip the **failing Todo sample** and send to breeze at ideablade dot com. We may have time to look at it. No promises. – Ward Jan 18 '13 at 11:03
  • After a very long delay, I found something that could help You pin this out: Win8 Ent Italian + VS2012 English --> date format bug, but Win8 Ent English + VS2012 English --> no bug! – frenchfaso Feb 17 '13 at 13:19
  • 1
    After further tests, the problem lies in the "Region Formats" (Windows control panel), not the "Display language" or "Location". If I set "Region Formats" to be "English (US)" the date problem disappears. – frenchfaso Feb 17 '13 at 13:35
-1

Your problem has to do with the default date formatter is not giving you exactly what you are looking for. It looks like you are receiving data in UTC form and your code doesn't expect this.

Take a look at ASP.NET Web API Date format in JSON does not serialise successfully.

They have a similar issue, but show how to customize the serializer. I've done this technique in past and it solved my problems

Community
  • 1
  • 1
photo_tom
  • 7,292
  • 14
  • 68
  • 116
  • Your controller should use the [Breeze] attribute which incorporates a JSON formatter configured specifically for BreezeJS client use. The date/time formatting is ISO 8601 standard. I do not believe this is a JSON formatting problem – Ward Jan 18 '13 at 10:50