-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix: inaccurate purchaseTime #279
Conversation
WalkthroughThe changes in the Changes
Security Recommendations
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🔇 Additional comments (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
if (item.value.purchasePrice) { | ||
purchasePrice = item.value.purchasePrice; | ||
} | ||
if (item.value.soldPrice) { | ||
soldPrice = item.value.soldPrice; | ||
} | ||
if (item.value.purchaseTime) { | ||
purchaseTime = new Date(item.value.purchaseTime.getTime() - item.value.purchaseTime.getTimezoneOffset() * 60000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is a minute being tacked on at the end of this math?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gettime returns number of milliseconds whereas gettimezoneoffset returns number of minutes, so multiplying the timezone offset by 60000 converts it to milliseconds
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK this makes more sense now, but also... What in the hell where the people who designed and implemented JavaScript drinking when they put this crap together? Both of those functions come from the same type for crying out loud!
What type of PR is this?
(REQUIRED)
What this PR does / why we need it:
(REQUIRED)
The
purchaseTime
value from theFormDatePicker
returns aDate
object when the form is submitted. This object only contains the date without any time details (hours, minutes, or seconds). For example, in GMT+8, it displays as "Fri Oct 11 2024 00:00:00 GMT+0800 (Malaysia Time)".However, when this date is sent to the update API, the payload is converted to a string using
JSON.stringify
, theDate
object is automatically converted to UTC (GMT+0). This causes the original date to shift, resulting in "2024-10-10T16:00:00.000Z" (which reflects an 8-hour difference due to the timezone offset)This PR resolves the issue by applying the appropriate timezone offset to the
purchaseTime
before passing it toJSON.stringify
, ensuring the correct date and time are retained.Which issue(s) this PR fixes:
(REQUIRED)
Fixes bug #125
Summary by CodeRabbit