tediousjs / tedious

Node TDS module for connecting to SQL Server databases.

Home Page:http://tediousjs.github.io/tedious/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add experimental `Temporal` support

arthurschreiber opened this issue · comments

There's an upcoming EcmaScript specification that adds better date and time handling support to JavaScript.

The functionality in this specification would allow us to greatly improve the support different date and time related data types.

Here's a list of SQL Server data types and the corresponding types from the temporal spec that they should map to/from:

  • date -> Temporal.PlainDate
  • datetime -> Temporal.PlainDateTime
  • datetime2 -> Temporal.PlainDateTime
  • datetimeoffset -> Temporal.ZonedDateTime
  • smalldatetime -> Temporal.PlainDateTime
  • time -> Temporal.PlainTime

With the experimental feature turned on, we shouldn't support Date objects at all anymore - their handling is awkward and error prone.

There's two polyfills available that we could use to implement this:

Polyfill Repo Status
@js-temporal/polyfill js-temporal/temporal-polyfill Alpha release available
temporal-polyfill fullcalendar/temporal Alpha release available

If the experimental temporal support is not enabled, we could still use temporal objects internally (instead of js-joda) and just return Date objects instead.

Here's some information on how to convert Temporal objects back into Date objects: https://tc39.es/proposal-temporal/docs/cookbook.html#temporal-types--legacy-date