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
Datetime stored incorrectly in postgresql #2220
Comments
Some discussion on this in node-postgres as well: brianc/node-postgres#783 |
Why is your server in different timezones? You shall use UTC in any server you have to avoid issues. Try to set |
@jwclark I think you are constructing a column type without timezone, thus you don't get your timestamps stored in UTC. From the postgres docs (https://www.postgresql.org/docs/9.6/static/datatype-datetime.html):
So in order to overcome this, try to change the data type like this:
|
I had the same problem (also postgres) and I fixed it with the following attribute for all date columns:
Have a look at these supported column types by TypeORM: Update: |
While I would not deploy a production workload to a non-UTC server, it seems a bit fragile to me if changing the timezone of the server can cause these types of bugs. As @chriskalmar and @filipjnc suggest, I've switched to 'timestamp with time zone' column type. Perhaps that should be the default for Date columns? |
dates and timezones is a fragile system itself. Dates are always complex and you simply need to know how to handle each case and you'll understand why it works this way.
no, they have different purposes. You use what you need in specific situations. |
Hey folks, just wanted to chime in. I think the "put your server in UTC" solution is fine (and the server should already be running in UTC), but this causes all sorts of problems during local development. If you have postgres and node running on your machine and the timezone of both is the SAME, you can safely use |
Issue type:
[x ] bug report
Database system/driver:
[ x]
postgres
TypeORM version:
[ ]
0.2.6
(or put your version here)Steps to reproduce or a small repository showing the problem:
The entity and test call below result in a timestamp in server time(rather than UTC) and without timezone information. This behavior exists as of pull request #1717 as far as I can tell.
@entity()
export class DateTest {
@PrimaryGeneratedColumn("uuid")
public id?: string;
@column()
public date?: Date;
}
testRepository.save({date: new Date()});
A potentially dangerous result of this bug is that two different servers in different timezones, but accessing the same database, could read the same entry and construct different timestamps(not just differences in timezone).
The comment here by @chriskalmar is not the actual behavior for postgres. As shown in the example above, new Date() is not stored as UTC.
The text was updated successfully, but these errors were encountered: