Repository navigation
NORM Dates
norm keeps every date and time in UTC, on every engine and on every host. A value written from a server in one time zone reads back as the same instant, the same day, and the same clock time from a server in another. This page is the map: each rule is stated once, in the section linked from here.
- Column types
- Values you write and filter by
- A day or a clock time in a named zone
- Defaults and date arithmetic
- The database session
- Temporal and audit periods
- Related documentation
| Builder | Holds | Postgres | MariaDB | SQLite | MongoDB |
|---|---|---|---|---|---|
date() |
A calendar day | DATE |
DATE |
TEXT |
date at UTC midnight |
time() |
A time of day | TIME |
TIME(6) |
TEXT |
string |
datetime() |
An instant | TIMESTAMP |
DATETIME(6) |
TEXT |
date |
timestamp() |
An instant | TIMESTAMP |
TIMESTAMP(6) |
TEXT |
date |
timestamptz() |
An instant | TIMESTAMPTZ |
TIMESTAMP(6) |
TEXT |
date |
Neon uses the Postgres types; Turso and D1 use the SQLite ones.
The three instant builders differ only in the native type. On Postgres
datetime() and timestamp() are the same type, and on MariaDB
timestamp() and timestamptz() are. Each holds the instant as a UTC
value and reads back as a Date.
Pick by range and by who else reads the table:
- MariaDB's
TIMESTAMPhas a limited range (it ends in 2038 on servers before 11.5), so usedatetime()for a far-future value. - On Postgres use
timestamptz()for a column that anything other than norm reads or writes.TIMESTAMPTZis the one type that means the same instant in every session time zone.
A Date is written as the instant it is. A date-time string that names
no offset is read as UTC, on a write, in a filter and as a literal
default, so a JSON payload means the same instant on every host. A
date() column keeps the UTC day of the value, and a time() column
keeps an 'HH:MM:SS' string.
- Writes: Schema → Factories.
- Filters: Querying → Date and time values.
"Today" in Kolkata and "today" in UTC are different days for part of
every day. zonedDay, zonedTimeOfDay, and zonedInstant turn a day
or a clock time in a named zone into the value a column stores; see
Schema → Dates in a time zone.
.default(() => new Date()) runs in the application and
{ $$_expression: 'NOW' } runs in the database. Both give the current
instant; Schema → Defaults covers the
MongoDB insert case.
DATE_ADD, DATE_DIFF, and DATE_TRUNC are oql expressions and count
days and months in UTC. oql states their rules:
DATE_DIFF units,
DATE_ADD month end,
and
temporal precision.
norm sends and reads UTC values, so the database session has to run in UTC as well.
| Engine | What happens |
|---|---|
| Postgres | The driver asks for TimeZone=UTC when it connects, so the session runs in UTC whatever zone the database or role is set to. |
| Postgres behind a pooler | A pooler may not pass that request on; the session then runs in the zone the server gives it. Nothing checks it. |
| Neon | HTTP has no startup message to ask in, so queries run in the database's own zone. Nothing checks it. |
| MariaDB | The driver sets each connection's time_zone to +00:00. There is nothing to configure. |
| SQLite, Turso, D1, MongoDB | There is no session time zone. |
Where the driver cannot ask, set the zone on the server. Set it on the
role when it has a timezone setting of its own, since that overrides
the database's. Behind a pooler, that is the role the pooler signs in
as, and the setting applies once the pooler opens a new server
connection:
ALTER ROLE app SET timezone TO 'UTC';
ALTER DATABASE app SET timezone TO 'UTC';To keep the database's own zone, pass the driver's
allowNonUtcTimeZone through database:
import { Norm } from '@tundralibs/norm';
const norm = new Norm({
database: {
dialect: 'postgres',
host: 'db.internal',
username: 'app',
password: 'app-password',
database: 'app',
allowNonUtcTimeZone: true,
},
});The driver then asks for no zone. With the database in
Asia/Kolkata, a row written with 2026-11-14T20:00:00Z in every
column reads back as:
| Column | Reads back |
|---|---|
date() |
2026-11-15, and a filter on the 14th misses it |
datetime(), timestamp()
|
2026-11-15T01:30:00Z |
timestamptz() |
2026-11-14T20:00:00Z |
Temporal and audit period columns are datetime() columns and shift
the same way. Set the option only for a schema whose instants are all
timestamptz(), with no date() column and no temporal or audit
table, or behind a pooler that rejects the TimeZone startup parameter
once the zone is set on the server, since nothing checks it then. The
drivers have the detail:
Postgres → Time zone
and Neon → Time zone.
EffectiveFrom and EffectiveTo are datetime() columns and follow
every rule above. The open-end marker has one rule of its own: give
sentinel an offset. See
Temporal → Options.
- Schema definition: the column builders and the zone helpers.
- Querying: filter values on date and time columns.
-
Temporal tables and Audit tables:
the period columns and
@AsOf. - Upgrade notes: what changed for rows and code written against an earlier version.