-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Convert saved non-UTC dates to UTC #10967
Conversation
🦋 Changeset detectedLatest commit: ae2e831 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
LGTM!
packages/db/src/runtime/index.ts
Outdated
if(!isISODateString(value)) { | ||
// values saved using CURRENT_TIMESTAMP are not valid ISO strings | ||
// but *are* in UTC, so append the UTC zone. | ||
value += '.000Z'; |
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.
Did a quick tests and += 'Z'
is actually all it takes — the milliseconds are irrelevant fwiw.
packages/db/src/runtime/index.ts
Outdated
const d = new Date(str); | ||
return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === str; // valid 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.
Do we even need to be this cautious? What are the chances something that matches the ISO pattern is invalid if we’re adding it to the DB?
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.
Not sure, is there a downside to doing this though (I just grabbed from stackoverflow)
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.
If it's copied code we now own, I'd just leave a comment to the source
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.
is there a downside to doing this though
I guess only extra work for each Date parsed? If you fetched a lot of data, you’re now constructing the Date
twice for each one. I don’t really mind leaving it in though.
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.
Removed extra bits, it's just the regex 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.
That was UTeasy
packages/db/src/runtime/index.ts
Outdated
const d = new Date(str); | ||
return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === str; // valid 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.
If it's copied code we now own, I'd just leave a comment to the source
Changes
astro:db
: TimeStamps stored usingNOW
(in UTC) are being translated to their Local Time value making the JavaScript value of theDate
object inaccurate #10964NOW
helper saves dates as theCURRENT_TIMESTAMP
, a UTC date that is unfortunately formated as2024-05-07 17:53:37
(no timezone).Testing
Docs
N/A, bug fix