different timezones causing chaos with rmi

Discussion in 'Java' started by epicwinter, Apr 24, 2007.

  1. epicwinter

    epicwinter Guest

    I am working on an application deployed in an ASP model using rmi with
    a swing client. I have been running into some problems with dates
    when the client is on a different timezone than the server. If the
    client is on est and the server runs on pct then when the client
    submits a date time it translates itself and so i could either gain 3
    hours or lose 3 hours depending on the direction of the
    translation.

    I realize I can start the client/server on a particular timezone using
    the -Duser.timezone property but the users can be all over the place.
    Any recommendations on how to handle this type of situation?
    thanks
    epicwinter, Apr 24, 2007
    #1
    1. Advertising

  2. On 23 Apr 2007 17:48:51 -0700, epicwinter wrote:
    > I am working on an application deployed in an ASP model using rmi
    > with a swing client. I have been running into some problems with
    > dates when the client is on a different timezone than the server.


    Always represent times internally using UTC. Use the local timezone
    only for "user" input and output, converting as close to the user as
    possible.

    /gordon

    --
    Gordon Beaton, Apr 24, 2007
    #2
    1. Advertising

  3. epicwinter

    Lew Guest

    Gordon Beaton wrote:
    > On 23 Apr 2007 17:48:51 -0700, epicwinter wrote:
    >> I am working on an application deployed in an ASP model using rmi
    >> with a swing client. I have been running into some problems with
    >> dates when the client is on a different timezone than the server.

    >
    > Always represent times internally using UTC. Use the local timezone
    > only for "user" input and output, converting as close to the user as
    > possible.


    That doesn't help if one trusts a clock that is inaccurate or not synchronized
    with the time one does control. All timestamps should come from the same
    controlled source or else be regarded as completely unreliable.

    Generally one cannot make assumptions about times from different clocks when
    one doesn't have control over all the clocks.

    --
    Lew
    Lew, Apr 24, 2007
    #3
  4. On Tue, 24 Apr 2007 08:12:38 -0400, Lew wrote:
    > That doesn't help if one trusts a clock that is inaccurate or not
    > synchronized with the time one does control. All timestamps should
    > come from the same controlled source or else be regarded as
    > completely unreliable.
    >
    > Generally one cannot make assumptions about times from different
    > clocks when one doesn't have control over all the clocks.


    Of course you need some degree of synchronization (through ntp or a
    common time source), but exactly how well the components need to be
    synchronized ultimately depends on the needs of the application.

    However I believe the issue here is not how to achieve that
    synchronization or compensate for the lack of it, but how to deal with
    different timezones occuring within the application, for example when
    the client and server are in different geographic locations. The two
    issues are orthogonal.

    /gordon

    --
    Gordon Beaton, Apr 24, 2007
    #4
  5. epicwinter

    epicwinter Guest

    On Apr 23, 11:09 pm, Gordon Beaton <> wrote:
    > On 23 Apr 2007 17:48:51 -0700, epicwinter wrote:
    >
    > > I am working on an application deployed in an ASP model using rmi
    > > with a swing client. I have been running into some problems with
    > > dates when the client is on a different timezone than the server.

    >
    > Always represent times internally using UTC. Use the local timezone
    > only for "user" input and output, converting as close to the user as
    > possible.
    >
    > /gordon
    >
    > --


    Gordon thanks for responding. But my question is how would you
    suggest implementing your solution. I use dates all over the software
    so I am hoping not to have to write some code every time i work with a
    date.

    I am not so much concerned about handling issues when users have bad
    clocks, that would certainly be nice, but at this point I just want it
    to work when the clocks are accurate.
    epicwinter, Apr 24, 2007
    #5
  6. epicwinter

    kevin cline Guest

    On Apr 23, 7:48 pm, epicwinter <> wrote:
    > I am working on an application deployed in an ASP model using rmi with
    > a swing client. I have been running into some problems with dates
    > when the client is on a different timezone than the server. If the
    > client is on est and the server runs on pct then when the client
    > submits a date time it translates itself and so i could either gain 3
    > hours or lose 3 hours depending on the direction of the
    > translation.


    What do you mean "translates itself?" How are you passing times from
    the client to the server? If you serialize and then deserialize
    either a Date or a Calendar you should have no problem. If you are
    converting to and from some human-readable string format, then you
    need to be careful.
    kevin cline, Apr 24, 2007
    #6
  7. epicwinter

    Lew Guest

    Gordon Beaton wrote:
    > However I believe the issue here is not how to achieve that
    > synchronization or compensate for the lack of it, but how to deal with
    > different timezones occuring within the application, for example when
    > the client and server are in different geographic locations. The two
    > issues are orthogonal.


    Not entirely. If I use only server times, it eliminates the timezone problem
    with client times. Therefore, not entirely orthogonal.

    --
    Lew
    Lew, Apr 25, 2007
    #7
  8. epicwinter

    epicwinter Guest

    On Apr 24, 3:40 pm, kevin cline <> wrote:
    > On Apr 23, 7:48 pm, epicwinter <> wrote:
    >
    > > I am working on an application deployed in an ASP model using rmi with
    > > a swing client. I have been running into some problems with dates
    > > when the client is on a different timezone than the server. If the
    > > client is on est and the server runs on pct then when the client
    > > submits a date time it translates itself and so i could either gain 3
    > > hours or lose 3 hours depending on the direction of the
    > > translation.

    >
    > What do you mean "translates itself?" How are you passing times from
    > the client to the server? If you serialize and then deserialize
    > either a Date or a Calendar you should have no problem. If you are
    > converting to and from some human-readable string format, then you
    > need to be careful.


    I am serializing a java.util.Date.
    epicwinter, Apr 26, 2007
    #8
  9. epicwinter

    Karl Uppiano Guest

    "epicwinter" <> wrote in message
    news:...
    > On Apr 23, 11:09 pm, Gordon Beaton <> wrote:
    >> On 23 Apr 2007 17:48:51 -0700, epicwinter wrote:
    >>
    >> > I am working on an application deployed in an ASP model using rmi
    >> > with a swing client. I have been running into some problems with
    >> > dates when the client is on a different timezone than the server.

    >>
    >> Always represent times internally using UTC. Use the local timezone
    >> only for "user" input and output, converting as close to the user as
    >> possible.
    >>
    >> /gordon
    >>
    >> --

    >
    > Gordon thanks for responding. But my question is how would you
    > suggest implementing your solution. I use dates all over the software
    > so I am hoping not to have to write some code every time i work with a
    > date.
    >
    > I am not so much concerned about handling issues when users have bad
    > clocks, that would certainly be nice, but at this point I just want it
    > to work when the clocks are accurate.


    You should only convert to and from local time at the client UI. Everything
    should be UTC (as long milliseconds) internally - that's what you should be
    sending over RMI. Most of Java's time and calendar conversion routines work
    that way. If you work with them as they were designed, it is almost a non
    issue. But the timezones do need to be set correctly on all machines.
    Karl Uppiano, Apr 26, 2007
    #9
  10. epicwinter

    Karl Uppiano Guest

    "epicwinter" <> wrote in message
    news:...
    > On Apr 24, 3:40 pm, kevin cline <> wrote:
    >> On Apr 23, 7:48 pm, epicwinter <> wrote:
    >>
    >> > I am working on an application deployed in an ASP model using rmi with
    >> > a swing client. I have been running into some problems with dates
    >> > when the client is on a different timezone than the server. If the
    >> > client is on est and the server runs on pct then when the client
    >> > submits a date time it translates itself and so i could either gain 3
    >> > hours or lose 3 hours depending on the direction of the
    >> > translation.

    >>
    >> What do you mean "translates itself?" How are you passing times from
    >> the client to the server? If you serialize and then deserialize
    >> either a Date or a Calendar you should have no problem. If you are
    >> converting to and from some human-readable string format, then you
    >> need to be careful.

    >
    > I am serializing a java.util.Date.


    You should not do that. java.util.Date is initialized with the local time
    zone. Send the UTC time in milliseconds as a long instead. Use that to
    reconstitute a new date at the other end. The timezone conversion will be
    done automatically for you, including daylight saving time, leap years, etc.
    Karl Uppiano, Apr 26, 2007
    #10
  11. epicwinter

    kevin cline Guest

    On Apr 26, 12:29 am, "Karl Uppiano" <> wrote:
    > "epicwinter" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > On Apr 24, 3:40 pm,kevin cline<> wrote:
    > >> On Apr 23, 7:48 pm, epicwinter <> wrote:

    >
    > >> > I am working on an application deployed in an ASP model using rmi with
    > >> > a swing client. I have been running into some problems with dates
    > >> > when the client is on a different timezone than the server. If the
    > >> > client is on est and the server runs on pct then when the client
    > >> > submits a date time it translates itself and so i could either gain 3
    > >> > hours or lose 3 hours depending on the direction of the
    > >> > translation.

    >
    > >> What do you mean "translates itself?" How are you passing times from
    > >> the client to the server? If you serialize and then deserialize
    > >> either a Date or a Calendar you should have no problem. If you are
    > >> converting to and from some human-readable string format, then you
    > >> need to be careful.

    >
    > > I am serializing a java.util.Date.

    >
    > You should not do that. java.util.Date is initialized with the local time
    > zone. Send the UTC time in milliseconds as a long instead. Use that to
    > reconstitute a new date at the other end. The timezone conversion will be
    > done automatically for you, including daylight saving time, leap years, etc.


    A java.util.Date does not contain timezone information. The local
    timezone is used only when constructing a date via deprecated
    methods.
    kevin cline, Apr 27, 2007
    #11
  12. epicwinter

    kevin cline Guest

    On Apr 25, 10:17 pm, epicwinter <> wrote:
    > On Apr 24, 3:40 pm,kevin cline<> wrote:
    >
    > > On Apr 23, 7:48 pm, epicwinter <> wrote:

    >
    > > > I am working on an application deployed in an ASP model using rmi with
    > > > a swing client. I have been running into some problems with dates
    > > > when the client is on a different timezone than the server. If the
    > > > client is on est and the server runs on pct then when the client
    > > > submits a date time it translates itself and so i could either gain 3
    > > > hours or lose 3 hours depending on the direction of the
    > > > translation.

    ....
    > I am serializing a java.util.Date.


    How do you know it is "translating itself?" When you convert a Date
    to a string without explicitly specifying a timezone, the Date is
    converted to a local time in the default timezone. So if you set a
    Data to 9:00PM April 26th in US Eastern time, and then print the same
    date on a system in US Pacific time, it will be displayed as 6:00 PM
    April 26th. But they are the same time, and if you print the timezone
    information, you will see that one is
    GMT-05:00 and the other is GMT-08:00.
    kevin cline, Apr 27, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=

    ViewState chaos

    =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=, Sep 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    327
    Mythran
    Sep 8, 2005
  2. Maximilian Michel

    Class Chaos

    Maximilian Michel, Jun 28, 2004, in forum: Python
    Replies:
    9
    Views:
    419
    Reinhold Birkenfeld
    Jun 28, 2004
  3. Danno
    Replies:
    22
    Views:
    665
    Danno
    Oct 18, 2006
  4. Ian Semmel

    CSS = Chaos ?

    Ian Semmel, Oct 21, 2007, in forum: ASP .Net
    Replies:
    10
    Views:
    704
    Kevin Spencer
    Oct 25, 2007
  5. Chris Angelico
    Replies:
    0
    Views:
    59
    Chris Angelico
    Jan 31, 2014
Loading...

Share This Page