mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
revert: "refactor: remove date-fns package (#9634)"
This reverts commit 1fcd9f38
This commit is contained in:
parent
99bef49128
commit
54f4f8986a
11763
package-lock.json
generated
11763
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -220,6 +220,7 @@
|
||||
"buffer": "^6.0.3",
|
||||
"chalk": "^4.1.2",
|
||||
"cli-highlight": "^2.1.11",
|
||||
"date-fns": "^2.29.3",
|
||||
"debug": "^4.3.4",
|
||||
"dotenv": "^16.0.3",
|
||||
"glob": "^8.1.0",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { ColumnMetadata } from "../metadata/ColumnMetadata"
|
||||
import { parseISO } from "date-fns"
|
||||
|
||||
/**
|
||||
* Provides utilities to transform hydrated and persisted data.
|
||||
@ -46,10 +47,22 @@ export class DateUtils {
|
||||
toUtc: boolean = false,
|
||||
useMilliseconds = true,
|
||||
): Date {
|
||||
/**
|
||||
* 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"
|
||||
? DateUtils.parseDateAsISO(mixedDate)
|
||||
: mixedDate
|
||||
typeof mixedDate === "string" ? parseISO(mixedDate) : mixedDate
|
||||
|
||||
if (toUtc)
|
||||
date = new Date(
|
||||
@ -266,23 +279,4 @@ export class DateUtils {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a date without the UTC-offset of the device
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
private static parseDateAsISO(dateString: string): Date {
|
||||
const date = new Date(dateString)
|
||||
const offset = date.getTimezoneOffset() * 60 * 1000
|
||||
const utc = date.getTime() + offset
|
||||
|
||||
return new Date(utc)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user