This is a migrated thread and some comments may be shown as answers.

Parameter JSON date format issue

4 Answers 392 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Scott Waye asked on 03 Oct 2015, 06:02 PM

 Hi,

 Using the HTML report viewer I am generating the html/javascript from an aspx class and am adding date parameters so that the resulting Javascript looks like this:

 

$("#reportViewer1")
    .telerik_ReportViewer({
         
        // The URL of the service which will serve reports.
        // The URL corresponds to the name of the controller class (ReportsController).
        // For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
        serviceUrl: "api/reports/",
 
        // The URL for the report viewer template. The template can be edited -
        // new functionalities can be added and unneeded ones can be removed.
        // For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
        templateUrl: 'ReportViewer/templates/telerikReportViewerTemplate-9.2.15.930.html',
 
        //ReportSource - report description
        reportSource: {
 
            // The report can be set to a report file name (trdx report definition)
            // or CLR type name (report class definition).
            report: "ReasonsForDemurrageBasic",
 
            // Parameters name value dictionary
            parameters: {
                restrictClientAccountCompanyKey : 1,portKey : 2,dateFormat : "dd/MM/yy",startDate : new Date("2015/01/01"),endDate : new Date("2015/11/01"),suppressTitles : false
            }
        },

 

So you can see that I am setting up to date parameters without times.  I want these dates to be passed back when executing the report as is, I don't want any timezone conversion.  When the report is run, using Fiddler I can see that the request is:

 

{"report":"ReasonsForDemurrageBasic","parameterValues":{"restrictClientAccountCompanyKey":1,"portKey":2,"dateFormat":"dd/MM/yy","startDate":"2015-01-01T05:00:00.000Z","endDate":"2015-11-01T05:00:00.000Z","suppressTitles":false}}

 

You can see that it has assumed that I want the dates converted (with an assumption of a time if 0:0:0 in my local timezone) into UTC.  I realise that the trend now is for JSON to write dates in this format with the timezone, but is there a way without hacking telerikReportViewer-9.2.15.930.min.js to stop it adjusting the time?  "startDate":"2015-01-01T00:00:00.000Z" would be ok for example in this case.

 

Thanks,

 Scott

4 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 07 Oct 2015, 02:07 PM
Hi Scott,

The HTML5 Viewer sends DateTime values in UTC format to the server. If you want to skip the Time part, in expressions use only the Date part of the report parameters.
Other approaches are to send the timezone as another parameter and to use it on the server to adjust the submitted DateTime values, or send values in string format (set parameters' Type properties to String).


Let us know if you need any further help.

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Scott Waye
Top achievements
Rank 2
Veteran
Iron
answered on 07 Oct 2015, 04:17 PM
Hi,  Thanks for the reply.  The first suggestion has a problem with timezones to the west.  A datetime starting as just a date of 1 Oct 2015, ends up as 30 Sep 2015 19:00 Z-5.   I could convert to a string I suppose, doesn't sound great, but should work ok.  Alternatively I suppose I can hack your javascript.  I will make a suggestion that you support a date datatype to make this better.
0
Scott Waye
Top achievements
Rank 2
Veteran
Iron
answered on 08 Oct 2015, 01:20 PM

I changed my code to generate the parameters as UTC dates :

 

parameters: {startDate : new Date(Date.UTC(2015,0,1)),endDate : new Date(Date.UTC(2015,1,1))

 

And although it looks a little odd as the date parts get converted to the previous day on the browser (but with the -5 timezone), they get converted back when the reports runs and so its ok.

0
Stef
Telerik team
answered on 09 Oct 2015, 02:24 PM
Hi Scott,

My recommendation is to rely on the default setting where client Datetime values are converted to UTC values before being submitted to the server. Thus you can avoid modifying the viewer's JS file (functionality). All DateTime values can be stored in UTC format on the server and handled respectively for any client in different time zone.

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Answers by
Stef
Telerik team
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Share this question
or