Closed pandeysubash404 closed 1 year ago
Can you create a PR for this?
Duplicate of #53
Could you please include the pnpm-lock (without pnpm as dependency) and remove the package-lock, sorry for the confusion.
Hi @Parajulibkrm ,
I have made the requested changes to the repository as per your instructions.
I have also installed pnpm globally using npm, so the project can now be installed and run with pnpm.
Please review the changes and let me know if everything looks good. If you have any further instructions or suggestions, please feel free to let me know.
Thank you for your guidance, and I look forward to your feedback.
Best regards, Subash Pandey
Fixed by #57
53
Problem Description: When using the provided input field, the displayed date appears to be one day behind the actual date. However, the date displayed in the paragraph below the input field shows the correct date. This inconsistency can be confusing for users, leading to potential misunderstandings or incorrect data inputs.
Cause of the Issue: The issue is caused by the difference in how the date is handled between the input field and the paragraph. The input field utilizes the
toISOString()
method to convert the date to an ISO string, which represents the date and time in Coordinated Universal Time (UTC). The string is then split to extract only the date portion. Conversely, the paragraph utilizes thetoLocaleString()
method, which considers the local time zone of the user's browser.Due to this discrepancy, when the input field displays the date in UTC and the user is in a time zone with a positive offset from UTC, such as UTC+01:00, the date appears to be one day behind the user's local date.
Proposed Solution: To address this issue and ensure consistent date representation across different time zones, I suggest the following solution:
value={new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().split("T")[0]}
date.getTimezoneOffset()
retrieves the offset in minutes between the user's local time zone and UTC.date.getTime() - date.getTimezoneOffset() * 60000
calculates the adjusted time in milliseconds, taking into account the user's time zone offset.new Date(...).toISOString().split("T")[0]
converts the adjusted time to an ISO string and extracts the date portion.By implementing this solution, the input field will display the correct date according to the user's local time zone, aligning it with the date displayed in the paragraph.
Screenshots Here are some of the screenshots that might be useful to understand the problem : Date Converter screen :
I hope this report helps you in resolving the date display discrepancy. If you have any further questions or require additional assistance, please feel free to reach out. Thank you for your attention to this matter.