Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: How to turn browser Date to server time zone

  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    74

    Default How to turn browser Date to server time zone

    Hi,

    Some customers want to have the application display date/time in server's timezone. Ideally, new date values created should also be in the server timezone. Is there anything in ExtJs can be used for that purpose? Does anyone have suggestions on how this problem might be solved?

    Thanks.

    Sean

    This feature has been implemented in Jaffa: http://jaffa.wiki.sourceforge.net/jaffa5.serverTimezone

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Answers
    4

    Default

    You could pass the server date to the app at startup and store it locally. Then create a wrapper function for Date that uses that value to initialize a Date object. Then you'd have to call that fn, rather than new Date(). You could theoretically do this by playing with the Date constructor so you wouldn't have to replace all calls to new Date(), but that could lead to a debugging nitemare down the road.

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    74

    Default

    Hi tryanDLS,

    If I am understand correctly, the gist of your solution is to get the server timezone information from server and reimplement javascript Date class functions for the server timezone. Do you know any code implementing timezone manipulation around? Is there a way to access javascript code of native functions?

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Answers
    4

    Default

    I'm not suggesting re-implementing any Date functions. I'm just suggesting that you create a function to replace your calls to new Date() with that can be initialized with the date you sent from the server. Or, send the server timezone and it could just adjust the current date by the difference between local and server timezones.

    You can add add functions to the Date prototype if you wish - there are examples of this in the Ext code. You don't really want to change implementation of base Date functionality by overriding as debugging Date issues can be a painful process - the effects are sometimes very subtle and won't be immediately noticed.

  5. #5
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    74

    Default

    The devil of this problem is at how timezone is adjusted and where it is adjusted. Take dwr as the transport between server and browser. The long millisecond value is used to send dates back and forth. This value is the absolute time value, which is same for a given date object regardless timezone. If we adjusting the millisecond value to fake up the display of server timezone date on the browser, such an adjustment needs to be undone before the date is posted back to the server. This could be tricky.

    A better way is to handle the timezone offset at the presentation level of the date object. This is not trivial either because Date.prototype.toString cannot be overriden. This limitation means that we cannot use new Date() to create a new date and cannot use the default toString the display the date. Is there any code in ExtJs needed to be modified/overriden if this is the way to display server timezone?

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Answers
    4

    Default

    Ext doesn't do any manipulation of the Date object other than to add some additional functions.

    You could add a function called toStringTZ that returns the value of the Date object adjusted by the offset you sent from the server for client display purposes. Only use this for building client UI elements, not for populating any string values you're serializing back to the server - these can call the base toString fn which will use the unadjusted value.

  7. #7
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    74

    Default

    A search on "new Date" across ExtJs code found its wide spread use. What should I do with it? Should I replace them?

    Because toString() is called implicitly, what is the best way to find its use in ExtJs?

  8. #8
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Answers
    4

    Default

    Do you really want to maintain a version of Ext where you did something like that? I think you need to take a step a back and re-think what you're trying to accomplish. Maybe you should be managing date adjustment on the server when you send/receive client data.

  9. #9
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    74

    Default

    I am still exploring the options. However, "new Date()" is still a problem in the client side if the serverside makes the adjustment. Here is the explanation. Suppose the server add a time offset to the millisecond value before the date is sent out to the client and subtract the time offset when it receives a date value posted from the client. This works well with the dates originating from the server. For dates originating from the client, the time offset needed to be done at the time of creation.

  10. #10
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Answers
    4

    Default

    Would you not just adjust every date going both ways? Regardless of whether a date field was sent from the server as server-5, or created on the client as server-5 (the local time), when it goes back to the server you always add 5.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •