Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

formatDate() in data-api-client depends on system timezone

See original GitHub issue

I had a problem with inserting values with the timestamp mysql data type. Javascript Date object 2020-05-28T03:56:48.466Z was being transformed to "2020-05-28 05:56:48". (I am in UTC+2 timezone. Server uses UTC, however I encountered this issue during local development.)

Then I tried running the script with

$ TZ='UTC' node somescript.js

and 2020-05-28T03:56:48.466Z was correctly transformed to "2020-05-28 03:56:48".

I think the problem might be that aws-sdk does not communicate my system timezone to Aurora Data API and expects UTC.

Related source code:

const formatDate = (date) => {
    const padNumber = (number) => number <= 9 ? '0' + number : number

    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()

    const hour = date.getHours()
    const minutes = date.getMinutes()
    const seconds = date.getSeconds()

    return year + '-' + padNumber(month) + '-' + padNumber(day) + ' ' + padNumber(hour) + ':' + padNumber(minutes) + ':' + padNumber(seconds)

Expected: timestamp string sent to Data API should be in UTC and not be related to system timezone.

Suggested fix: use UTC variants of Date methods like Date.prototype.getUTCHours()

Thanks for this amazing library!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

ArsenyYankovskycommented, Jul 10, 2020

I’ll definitely check it out and let you know. I don’t immediately see any issues with it, but I’ll run some tests and if everything go well publish a new version.

filipsukcommented, Jul 14, 2020

Thank you so much @ArsenyYankovsky 👍. I will give it a try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support native JavaScript Date type · Issue #28 - GitHub
1 AWS services run in UTC time zone so in AWS the flag does nothing special. ... formatDate() in data-api-client depends on system...
Read more >
How to display dates in your user's time zone with the Intl API
Running Intl.DateTimeFormat().resolvedOptions() in a browser tells us everything the browser knows about the user's date and time preferences.
Read more >
Difference between timestamps with/without time zone in ...
The behaviour differs depending on at least three factors: The timezone setting in the client. The data type (i.e. WITH TIME ZONE or...
Read more >
Guide to time zone handling for REST APIs in Java - LinkedIn
I am trying to cover up the mostly theoretical (without code example) parts under this article and in the next one willing describe...
Read more >
Bootstrap 中文网开源项目免费 CDN 加速服务 - BootCDN
inferno-server. Provides methods to render HTML ... moment-timezone. Parse and display moments in any ... jquery-dateFormat. It's a jQuery Plugin to format ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found