Wrong time zone of calendar events

  1. #1

    Wrong time zone of calendar events

    Hello,

    The web server and the clients are in different time zones, for example:
    server: 16 Oct. 2013 8:52:36 AM
    client: 16 Oct. 2013 4:53:25 PM

    I am using the CalendarPanel (an exact copy of your calendar online example) to add events in a database. The events' time is correct in the database (sql server 2008 r2), for example this is what a query using sql server management studio returns:

    eventid calendarid startdate enddate title
    28 1 2013-10-17 16:00:00.000 2013-10-17 16:30:00.000 stis17
    27 1 2013-10-16 17:00:00.000 2013-10-16 17:00:00.000 neo111
    23 1 2013-10-16 00:00:00.000 2013-10-16 01:00:00.000 qwerty

    When I access the calendar web page from my visual studio working copy running locally (i.e. local web server), the events render correctly:
    Click image for larger version. 

Name:	callocal.PNG 
Views:	19 
Size:	2.5 KB 
ID:	7051

    But when I am using the same web application in the remote server, the time of the events is shifted by exactly the hour span between my location and the server's thus causing the calendar to render incorrectly:
    Click image for larger version. 

Name:	calwrong.PNG 
Views:	14 
Size:	2.8 KB 
ID:	7052

    Why is this happening and how can this be fixed? Does this relate to a json bug, maybe?

    Thank you very much.
  2. #2
    Hi @Mimisss,

    I think you caught a related thread correctly.
    http://forums.ext.net/showthread.php?24696

    I posted it here for references.
    Last edited by Daniil; Oct 17, 2013 at 5:22 PM.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @Mimisss,

    I think you caught a related thread correctly.
    http://forums.ext.net/showthread.php?2469

    I posted it here for references.
    ???

    wrong reference?
  4. #4
    Sorry, corrected.
  5. #5
    Quote Originally Posted by Daniil View Post
    Sorry, corrected.
    Ah, yes, the same problem. Only I am using version 1.x so there is no such thing as
    JSON.GlobalSettings.DateTimeZoneHandling
    , I guess. Should I expect a fix in a new release then?
  6. #6
    I am not sure it will appear in v1.x. Also there is no time frame for a new release. So, let's start from coming up a solution for you.

    1. Do you have Ext.NET v1 sources?

    2. Please demonstrate how you serialized the data.
  7. #7
    Quote Originally Posted by Daniil View Post
    I am not sure it will appear in v1.x. Also there is no time frame for a new release. So, let's start from coming up a solution for you.

    1. Do you have Ext.NET v1 sources?
    No.

    Quote Originally Posted by Daniil View Post
    2. Please demonstrate how you serialized the data.
    Data parsing:
        <script type="text/javascript">
            Date.parseFunctions.MS = Date.parseFunctions.M$;
            Date.formatFunctions.MS = Date.formatFunctions.M$;
        </script>
    Calendar EventStore declaration:
    <EventStore 
                    ID="EventStore1" 
                    runat="server"
                    DateFormat="M$"
                    IgnoreExtraFields="false">
                    <Proxy>
                        <ext:HttpProxy Url="/Common/CalendarService.asmx/GetEvents" Json="true" />
                    </Proxy>
                    <Reader>
                        <ext:JsonReader Root="d" />
                    </Reader>
                </EventStore>
    Declaration of custom Event object:
    Ext.calendar.EventMappings = {
        EventId: {
            name: 'EventId',
            mapping: 'id',
            type: 'int'
        },
        CalendarId: {
            name: 'CalendarId',
            mapping: 'cid',
            type: 'int'
        },
        Title: {
            name: 'Title',
            mapping: 'title',
            type: 'string'
        },
        StartDate: {
            name: 'StartDate',
            mapping: 'start',
            type: 'date',
            dateFormat: 'c'
        },
        EndDate: {
            name: 'EndDate',
            mapping: 'end',
            type: 'date',
            dateFormat: 'c'
        },
        Location: {
            name: 'Location',
            mapping: 'loc',
            type: 'string'
        },
        Notes: {
            name: 'Notes',
            mapping: 'notes',
            type: 'string'
        },
        Url: {
            name: 'Url',
            mapping: 'url',
            type: 'string'
        },
        IsAllDay: {
            name: 'IsAllDay',
            mapping: 'ad',
            type: 'boolean'
        },
        Reminder: {
            name: 'Reminder',
            mapping: 'rem',
            type: 'string'
        },
        IsNew: {
            name: 'IsNew',
            mapping: 'n',
            type: 'boolean'
        },
        UserId: {
            name: 'UserId',
            mapping: 'UserId'
        },
        CustomerId: {
            name: 'CustomerId',
            mapping: 'CustomerId',
            type: 'int'
        }
    };
    
    (function () {
        var M = Ext.calendar.EventMappings;
    
        Ext.calendar.EventRecord = Ext.data.Record.create([
        M.EventId,
        M.CalendarId,
        M.Title,
        M.StartDate,
        M.EndDate,
        M.Location,
        M.Notes,
        M.Url,
        M.IsAllDay,
        M.Reminder,
        M.IsNew,
        M.UserId,
        M.CustomerId
        ]);
    
        Ext.calendar.EventRecord.reconfigure = function () {
            Ext.calendar.EventRecord = Ext.data.Record.create([
            M.EventId,
            M.CalendarId,
            M.Title,
            M.StartDate,
            M.EndDate,
            M.Location,
            M.Notes,
            M.Url,
            M.IsAllDay,
            M.Reminder,
            M.IsNew,
            M.UserId,
            M.CustomerId
            ]);
        };
    })();
    GetEvents web service method:
    public IEnumerable<My.Repository.Event> GetEvents(DateTime? start, DateTime? end)
            {
                   // linq query to return collection of events from database
            }
    Each event is automatically saved to database upon insertion:

    var CompanyX = {
        getCalendar: function () { return CompanyX.CalendarPanel1; },
        getStore: function () { return CompanyX.EventStore1; },
        getWindow: function () { return CompanyX.EventEditWindow1; },
        ...
        record: {
            add: function (win, rec) {
                win.hide();
                rec.data.IsNew = false;
                CompanyX.record.save(rec);
                CompanyX.ShowMsg('event added');
            },
            save: function (rec) {
                Ext.net.DirectMethod.request({
                    url: "Common/CalendarService.asmx/Save",
                    json: true,
                    cleanRequest: true,
                    params: {
                        e: rec.data
                    },
                    success: function (result) {
                        rec.data.EventId = result.EventId;  // get new record id
                        rec.data.UserId = result.UserId;    // set custom event data value
                        CompanyX.getStore().add(rec);    // add to store 
                    }
                });
          }    
    }
    Save web service method:
    public My.Repository.Event Save(My.Repository.Event e)
            {
                // linq query to insert event to database
                MyDataContext cxt = new MyDataContext();
                cxt.Events.InsertOnSubmit(e);
                cxt.SubmitChanges();
                return e;
            }
    FYI, I've also tried your online Remote Data Calendar example as is (i.e. without a custom Event object and saving) with the same results.

    If there is anything else I can provide you with, please let me know.
  8. #8

    Data serialization

    Quote Originally Posted by Daniil View Post
    2. Please demonstrate how you serialized the data.
    This is what Firefox Web Console reports as json response (for the three events demonstrated in my first post):

    Title: "stis17"
    StartDate: "/Date(1382043600000)/"
    EndDate: "/Date(1382045400000)/"
    
    Title: "neo111"
    StartDate: "/Date(1381960800000)/"
    EndDate: "/Date(1381960800000)/"
    
    Title: "qwerty"
    StartDate: "/Date(1381899600000)/"
    EndDate: "/Date(1381903200000)/"
  9. #9
    So, any thoughts?

    Is the problem with the json serialization or the way javascript interprets dates on the browser? Here is a long conversation on the subject... other pppl have same issues with different platforms so it may not be an ext.net problem after all.

    But, solution?

    The hosting server has UTC offset -5. My local UTC offset is 3. After retrieving the events with local times from database, the calendar keeps displaying them with an extra 8 hours added to StartDate and EndDate.

    Last but not least, upon event creation I am just saving the datetime provided by the calendar. Maybe, things could be fixed if the calendar provided a UTC time instead of a local time?
    Last edited by Dimitris; Oct 21, 2013 at 8:44 PM.
  10. #10
    Yes, it is not a problem in Ext.NET. It is how a WebService serializes the dates. Ext.NET doesn't affect it.

    The same problem was discussed here.
    http://forums.ext.net/showthread.php?25715

    You should be able to pick up a solution there.

Similar Threads

  1. Replies: 14
    Last Post: Oct 18, 2013, 6:04 AM
  2. Replies: 5
    Last Post: Feb 17, 2013, 12:51 AM
  3. [CLOSED] Time zone for time in UTC
    By krzak in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jun 01, 2011, 1:56 PM
  4. Replies: 15
    Last Post: Feb 03, 2011, 1:27 PM
  5. [CLOSED] Different time zone settings on DateFields
    By georgek in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 04, 2010, 1:40 AM

Tags for this Thread

Posting Permissions