You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[looking for feedback] Reworking temporal DataTypes #14295
Temporal.{PlainMonthDay, PlainYearMonth, TimeZone, Calendar} don't have an associated JS nor DB DataType.
As indicated in #14213, we're not currently interested in supporting postgres's time tz type, as they themself recommend against using it.
Footnotes
For now, I trying to use ZonedDateTime with one of these types should emit an error explaining that no DB type matching ZonedDateTime is available yet, and that the user should
split it into two attributes: a plain datetime & a timezone, or store it as a string. ↩
Reacted by Blake Patton, crazyscience, functionx.dev, Mariusz Stępień and Vladyslav Huba
DateTypes.DATETIME: Always means "Date with timezone". Because it will work fine in most cases by default.
DataTypes.DATETIME.PLAIN: Always means "Date without timezone". It could only accepts Temporal.PlainDateTime.
Many developers arguing in other issues for demanding of date/time without timezone, because they didn't find out the best practice of usage of time.
In my opinion, when we want to use a date/time field in database, it should always be with timezone. And physically, time is always with timezone. The cases when people are not mentioning timezone, mostly they only consider the local time. But use time with timezone in these cases are also acceptable and no bad effects.
The base reason why should we use date/time type of fields in database, is Just because we need them to be calculated with other values (comparing, manipulating, etc.). If people only need time for literally expressing, the timezone will not be strictly necessary. In this case, just use plain time or even string will be ok. But if we use time for calculating, we need the exact value (with timezone).
Another thing is, always use UTC formatted in any transferring is the best practice. Also for storing to database. So in PG it works great by default. It will be the clients' stuff to transform stored time to local timezone in view. And by default Date in browser parsing an UTC time string works right.
Think about it, if we use time with timezone in a project, whether if it is a local one or global, it always work fine. But if use time without timezone, it only works for local projects.
But use time with timezone in these cases are also acceptable and no bad effects.
Super not true. When you have a table with 30 billion rows and 4 datetime columns in each row, the addition of useless data (in this case, timezone info) definitely has an impact. Maybe not noticeable when someone's building yet another todo app. But ORMs should be built for performance application and production loads, not hobbyists building a blog.
Additionally, timezone boundaries move constantly. Storing the timezone data in the database as if it's going to be accurate for any length of time is seriously misguided. Production applications should default to avoid timezones and use them when they are needed specifically.
You can always use UTC time to store into DB, the timezone will be calculated or not on Sequelize or client side. Unless you just need local time, and no need to convert, you just store local time. The size of each has no difference.
From another aspect, performance optimization should be the App developers' responsibility. As for framework/library developer, should just provide the options. You can also use the DataTypes.DATETIME.PLAIN for no conversion needed fields. It all by your own.
@mytharcher while I concede that the storage does indeed appear to be unaffected, I still would maintain that a framework has a lot of sway in how programming patterns are adopted and therefor still think that the default behavior should reflect best practices.
Per the postgres link you sent above, directly below the table of storage sizes, they have a remark that says that according to the SQL standards, datetime columns must not include timezone data unless explicitly stated. I still agree with the SQL standards on this one. Timezones in the database are a bit of a foot 🔫.
The reason I originally went for DataTypes.DATETIME (unzoned) + DataTypes.DATETIME.ZONED is that we currently have DataTypes.TIME (unzoned) & have a PR for DataTypes.TIME.ZONED.
I think mixing up which one is zoned by default and which one isn't would lead to confusion.
However, it makes sense for DataTypes.TIME to be unzoned by default, because, as the pg docs indicate, the usefulness of DataTypes.TIME.ZONED is questionable. That is not true for DataTypes.DATETIME.ZONED.
Whether we make zoned or unzoned the default is inevitably going to lead to people using it without thinking about whether they want it to be zoned or not. This is mitigated by the fact that we will only accept ZonedDateTime & PlainDateTime respectively, so they will eventually have to think about which type they really need, but maybe we should go the route of no default here.
DataTypes.DATETIME: error, please use DataTypes.DATETIME.ZONED, or DataTypes.DATETIME.PLAIN
DataTypes.DATETIME.PLAIN
DataTypes.DATETIME.ZONED
or just
DataTypes.ZONEDDATETIME
DataTypes.PLAINDATETIME (this uppercase convention makes this somewhat difficult to read)
Yeah, I don't think DataTypes.ZONEDDATETIME is a good solution. I think it should be fine to have no default and force people to specify DataTypes.DATETIME.ZONED.
Should DataTypes.DATETIME.OFFSET accept Date? While Date is not compatible with DataTypes.DATETIME.PLAIN, it works fine with DataTypes.DATETIME.OFFSET. I think we can support it without any issues
Activity
mytharcher commentedon Jun 17, 2022
My proposal for the naming:
DateTypes.DATETIME: Always means "Date with timezone". Because it will work fine in most cases by default.DataTypes.DATETIME.PLAIN: Always means "Date without timezone". It could only acceptsTemporal.PlainDateTime.Many developers arguing in other issues for demanding of date/time without timezone, because they didn't find out the best practice of usage of time.
In my opinion, when we want to use a date/time field in database, it should always be with timezone. And physically, time is always with timezone. The cases when people are not mentioning timezone, mostly they only consider the local time. But use time with timezone in these cases are also acceptable and no bad effects.
The base reason why should we use date/time type of fields in database, is Just because we need them to be calculated with other values (comparing, manipulating, etc.). If people only need time for literally expressing, the timezone will not be strictly necessary. In this case, just use plain time or even string will be ok. But if we use time for calculating, we need the exact value (with timezone).
Another thing is, always use UTC formatted in any transferring is the best practice. Also for storing to database. So in PG it works great by default. It will be the clients' stuff to transform stored time to local timezone in view. And by default
Datein browser parsing an UTC time string works right.Think about it, if we use time with timezone in a project, whether if it is a local one or global, it always work fine. But if use time without timezone, it only works for local projects.
crazyscience commentedon Aug 2, 2022
Super not true. When you have a table with 30 billion rows and 4 datetime columns in each row, the addition of useless data (in this case, timezone info) definitely has an impact. Maybe not noticeable when someone's building yet another todo app. But ORMs should be built for performance application and production loads, not hobbyists building a blog.
Additionally, timezone boundaries move constantly. Storing the timezone data in the database as if it's going to be accurate for any length of time is seriously misguided. Production applications should default to avoid timezones and use them when they are needed specifically.
https://www.youtube.com/watch?v=-5wpm-gesOY
crazyscience commentedon Aug 2, 2022
My proposal for the naming:
DateTypes.DATETIME: Always means "Date without timezone". Because it will work fine in most cases by default.DataTypes.DATETIME.IM_A_MASOCHIST: Always means "Date with timezone". 😄mytharcher commentedon Aug 3, 2022
@crazyscience
You may have a check on those DBs docs, whether the DATE type with timezone or without, it will not affect size of storing.
You can always use UTC time to store into DB, the timezone will be calculated or not on Sequelize or client side. Unless you just need local time, and no need to convert, you just store local time. The size of each has no difference.
From another aspect, performance optimization should be the App developers' responsibility. As for framework/library developer, should just provide the options. You can also use the
DataTypes.DATETIME.PLAINfor no conversion needed fields. It all by your own.crazyscience commentedon Aug 10, 2022
@mytharcher while I concede that the storage does indeed appear to be unaffected, I still would maintain that a framework has a lot of sway in how programming patterns are adopted and therefor still think that the default behavior should reflect best practices.
Per the postgres link you sent above, directly below the table of storage sizes, they have a remark that says that according to the SQL standards, datetime columns must not include timezone data unless explicitly stated. I still agree with the SQL standards on this one. Timezones in the database are a bit of a foot 🔫.
mytharcher commentedon Aug 24, 2022
@crazyscience
I think we could make clear some things below:
In these conditions,
DateTypes.DATETIMEwith timezone by default (defined in ORM) would be the easiest way for most user.ephys commentedon Sep 17, 2022
The reason I originally went for
DataTypes.DATETIME(unzoned) +DataTypes.DATETIME.ZONEDis that we currently haveDataTypes.TIME(unzoned) & have a PR forDataTypes.TIME.ZONED.I think mixing up which one is zoned by default and which one isn't would lead to confusion.
However, it makes sense for
DataTypes.TIMEto be unzoned by default, because, as the pg docs indicate, the usefulness ofDataTypes.TIME.ZONEDis questionable. That is not true forDataTypes.DATETIME.ZONED.Whether we make zoned or unzoned the default is inevitably going to lead to people using it without thinking about whether they want it to be zoned or not. This is mitigated by the fact that we will only accept
ZonedDateTime&PlainDateTimerespectively, so they will eventually have to think about which type they really need, but maybe we should go the route of no default here.DataTypes.DATETIME: error, please useDataTypes.DATETIME.ZONED, orDataTypes.DATETIME.PLAINDataTypes.DATETIME.PLAINDataTypes.DATETIME.ZONEDor just
DataTypes.ZONEDDATETIMEDataTypes.PLAINDATETIME(this uppercase convention makes this somewhat difficult to read)WikiRik commentedon Sep 18, 2022
Yeah, I don't think
DataTypes.ZONEDDATETIMEis a good solution. I think it should be fine to have no default and force people to specifyDataTypes.DATETIME.ZONED.ephys commentedon Sep 27, 2022
ephys commentedon Dec 22, 2022
Updated the proposal (in the original post) with the following changes:
DataTypes.TIME.OFFSET, see feat: time with timezone #14213I still have one pending question:
DataTypes.DATETIME.OFFSETacceptDate? WhileDateis not compatible withDataTypes.DATETIME.PLAIN, it works fine withDataTypes.DATETIME.OFFSET. I think we can support it without any issues[-][RFC] Consider deprecating & replacing `DataTypes.DATE`[/-][+]Reworking temporal DataTypes[/+][-]Reworking temporal DataTypes[/-][+][looking for feedback] Reworking temporal DataTypes[/+]ephys commentedon Jun 14, 2023
As mentioned in #4900, we can also map the
INTERVALdata type toTemporal.Duration