PDA

View Full Version : [OPEN] [#224] Bug on serialization of DateFormat = "MS"



Periscope
Apr 15, 2013, 6:54 PM
There is a bug in the Ext.Net.Utilities project that is preventing the correct serialization of DateTime columns on DataGrids:

DateTime is serialized in MS format (/Date(xxxx)/) and there is a configuration to set this in Ext.Net in a ModelField (ModelField.DateFormat = "MS"), but, the DateTimeUtils, method ConvertNetToPHP, near line 216:



case "M":
final.Append("n");


resulting in:



{name:\"LastSeen\",type:\"date\",dateFormat:\"nS\"}],


The correct behaviour would be serialize dateFormat: \"MS\" instead of \"nS\"

BTW, why this Ext.Net.Utilities is not present in the premium source code access???

Baidaly
Apr 15, 2013, 10:18 PM
Hello!

Welcome to our forum!

Thank you for your report!

Can you, please, provide sample to reproduce?

geoffrey.mcgill
Apr 15, 2013, 10:26 PM
Actually, we don't need a sample for this one. Vladimir and I are discussing.

The defect will be fixed immediately.

geoffrey.mcgill
Apr 15, 2013, 10:29 PM
Ext.Net.Utilities is an open-source MIT licensed library with full source code available on GitHub, see

https://github.com/extnet/Ext.NET.Utilities

Vladimir
Apr 15, 2013, 10:31 PM
Please use M$ instead MS
See
http://examples2.ext.net/#/GridPanel/Paging_and_Sorting/JSON_WebService/

We will fix it soon (in 2.2.0 release)

geoffrey.mcgill
Apr 15, 2013, 10:46 PM
Fix has been committed to Ext.NET.Utilities project.

We will be including this fix in the upcoming Ext.NET Pro 2.2.0 release.

JCKodel
Apr 16, 2013, 4:21 AM
The M$ worked fine.

Some suggestions:

1) Create a overload with an Enum (DataFormat.Microsoft, DataFormat.ISO, etc.)

2) When using MVC, obey the global Newtonsoft JSON configuration (usually we determine the type of Date serialization in the GlobalConfig on Global.asax, but Ext.JS don't apply those settings and always serializes date as MS format).

3) Create some global Newtonsoft Configuration in Ext (just like MVC has)

4) Enable M$ by default, because it is the default format for DateColumn

Also, there is a side bug (I'm not sure if it is a bug):

In my database, the dates are in UTC (GMT+0). When serialized, the date arrives in the client side with UTC value, but with my local timezone.

Ex.: in the database, it is 16/04/2013 00:20 GMT+0
In the client, it is 16/04/2013 00:20 GMT-3

It should be GMT+0 or 16/04/2013 20:20 GMT-3

But I'm guessing this is a serialization/DateTime issue, right?

geoffrey.mcgill
Apr 16, 2013, 5:41 AM
1) Create a overload with an Enum (DataFormat.Microsoft, DataFormat.ISO, etc.)

Agreed. We can look into this. Will add as a feature request for now.


2) When using MVC, obey the global Newtonsoft JSON configuration (usually we determine the type of Date serialization in the GlobalConfig on Global.asax, but Ext.JS don't apply those settings and always serializes date as MS format).

3) Create some global Newtonsoft Configuration in Ext (just like MVC has)

We need to do some work on enabling more settings for the Json Serialization/Deserialization. This is something I'm going to look into for the 2.3.0 release.


4) Enable M$ by default, because it is the default format for DateColumn

The DateColumn should be set with a DataTime object. The string is serialized into an ISO formatted string, such as "yyyy-MM-ddTHH:mm:ss". The "MS" format is not used by default.


Also, there is a side bug (I'm not sure if it is a bug):

In my database, the dates are in UTC (GMT+0). When serialized, the date arrives in the client side with UTC value, but with my local timezone.

Ex.: in the database, it is 16/04/2013 00:20 GMT+0
In the client, it is 16/04/2013 00:20 GMT-3

It should be GMT+0 or 16/04/2013 20:20 GMT-3

But I'm guessing this is a serialization/DateTime issue, right?

I'm not sure how you're converting that client Date value into a string, but JavaScript Date objects are relative to the client machine.

Periscope
Apr 16, 2013, 4:40 PM
That's the point: I'm doing nothing out of the box =\ For some reason, the MS format is the default format (instead of ISO) and I have no control of serialization:

My PetaPoco class:



[Column] public DateTime? LastSeen { get; set; }


My Ext model method:



public static Ext.Net.ModelFieldCollection ExtModel = new Ext.Net.ModelFieldCollection
{
new Ext.Net.ModelField("ID", Ext.Net.ModelFieldType.Auto),
new Ext.Net.ModelField("Enabled", Ext.Net.ModelFieldType.Boolean),
new Ext.Net.ModelField("DisplayName", Ext.Net.ModelFieldType.String),
new Ext.Net.ModelField("Login", Ext.Net.ModelFieldType.String),
new Ext.Net.ModelField("PrimaryEMail", Ext.Net.ModelFieldType.String),
new Ext.Net.ModelField("Memo", Ext.Net.ModelFieldType.String),
new Ext.Net.ModelField("LastSeen", Ext.Net.ModelFieldType.Date, "M$"),
};


My datagrid date column code:


public static DateColumn.Builder DateTimeColumn(this HtmlHelper html, int flex, string caption, string dataFieldName, bool groupable = false)
{
return html.X().DateColumn()
.Flex(flex)
.Text(caption)
.DataIndex(dataFieldName)
.Format("c")
.Renderer("var id=this.getId() + '-' + rowIndex + '-' + colIndex;setTimeout(function(){$('#' + id).easydate(window.easyDateOptions)},100);return value == null ? res('EasyDate_Never') : '<abbr id=\"' + id + '\">' + Ext.Date.subtract(value, Ext.Date.MINUTE, new Date().getTimezoneOffset()) + '</abbr>';")
.Groupable(groupable);
}



Generated javascript:


columns:
{
items:
[
{xtype:"datecolumn",flex:2,dataIndex:"LastSeen",groupable:false,renderer:function(value,metadata, record,rowIndex,colIndex,store,view)
{
var id=this.getId() + '-' + rowIndex + '-' + colIndex;

setTimeout(function(){$('#' + id).easydate(window.easyDateOptions)},100);

return value == null ? res('EasyDate_Never') : '<abbr id="' + id + '">' + Ext.Date.subtract(value, Ext.Date.MINUTE, new Date().getTimezoneOffset()) + '</abbr>';
},
text:"Visto",
format:"c"
}


Generated data serialization:


{"data":[{"ID":"9ee5a2db-a5db-11e2-b2ac-f46d040a8d55","Enabled":true,"DisplayName":"Admin","Login":"admin","PrimaryEMail":"admin@admin.com","Memo":null,"LastSeen":"\/Date(1366137473250)\/"},{"ID


Without the dataFormat = "M$" or "MS", the data serialization still uses Microsoft Format.

It's all working, but, the defaults are not the expected ones, which will cause some troubles in MVC.

As the timezone, the Date(1366137473250) represents Tue Apr 16 2013 15:37:53 GMT-0300 (E. South America Standard Time), but should be Tue Apr 16 2013 15:37:53 GMT+0000 (because here is 12:37 pm now, not 15:37 (3:37 pm))

Nevertheless, with some fixed, all is working fine now... Thank you for the fast response. :)

geoffrey.mcgill
Apr 16, 2013, 8:33 PM
Can you demonstrate how you are binding the data to the Store. I'm assuming you are controlling the Serialization of the Data, which is using then using the default Microsoft DateTime serialization format.

If the data is bound to the Store using Ext.NET, then the ISO format is used by default.

Periscope
Apr 16, 2013, 8:56 PM
Then the defaults and timezone is my fault... I thought I was using some StoreResult, but I'm serializing with MVC.

Sorry about that :(



[HttpPost]
public ActionResult List(int page, int start, int limit, string sort, string dir, string filter)
{
using (var svc = new OrganizationService())
{
int totalCount;
var items = svc.GetUsersDataGrid(page, start, limit, sort, dir, filter, out totalCount);

return Json(new { data = items, totalCount });
}
}

Daniil
May 01, 2013, 7:46 AM
SVN commit #5090
[UPDATE] JSON class, GlobalSettings/RequestSettings properties to manage serialization

There is still something to think about. So, created an Issue.
https://github.com/extnet/Ext.NET/issues/224