drizzle-team / drizzle-team/drizzle-orm

Support for string based timestamp field using ISO formatting

Open
#1,757 10 comments 49 reactions 1 assignee Claimed by @AndriiSherman View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

Right now we are able to insert or update our records using an ISO formatted UTC string (ie `'2024-01-04T12:54:11Z'`). However, when we select that date back out of the database, it's returning it in the format that our database (PG) is storing it (ie `'2024-01-04 12:54:11'`). This causes problems when using this return value with `new Date()` since the time zone will be inferred from the server or client. Additionally, this also means we have to parse the string and reformat it before serializing the value when sending it over HTTP.

Ideally, we would like to be able to work with timestamps as string, but always have these strings ISO formatted.

To workaround this, we are currently using our own custom type that is a combination of both the `date` and `string` versions to achieve the result we would like.

The main piece of making this work is.
```ts
override mapFromDriverValue = (value: string): string => {
const date = new Date(this.withTimezone ? value : value + '+0000');

return date.toISOString();
};
```

Would it be considerable to support an ISO string timpstamp in drizzle?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.