Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DateChooser not prompting with the correct selected dates

    Hi,

    I'm trying to launch the DateChooser of a DateItem with an autoselected date from the resepctive DateItem. The date being selected on the popup DateChooser is always one day less than than DateItem. I extended the DateChooser class and added a DrawHandler where I put :

    Code:
    Date data = getData();  
    Date date = formatter.parse(dateItem.getValue().toString());    
    GWT.log("DateChooser data : " + data.toString());    
    GWT.log("DateItem date : " + date.toString());    
    setData(date);    
    redraw();
    Output from this is:

    Code:
    INFO: DateChooser data : Mon Nov 28 12:00:00 EST 2016
    INFO: DateItem date : Mon Sep 19 00:00:00 EDT 2016
    As you can see the launcher is displaying the 18th instead of the 19th:







    #2
    Sorry, this isn't really enough to work with. Your logs actually show totally different dates (Sep 19 vs Nov 28), not an off-by-one issue, and that problem is likely to do with the "formatter" object (which you haven't explained) not being able to parse date.toString() (which is not typical user input).

    As far as the date ended up off by a day, calling setData() after changing the date value yourself (as your code may do) is probably what's going wrong, as there's no off-by-one issue in the Showcase. What may be going wrong is that you are using the browser's toString(), which for a field of type "date" would show spurious precision ("date" values are represented a time of noon, as an internal detail), then your parser naively parses that noon value and gets the timezone wrong. For more background on the kinds of common errors that come up when working with date, time and datetime values, see the Date Format and Storage overview.

    Comment


      #3
      Sorry, let me provide some more details. The formatter is just a simple

      com.google.gwt.i18n.shared.DateTimeFormat

      The two date objects are just being used to show how I believe the DateChooser works. I believe under the hood the DateChooser defaults to what is selected in the DateItem (confirmed in the showcase). If there is no date in the date item, or it cannot parse what is there, it defaults to Today's date (also confirmed in the showcase).

      I am pre-populating the DateItem with a given date ( Mon Sep 19th ) . The Nov 28th date is what is defaulted in the DateChooser as Today's date (accessed via the getData() call) .

      And as you can see, the formatter correctly parses the input date (Sep 19th) into a date object. But after a setData() call on the DateChooser with this date object, the DateChooser displays Sunday the 18th instead ( in the screenshot). The same happens for the EndDate DateItem (23rd transforms to 22nd).

      What I'm lacking in the showcase is the ability to test this functionality across different timezones & different date formats.





      Comment


        #4
        Again, see the Date Format and Storage overview, focusing on the concept of a logical date and how those are represented, and related APIs. Your approach of just parsing the browser's Date.toString() is invalid and would lead to these kinds of one-day shifts, because of the underlying representation (noon) previously discussed.

        Comment

        Working...
        X