Skip to content

Commit

Permalink
manually ported changes from #7796
Browse files Browse the repository at this point in the history
  • Loading branch information
pleerock committed Feb 16, 2022
1 parent 942fee3 commit 7e625b8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
34 changes: 29 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"sqlite3": "^5.0.2",
"ts-node": "^9.1.1",
"typeorm-aurora-data-api-driver": "^2.0.0",
"date-fns": "2.22.1",
"typescript": "^4.2.2"
},
"peerDependencies": {
Expand Down
17 changes: 16 additions & 1 deletion src/util/DateUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ColumnMetadata } from "../metadata/ColumnMetadata";
import { parseISO } from "date-fns";

/**
* Provides utilities to transform hydrated and persisted data.
Expand Down Expand Up @@ -33,7 +34,21 @@ export class DateUtils {
* Converts given value into date object.
*/
static mixedDateToDate(mixedDate: Date|string, toUtc: boolean = false, useMilliseconds = true): Date {
let date = typeof mixedDate === "string" ? new Date(mixedDate) : mixedDate;
/**
* new Date(ISOString) is not a reliable parser to date strings.
* It's better to use 'date-fns' parser to parser string in ISO Format.
*
* The problem here is with wrong timezone.
*
* For example:
*
* ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
* in my timezone, which is not true for my timezone (GMT-0300). It should
* be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
*
* https://stackoverflow.com/a/2587398
*/
let date = typeof mixedDate === "string" ? parseISO(mixedDate) : mixedDate;

if (toUtc)
date = new Date(
Expand Down

0 comments on commit 7e625b8

Please sign in to comment.