-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Format created of transaction with date time value if the created date is the current date #34784
Conversation
…e is the current date
@cubuspl42 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
src/libs/actions/IOU.js
Outdated
@@ -870,6 +870,8 @@ function createDistanceRequest(report, participant, comment, created, category, | |||
// If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function | |||
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); | |||
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report; | |||
const currentTime = DateUtils.getDBTime(); | |||
const currentCreated = created === format(new Date(currentTime), CONST.DATE.FNS_FORMAT_STRING) ? currentTime : created; |
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.
Isn't this equivalent to isSameDay?
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.
Yes it's what we want to do.
src/libs/actions/IOU.js
Outdated
@@ -870,6 +870,8 @@ function createDistanceRequest(report, participant, comment, created, category, | |||
// If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function | |||
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); | |||
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report; | |||
const currentTime = DateUtils.getDBTime(); |
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.
Please extract this logic to a function like...
/**
* Conditionally add the time-of-day information to the request creation timestamp
*/
fun enrichMoneyRequestTimestamp(created) {
// ...
return currentCreated;
}
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.
@cubuspl42 I created a util for this.
src/libs/DateUtils.ts
Outdated
*/ | ||
function enrichMoneyRequestTimestamp(created: string) { | ||
const currentTime = getDBTime(); | ||
return isSameDay(new Date(created), new Date(currentTime)) ? currentTime : created; |
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.
Please test if it works when dropping the new Date(...)
wrapping call
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.
IsSameDay only apply type number and Date.
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.
Oh, it does on 2.x
indeed. I started a thread.
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.
There's some active discussion, but it won't be actionable for this PR. We're good here.
src/libs/DateUtils.ts
Outdated
* Return the date with full format if the created date is the current date. | ||
* Otherwise return the created date. | ||
*/ | ||
function enrichMoneyRequestTimestamp(created: string) { |
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.
Please state the return type explicitly
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.
@cubuspl42 I updated the return type.
Reviewer Checklist
Screenshots/VideosAndroid: Nativecreated-timestamp-android-compressed.mp4Android: mWeb ChromeiOS: Nativecreated-timestamp-ios-compressed.mp4iOS: mWeb SafariMacOS: Chrome / Safaricreated-timestamp-web-converted.mp4MacOS: Desktop |
@deetergp This is definitely a problem! 😬 Was our testing approach incorrect? Sorry if it's a trivial question, but why are you analyzing the response, not the request? |
I just re-tested again and the created is still correct in both request and response. Correct me if I missed somethings Screen.Recording.2024-01-23.at.16.39.16.mov |
src/libs/DateUtils.ts
Outdated
const currentTime = getDBTime(); | ||
return isSameDay(new Date(created), new Date(currentTime)) ? currentTime : created; |
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.
I think we might have some timezone issues here...
getDBTime
returns a time in UTC+0, but it is cleared of the timezone information... I don't think we should use its output at all for any time calculations.
I think what happens here is a round-trip of date conversions: local -> UTC -> local, or something like that...
We should do something like this if I'm not mistaken.
const now = new Date();
return isSameDate(new Date(created), now) ? getDBTimeFromDate(now) : created;
getDBTimeFromDate
is the second half of getDBTime
, extracted.
@dukenv0307 Please test the PR by faking the timezone and time so that locally, the date is different from that in UTC+0. |
@deetergp I'm UTC+1; I think @dukenv0307 is close. There's no such thing as distinguished This is a giant mess and that's why I voted to go with Yoda Time instead of |
@cubuspl42 I just tested and we're right. the problem is we compare two date with different timezone. Updated to fix this. |
src/libs/DateUtils.ts
Outdated
const currentTime = getDBTime(); | ||
return formatWithUTCTimeZone(created) === formatWithUTCTimeZone(currentTime) ? currentTime : created; |
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.
Sorry, I won't happily approve more smelly approaches to date operations. Let's stick with the best thing we got, using date-fns
as much as possible.
You'll have to convince me why that's not the good idea.
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.
@cubuspl42 We already have formatWithUTCTimeZone
function and this function use date-fns-tz
lib as well so I think it's good to use this function.
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.
getDBTime
creates a Date
, converts it to string, screws up the ISO format, then we pass it to formatWithUTCTimeZone
, which again parses the string to Date
, dumps it to string, and then we compare it.
It's a nightmare.
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.
Also, is this even correct? Aren't we ultimately forced to use the "DB time" format?
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.
So timezone we should use. the current user timezone or UTC timezone.
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.
To avoid the created
string invalid date we can use isValid
function of date-fns
as well
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.
Okey, let's try...
const now = new Date();
const createdDate = parse(created, CONST.DATE.FNS_FORMAT_STRING, now);
return isSameDate(createdDate, now) ? getDBTimeFromDate(now) : created;
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.
@cubuspl42 I tested and updated this.
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.
Time zones are the worst. Just to clarify, all datetimes that get saved to our back end should be stored as UTC strings in the YYYY-MM-DD HH:MM:SS
format. But the kicker is that when displaying them back to the user, we probably need to show it relative to their time zone.
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.
Timezones are the worst, true, but we're not helping ourselves by making very questionable decisions like passing dates around as strings, converting Date
s to string to Date
s to strings to Date
..., not using separate types for instants and dates and datetimes, etc., etc.
src/libs/DateUtils.ts
Outdated
@@ -730,6 +730,23 @@ function formatToSupportedTimezone(timezoneInput: Timezone): Timezone { | |||
}; | |||
} | |||
|
|||
/** | |||
* Returns the time in milliseconds of a date in the format expected by the database |
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.
Time in milliseconds?
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.
Updated comment.
src/libs/DateUtils.ts
Outdated
/** | ||
* Returns the time in milliseconds of a date in the format expected by the database | ||
*/ | ||
function getDBTimeFromDate(date: Date): string { |
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.
Well, please use it inside getDBTime
now
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.
Updated to use getDBTimeFromDate
in getDBTime
.
src/libs/DateUtils.ts
Outdated
@@ -360,12 +360,19 @@ function getMicroseconds(): number { | |||
return Date.now() * CONST.MICROSECONDS_PER_MS; | |||
} | |||
|
|||
/** | |||
* Returns the format yyyy-MM-dd HH:mm:ss of a date in the format expected by the database |
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.
Okey, let's nuke this comment (as it's a helper function related to getDBTime
) and update the original comment so it makes sense.
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.
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.
I didn't realize that you aren't the author of the phrase I commented earlier
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.
Sound good, updated the comment.
src/libs/DateUtils.ts
Outdated
function getDBTimeFromDate(date: Date): string { | ||
return date.toISOString().replace('T', ' ').replace('Z', ''); | ||
} | ||
|
||
/** | ||
* Returns the current time in milliseconds in the format expected by the database |
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.
/**
* Convert the given timestamp to the "yyyy-MM-dd HH:mm:ss" format, as expected by the database
*
* @param [timestamp] the given timestamp (if omitted, defaults to the current time)
*/
I tested this with timezone spoofing and I believe the logic is timezone-proof now! @deetergp Would you confirm it fixed the problem for you? |
@cubuspl42 Yep, it fixed the issue for me! The money request I made created a transaction in the data base with UTC timestamp of when I created it, in the expected format. |
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.
Looks good and tests well, thanks for the changes.
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Cherry-picked to staging by https://github.com/francoisl in version: 1.4.33-5 🚀
@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes. |
🚀 Deployed to staging by https://github.com/deetergp in version: 1.4.34-0 🚀
|
🚀 Deployed to staging by https://github.com/deetergp in version: 1.4.34-0 🚀
|
🚀 Deployed to production by https://github.com/francoisl in version: 1.4.34-1 🚀
|
Details
Fixed Issues
$ #33814
PROPOSAL: #33814 (comment)
Tests
YYYY-MM-DD HH:mm:ss
Offline tests
YYYY-MM-DD HH:mm:ss
QA Steps
YYYY-MM-DD HH:mm:ss
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
android-1.mov
Android: mWeb Chrome
Screen.Recording.2024-01-19.at.11.52.41.mov
iOS: Native
iOS: mWeb Safari
Screen.Recording.2024-01-19.at.11.50.58.mov
MacOS: Chrome / Safari
Screen.Recording.2024-01-19.at.11.43.38.mov
MacOS: Desktop
Screen.Recording.2024-01-19.at.12.07.23.mov