Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unpredictable movements of the dates in the date picker included in the table widget; are decreased by 1 day. #25081

Closed
1 task done
felix-appsmith opened this issue Jul 4, 2023 · 22 comments
Assignees
Labels
Bug Something isn't working Community Reported issues reported by community members Date Picker Widget Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Table Inline Edit Issues related to inline editing Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets

Comments

@felix-appsmith
Copy link

felix-appsmith commented Jul 4, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Description

Currently, in a table widget, if we try to add a new row and one of the fields is a date picker, it will decrease the selected date by one day. For example, if I select 2023-07-09, it will select 2023-07-08. The strange thing about this bug is that it only occurs in a European time zone; it doesn't happen in another time zone.

Steps To Reproduce

I tried to replicate the issue unsuccessfully. However, the user shared the application where the problem can be seen. Make sure you are in a European time zone.

For more context and videos, you can see the conversation with the user: https://app.frontapp.com/open/cnv_11b2uw5o?key=6Ow9FD3H6U0PYcJY6lBMKc7w2XqkaAaq

Public Sample App

https://app.appsmith.com/app/bug-date-simple/page1-64a7d393af033d5dcc48b2e6

Environment

Production

Issue video log

https://www.loom.com/share/405cc2a2c6aa416ea7245721dc33dc76?sid=398a0130-dc0e-4bea-8be4-44fc7b0c83e8

Version

Cloud: Appsmith v1.9.25-SNAPSHOT

@felix-appsmith felix-appsmith added Bug Something isn't working Needs Triaging Needs attention from maintainers to triage labels Jul 4, 2023
@felix-appsmith felix-appsmith added Date Picker Widget Table Widget V2 Issues related to Table Widget V2 labels Jul 4, 2023
@github-actions github-actions bot added the Widgets Product This label groups issues related to widgets label Jul 4, 2023
@somangshu somangshu changed the title [Bug]: Bugs the dates in the date picker included in the table widget are decreased by 1 day. [Bug]: Unpredictable movements of the dates in the date picker included in the table widget are decreased by 1 day. Jul 5, 2023
@somangshu somangshu changed the title [Bug]: Unpredictable movements of the dates in the date picker included in the table widget are decreased by 1 day. [Bug]: Unpredictable movements of the dates in the date picker included in the table widget; are decreased by 1 day. Jul 5, 2023
@somangshu somangshu added the Community Reported issues reported by community members label Jul 5, 2023
@somangshu
Copy link
Contributor

My understanding here is that the timezone that is stored in the DB and selected on client side are different.
Usually this kinda issue happens when the timezone stated in the date object is different from the one you are in. This will show unpredictable results with default date objects. This is specially visible because the user is only viewing dd-mm-yy. If we can see the full date before and after, it will be easier for us to help them out.

Screenshot 2023-07-05 at 2 41 31 PM

@benjamindonze
Copy link

This is not unpredictable this is always happening when:

  • you have a table widget with a date column with format YYYY-MM-DD
  • you add a new row
  • you are in european time zone

The problem here is that I set my date widget to use format date format (and display format) YYYY-MM-DD. Apparently when updating the row I can see by printing with in logs that "currentRow" does correctly hold a date in the format YYYY-MM-DD that match the one you select in the widget.

But when adding a row the value hold by "newRow" is in format 2023-07-19T22:00:00.000Z. So probably if you select 2023-07-20 in that widget it actually select 2023-07-20T00:00 in my local time zone and then transform it to UTC time zone. While it should work only with date (with no time)

Well anyway the problem happens in the widget as I can see this happens before the query to the DB. Moreover the issue only happen with new row, row update seems to work.

@benjamindonze
Copy link

Looking at the code for DateCell widget I can see that when selecting the date while updating a date, the date is formated with
const formattedDate = date ? moment(date).format(inputFormat) : "";
But this is not done when it is a new row.

Thus this probably lead to keeping the date with time when beeing in newRow mode and so applying some timezoning but correctly handinling the updates.

See below the whole code block:

const onDateSelected = (date: string) => {
    if (isNewRow) {
      updateNewRowValues(alias, date, date);
      return;
    }

    if (isRequired && !date) {
      setIsValid(false);
      setShowRequiredError(true);
      return;
    }
    setIsValid(true);
    setShowRequiredError(false);
    setHasFocus(false);

    const formattedDate = date ? moment(date).format(inputFormat) : "";
    onDateSave(rowIndex, alias, formattedDate, onDateSelectedString);
  };

@amareshvarma
Copy link

Is there a way I can contribute to this, any steps to reproduce

@imatpro
Copy link

imatpro commented Jul 11, 2023

Hello, i have a same problem. when I select date in datepicker (without time precision) the datepicker.selectedDate is at J-1

Capture d’écran 2023-07-11 à 10 13 29 Capture d’écran 2023-07-11 à 10 13 55

Thanks for helping

@benjamindonze
Copy link

Is there a way I can contribute to this, any steps to reproduce

Well check the 1st post it includes a link to a sample app that shows the issue.

@somangshu
Copy link
Contributor

Thanks for the detailed analysis @benjamindonze. This will help us debug and triage the issue better.
We will take this up internally and prioritise it.

@amareshvarma LMK if you are interested in contributing. This issue might be involved, so my suggestion is to start with other good first issues

cc @keyurparalkar

@amareshvarma
Copy link

@benjamindonze
image
It says 404 error either it is not there or I do not have access

@benjamindonze
Copy link

I have invited support@appsmith.com and made that app public so you should now have access otherwise I don't know how I can give you access

@somangshu
Copy link
Contributor

@amareshvarma the app might not be accessible to you. You will have to repro this on your own end.

@dilippitchika
Copy link
Contributor

Hello can you please use - {{moment.utc(DatePicker1.formattedDate)}} instead of using {{Datepicker1.selectedDate}} for now?

@somangshu you are right, this confusion is coming quite often because selectedDate is taking the user's selection and internally using the locale to convert to UTC time.

Our options are

  1. Add a new property in the datepicker which is a toggle to remove selectedDate UTC formatting
  2. Add a new reference property called {{Datepicker1.localDate}} which will just give the selected date without any utc logic applied to it.

Please suggest if there are other options.

@benjamindonze
Copy link

@amareshvarma the app might not be accessible to you. You will have to repro this on your own end.

I can also add you to the app if you want

@PaulMcF1987
Copy link

@somangshu @keyurparalkar @dilippitchika

I have been faced with this issue and was pointed here form the discord support channel

I think I have since found a solution although it is early days

I was finding that, no matter what I tried, when using moment that the utc time was always applied, adding 1hour onto the time.
The issue only occurred with the Date/Time input, when viewing in a text widget, the date/time was able to be formatted correctly

I have since added the https://cdn.jsdelivr.net/npm/date-and-time@3.0.2/date-and-time.min.js library and am using {{date.parse(appsmith.store.group.datetime, 'YYYY-MM-DD HH:mm:ss [GMT]' )}}

This seems to have sorted the issue but time will tell

@benjamindonze
Copy link

Any news on fixing this issue?

@Nikhil-Nandagopal
Copy link
Contributor

@benjamindonze we haven't picked this up yet and this could be an issue with moment. Try using the solution that Paul has mentioned above and let us know if it works!

@Nikhil-Nandagopal Nikhil-Nandagopal added the Medium Issues that frustrate users due to poor UX label Jan 23, 2024
@lrytz
Copy link

lrytz commented May 14, 2024

To reproduce in a JS function (I assume it's the same underlying issue):

image

@Harshithazemoso
Copy link

Harshithazemoso commented May 21, 2024

I have picked up the issue and I have tried changing the timezone to europe and connected to datasource but I couldnt reproduce the issue ,are there any steps how to reproduce this or is it resolved ?

@benjamindonze
Copy link

benjamindonze commented May 22, 2024

Have you tried the public sample app link in the first post : https://app.appsmith.com/app/bug-date-simple/page1-64a7d393af033d5dcc48b2e6

It is very easy to see that the problem is still there. If you simply click "Add new row" and the select a date the save. Then you can see on the left pane "Changed row" that the date is not correct.
For exemple I select date "2024-05-22" and I see after saving in Changed row : {
"date": "2024-05-21T22:00:00.000Z"
}

You can also clearly see behavior is different when you change an existing row

@Harshithazemoso
Copy link

Thanks for the response @benjamindonze ,will look into that

@Nikhil-Nandagopal Nikhil-Nandagopal added the Table Inline Edit Issues related to inline editing label May 29, 2024
Harshithazemoso pushed a commit to Harshithazemoso/appsmith that referenced this issue May 31, 2024
@Harshithazemoso
Copy link

hello @benjamindonze I have raised a pr for this issue,can you please look into it

@benjamindonze
Copy link

I did put a comment and approved the PR

@Nikhil-Nandagopal Nikhil-Nandagopal added the Widgets & Accelerators Pod Issues related to widgets & Accelerators label Aug 6, 2024
jacquesikot added a commit that referenced this issue Sep 30, 2024
…ix Timestamp (ms) (#36455)

## Description

**Problem**
When populating a table widget with data that includes dates in Unix
timestamp (milliseconds) format, setting the column type to "Date," the
input format to "Unix timestamp (ms)," and selecting a display format
leads to an issue during inline editing. While the date picker behaves
correctly, selecting a new date results in the table cell showing an
"Invalid Date" error.

**Root Cause**
The platform currently uses DateInputFormat.MILLISECONDS for Unix
timestamp (ms) formatting. However, this value is not a valid option for
the moment.format() function, which expects the input format to be 'x'
for Unix timestamps in milliseconds. This mismatch leads to the "Invalid
Date" error.

**Solution**
Modify the logic to map DateInputFormat.MILLISECONDS to the correct
moment format string 'x'.
Adjust the table's transformDataPureFn to correctly process and display
dates in Unix timestamp (ms) format after inline edits, ensuring the
moment library can handle the input properly.

**Outcome**
This fix ensures that when a user selects a date via the date picker in
inline editing mode, the selected date is displayed correctly in the
table without any errors.


Fixes #35631, #25081

## Automation

/ok-to-test tags="@tag.Sanity, @tag.Binding, @tag.Table,
@tag.Datepicker"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11101758400>
> Commit: 6a3cae7
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11101758400&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity, @tag.Binding, @tag.Table, @tag.Datepicker`
> Spec:
> <hr>Mon, 30 Sep 2024 08:54:58 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Enhanced date column editing in table widgets to accept Unix
timestamps in milliseconds without errors.
	- Introduced a new enumeration for improved date formatting options.
- Added mock data structures for testing various date formats and
transformations in the table widget.
- New method for generating formatted date strings for tomorrow in both
verbose and ISO formats.

- **Bug Fixes**
- Improved validation logic for date inputs in the table, ensuring
proper handling of different date formats.

- **Tests**
- Added new test cases to validate date handling and input formats in
the table widget.
- Introduced a new test suite for transforming table data based on
specified column metadata.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@rahulbarwal
Copy link
Contributor

This is fixed with: #36455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members Date Picker Widget Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Table Inline Edit Issues related to inline editing Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging a pull request may close this issue.