Tapestry 5
  1. Tapestry 5
  2. TAP5-1575

DateField is not multi-timezone safe

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Duplicate
    • Affects Version/s: 5.1.0.5
    • Fix Version/s: None
    • Component/s: tapestry-core

      Description

      If the client is in a different timezone to the server, selecting a date will set the wrong value in the input field in most cases.

      The cause is the use of 'milliseconds since epoch'.

      The following demonstrates part of the problem:

      TimeZone serverTz = TimeZone.getTimeZone("GMT+1000");
      TimeZone clientTz = TimeZone.getTimeZone("GMT-1500");

      // simulates client to server communication method used by DateField
      TimeZone.setDefault(serverTz);
      SimpleDateFormat serverDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

      SimpleDateFormat clientDf = (SimpleDateFormat) serverDf.clone();
      clientDf.setTimeZone(clientTz);

      String dateSelection = "2011-07-01 00:00:00";
      Date clientDate = clientDf.parse(dateSelection);

      Date serverDate = new Date(clientDate.getTime());
      System.out.println("2011-07-01 00:00:00 = " + serverDf.format(serverDate) + "?");

      So if a user selected July 7 2011, the field would display July 2 2011 if the timezones were as above.

      My solution was to remove the usage of both the java and javascript `Date.getTime` and `new Date(time)` functions. Instead, I serialise to "yyyy-MM-dd" and format/parse this on the server using the same tz as the format parameter.

        Activity

        Hide
        Paul Stanton added a comment -

        dup of TAP5-841

        Show
        Paul Stanton added a comment - dup of TAP5-841
        Hide
        Bob Harner added a comment -

        This issue looks like a duplicate of TAP5-841

        Show
        Bob Harner added a comment - This issue looks like a duplicate of TAP5-841

          People

          • Assignee:
            Unassigned
            Reporter:
            Paul Stanton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development