question-mark
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.

Question about the `date` type

See original GitHub issue

The Postgres date data type has no information about timezone. That wouldn’t make any sense. However, the dateParser in node-postgres defaults to Greenwich timezone due to the way it’s instantiating the object.

According to this MDN article, when creating a new Date, the constructor uses the Date.parse which, if passed a string without a timezone, will default to the systems timezone. This is not the behavior I’m seeing in the node.

Consider the following on my system in GMT-0600

new Date('2014-01-24').getDate() // => 23
new Date('2014-01-24 00:00:00').getDate() // => 24
new Date( 2014, 0, 24 ).getDate() // => 24

It’s my feeling that when the data type is date then we should use one of the latter two methods so that it actually defaults to system timezone. The first method is being employed by node-postgres right now:

https://github.com/brianc/node-postgres/blob/master/lib/types/textParsers.js#L17

Thoughts?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
jrf0110commented, Jan 23, 2014

Right. Not a PG problem but a node-pg problem. My fix:

pg.types.setTypeParser( 1082, 'text', function( val ){
  return new Date( val + ' 00:00:00' );
});
0reactions
polobocommented, Sep 21, 2014

This issue appears to be resolved and able to be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date Question Type - SurveySparrow Help Center
The date question type allows you to preset the date format in your surveys. With this feature, all your respondents will be made...
Read more >
Date Question Type | Alchemer Help
A Date question is a short-answer, open-text field with validation that ensures entries are dates. You can choose to validate MM/DD/YYYY ...
Read more >
Date question - Help Center - Typeform
Need to ask for date of birth, add an appointment scheduler, or test your respondents' knowledge about historical days? You can do all...
Read more >
Question type - Date - LimeSurvey Manual
This question type can be used to ask for a certain date, time or a combination of both date and time. The values...
Read more >
10 Perfect Questions to Ask On The First Date To Really Get ...
10 Perfect Questions to Ask On The First Date To Really Get To Know Someone · 1. “What Makes You Unique?” · 2....
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found