PDA

View Full Version : [CLOSED] JSON is using the user's current time zone when converting a DateTime



RCN
May 03, 2013, 12:21 PM
I found an issue regarding the DateTime conversion by Json. I have a GridPanel with a date column but when i run the example my current time zone is -3:00 (Brazil) is applied to the value of date column.

6153

It was supposed to be 09:14:..

Note: i found another thread regarding this issue, but i think that it's incomplete: http://forums.ext.net/showthread.php?18942-CLOSED-Wrong-JSON-Date-Timezone

1 - View


<ext:GridPanel ID="GridPanel1" runat="server" Title="Records">
<Store>
<ext:Store runat="server" ID="Store2">
<Proxy>
<ext:AjaxProxy Url="/Example/LoadFakeRecords/">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="data" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="Model2" runat="server">
<Fields>
<ext:ModelField Name="ID" Type="String" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="Birthdate" Type="Date" DateFormat="d/m/Y H:i:s">
<Convert Handler="return Ext.util.Format.date(value, 'd/m/Y H:i:s');" />
</ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:RowNumbererColumn ID="RowNumbererColumn1" runat="server" />
<ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" />
<ext:Column ID="Column3" runat="server" Text="Name" DataIndex="Name" />
<ext:Column ID="Column2" runat="server" Text="Birthdate" DataIndex="Birthdate" />
</Columns>
</ColumnModel>
</ext:GridPanel>


2 - Controller


public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
return View();
}

public StoreResult LoadFakeRecords()
{
List<Person> lst = new List<Person>();

for (int index = 0; index < 15; index++)
{
lst.Add(new Person
{
ID = index,
Name = "Name" + index,
Birthdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, index)
});
}

return new StoreResult(lst, lst.Count());
}
}


3 - Utility


public class Person
{
public int ID { get; set; }

public string Name { get; set; }

public DateTime Birthdate { get; set; }
}


Thanks in advance

Vladimir
May 03, 2013, 12:42 PM
Try to set in web.config


dateTimeZoneHandling="RoundtripKind"


or in Global.asax


JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.RoundtripKind ;

RCN
May 03, 2013, 1:13 PM
Unfortunately, i was not able to find any source that explain how to make that configuration in the Web.Config.

In Global.asax it works perfectly.

RCN
May 03, 2013, 4:10 PM
Sorry Vladimir, i thought it worked but it didn't. To accomplish it, it's necessary to do the following in the Global.asax:



Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;

Daniil
May 06, 2013, 4:03 AM
Hi,

I was able to reproduce the problem in IE9 and Chrome, but not in FireFox.

I can confirm that DateTimeZoneHandling.Local appears to help remedy the problem,the RoundtripKind setting doesn't.


Unfortunately, i was not able to find any source that explain how to make that configuration in the Web.Config.

Just in the "extnet" section.

<extnet dateTimeZoneHandling="Local" />

RCN
May 06, 2013, 11:27 AM
Thank you Danill

shmuly
May 08, 2013, 3:49 PM
Sorry Vladimir, i thought it worked but it didn't. To accomplish it, it's necessary to do the following in the Global.asax:



Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;


I tried this (web.config option) in my Web Forms site. I got an error stating that the attribute was unrecognized.

RCN
May 08, 2013, 3:56 PM
Please try to add the following code into your Global.asax



protected void Application_Start()
{
Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
}

shmuly
May 08, 2013, 4:02 PM
Please try to add the following code into your Global.asax



protected void Application_Start()
{
Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
}


I'm getting an error "GlobalSettings is not a member of Ext.Net.JSON"

RCN
May 08, 2013, 4:13 PM
you must update from SVN

shmuly
May 08, 2013, 4:33 PM
you must update from SVN

I don't have access to SVN since I'm still in the research phase of our application. I'm developing a POC in order to make the decision whether to go with Ext.net or not.

RCN
May 08, 2013, 4:53 PM
Unfortunately i cannot provide you an updated version of the DLL's. You must request them from a Ext.Net Support Member

Daniil
May 09, 2013, 3:32 AM
Hi @shmuly,

That option will go to the next official release. Thank you for your interest in Ext.NET!

Dimitris
Oct 17, 2013, 7:12 AM
I think the same problem exists in version 1.x. How can it be configured?

Daniil
Oct 18, 2013, 6:04 AM
The discussion regarding v1.x is continued here:
http://forums.ext.net/showthread.php?26869