1. #1
    Sencha User
    Join Date
    Apr 2009
    Location
    France
    Posts
    50
    Vote Rating
    0
    G.edwin is on a distinguished road

      0  

    Default Date change on client side - TimeZone

    Date change on client side - TimeZone


    Hi,

    I faced an issue with dates, we have deployed an application on a Paris' server, and the user is based in London (so we have a gap of an hour). When the user displays date recovered in database, he has an hour of difference with the database data (From a user based in Paris we can't see a difference with database's data.)

    If i change my local TimeZone, the bug appears. Some trace show that in server side, date's data are not transformed, so i guess it's on the client side or while the RPC. How can I specify in gwt-gxt to does not modify date (whatever the TimeZone of the user) ?

    Thanks a lot !

  2. #2
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    GWT RPC will loose timezone information. The date will actually stay the same, but the server will show it at its timezone

  3. #3
    Sencha User
    Join Date
    Apr 2009
    Location
    France
    Posts
    50
    Vote Rating
    0
    G.edwin is on a distinguished road

      0  

    Default


    Can't I force the client side to use a specific TimeZone ?
    (with DateTimeFormat.getFormat(...) or something ?)

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You can override (overload) the GWT RPC custom date serializer with any behaviour you need.

    You could also send the date not as date but as date, month and year if you need the informations regardless of timezone

  5. #5
    Sencha User
    Join Date
    Apr 2009
    Location
    France
    Posts
    50
    Vote Rating
    0
    G.edwin is on a distinguished road

      0  

    Default


    Thanks, i dig into it, and find that could be solve my problem :

    Code:
    /**
     * Custom field serializer for {@link java.util.Date}.
     */
    public final class Date_CustomFieldSerializer {
    
          public static void deserialize(SerializationStreamReader streamReader,Date instance) {
            // No fields
          }
        
          public static Date instantiate(SerializationStreamReader streamReader) throws SerializationException {
        //    return new Date(streamReader.readLong());
            return new Date(streamReader.readInt(),streamReader.readInt(),streamReader.readInt(),streamReader.readInt(),streamReader.readInt());
          }
        
          public static void serialize(SerializationStreamWriter streamWriter,
              Date instance) throws SerializationException {
        //    streamWriter.writeLong(instance.getTime());
              System.out.println("serialize date...");
            streamWriter.writeInt(instance.getYear());
            streamWriter.writeInt(instance.getMonth());
            streamWriter.writeInt(instance.getDate());
            streamWriter.writeInt(instance.getHours());
            streamWriter.writeInt(instance.getMinutes());
          } 
    }
    But, should i have to replace the GWT Date_CustomFieldSerializer class by this one ? Or is there a way i could use my Date_CustomFieldSerializer instead of the GWT's one ?

  6. #6
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You need to overload it. But yours higher in the classpath than the GWT one.

  7. #7
    Sencha User
    Join Date
    Apr 2009
    Location
    France
    Posts
    50
    Vote Rating
    0
    G.edwin is on a distinguished road

      0  

    Default


    Ok, do you mean doing that ?

    Code:
    public class GenDealModelDto extends BaseModelData implements Serializer  {
    
       /* constructor... getters & setters of some date attributes */
    
      public void deserialize(SerializationStreamReader stream, Object instance,    String typeSignature) throws SerializationException {
            // TODO Auto-generated method stub
            
        }
    
        public String getSerializationSignature(Class<?> clazz) {
            // TODO Auto-generated method stub
            return null;
        }
    
        public Object instantiate(SerializationStreamReader stream, String typeSignature) throws SerializationException {
            // TODO Auto-generated method stub
            return null;
        }
    
        public void serialize(SerializationStreamWriter stream, Object instance, String typeSignature) throws SerializationException {
            // TODO Auto-generated method stub
        }
    }
    And doing my date modifications in the "instantiate" and "serialize" methods ?

    (btw, thanks again for your reactivty )

  8. #8
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    No, just but the class you gave in the previous post higher in the classpath than the original one. This is not linked to GWT or GXT.

  9. #9
    Sencha User
    Join Date
    Apr 2009
    Location
    France
    Posts
    50
    Vote Rating
    0
    G.edwin is on a distinguished road

      0  

    Default


    Ok but i don't see where I can overload it, and how ?
    I have not a call of the Date_CustomFieldSerializer (i guess it's done through gwt.rpc), so i can't find where i could overload that.

    PS : I tried to replace the file Date_CustomFieldSerializer of the gwt-user.jar with my own but without success

  10. #10
    Sencha User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    867
    Vote Rating
    1
    micgala is on a distinguished road

      0  

    Default


    One way to this would be.

    In the project that you need this, simply create a new package named:
    com.google.gwt.user.client.rpc.core.java.util

    And then put your custom Date_CustomFieldSerializer.java in that package.

    As Sven pointed out, this is not related to gwt/gxt, but to Java itself.

    If you use Eclipse, make sure your src folder has more priority than your jar dependencies (it is NORMALLY the case).

    Regards,
    Michel.

Similar Threads

  1. Date columns change based on client GMT
    By Twain in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 12 Nov 2011, 1:57 PM
  2. Date with incorrect timezone
    By Tim Siney in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 18 Jan 2011, 7:56 AM
  3. client side Validation for Date
    By Alka_5m1980 in forum Community Discussion
    Replies: 0
    Last Post: 31 Mar 2009, 3:26 AM
  4. Change the client's timezone
    By keypoint in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 21 Sep 2008, 1:18 AM

Thread Participants: 7

Tags for this Thread