nextcloud / nextcloud/server

Handling `datetime` upper/lower range differences across different databases

Open
#46,208 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage feature: caldav feature: database technical debt
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Something I came across while looking into another matter so documenting here for later.

The datetime type (via doctrine-dbal) has different year ranges depending on the database in-use.

This may be problematic in a few spots[^1] and thus we may want to consider setting a reasonable upper/lower bound range when saving dates in the database so that we never end up with dates we can never save back/etc.

Here are the ranges each db says they support:

(ignoring time and day since the point is more about the year part)

db Low High
MariaDB[^2] 1000 CE 9999 CE
PostgreSQL[^3] 4713 BCE (!) 294276 CE (!)
SQLite[^4] 4714 BCE ?
Oracle[^5] 4712 BCE 9999 CE
MySQL[^6] 1000 CE 9999 CE

I currently propose 1000 CE to 9999 CE since it's basically the only common range.

[^1]: Try setting a date to >9999 in Deck with a MariaDB/MySQL backend; I presume db conversion break too. Ironically, with a PostgreSQL backend we appear to detect >9999 as an invalid date, but I can't figure out where. Though we do enforce limits before it gets to the database in some places for other reasons (e.g. https://github.com/nextcloud/calendar/blob/427dc3aebc6b16d69269b26fce11ca353ace528f/src/store/davRestrictions.js#L12), but this isn't universal.
[^2]: https://mariadb.com/kb/en/datetime/
[^3]: https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-DATETIME
[^4]: Varies because it can use TEXT/REAL/INTEGER internally, but best documented is as stated
[^5]: https://docs.oracle.com/cd/B13789_01/server.101/b10759/sql_elements001.htm#SQLRF00200
[^6]: https://dev.mysql.com/doc/refman/8.4/en/datetime.html

Doctrine mapping matrix: https://www.doctrine-project.org/projects/doctrine-dbal/en/3.8/reference/types.html#mapping-matrix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Doctrine DBAL mapping matrix and the date-validation example in src/store/davRestrictions.js. Trace how dates are saved in Deck across the listed database backends, including where PostgreSQL rejects out-of-range values. Done means the project has an agreed common range and consistent validation before database conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
mariadb, mysql, php, postgresql, sqlite
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.