typeorm 0.3.13-dev.4fa14e3 → 0.3.13-dev.98f2205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,16 +55,4 @@ export declare class DateUtils {
55
55
  * Formats given number to "0x" format, e.g. if it is 1 then it will return "01".
56
56
  */
57
57
  private static formatMilliseconds;
58
- /**
59
- * Parse a date without the UTC-offset of the device
60
- *
61
- * The problem here is with wrong timezone.
62
- *
63
- * For example:
64
- *
65
- * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
66
- * in my timezone, which is not true for my timezone (GMT-0300). It should
67
- * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
68
- */
69
- private static parseDateAsISO;
70
58
  }
@@ -1,3 +1,4 @@
1
+ import { parseISO } from "date-fns";
1
2
  /**
2
3
  * Provides utilities to transform hydrated and persisted data.
3
4
  */
@@ -32,9 +33,21 @@ export class DateUtils {
32
33
  * Converts given value into date object.
33
34
  */
34
35
  static mixedDateToDate(mixedDate, toUtc = false, useMilliseconds = true) {
35
- let date = typeof mixedDate === "string"
36
- ? DateUtils.parseDateAsISO(mixedDate)
37
- : mixedDate;
36
+ /**
37
+ * new Date(ISOString) is not a reliable parser to date strings.
38
+ * It's better to use 'date-fns' parser to parser string in ISO Format.
39
+ *
40
+ * The problem here is with wrong timezone.
41
+ *
42
+ * For example:
43
+ *
44
+ * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
45
+ * in my timezone, which is not true for my timezone (GMT-0300). It should
46
+ * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
47
+ *
48
+ * https://stackoverflow.com/a/2587398
49
+ */
50
+ let date = typeof mixedDate === "string" ? parseISO(mixedDate) : mixedDate;
38
51
  if (toUtc)
39
52
  date = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
40
53
  if (!useMilliseconds)
@@ -204,23 +217,6 @@ export class DateUtils {
204
217
  return String(value);
205
218
  }
206
219
  }
207
- /**
208
- * Parse a date without the UTC-offset of the device
209
- *
210
- * The problem here is with wrong timezone.
211
- *
212
- * For example:
213
- *
214
- * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
215
- * in my timezone, which is not true for my timezone (GMT-0300). It should
216
- * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
217
- */
218
- static parseDateAsISO(dateString) {
219
- const date = new Date(dateString);
220
- const offset = date.getTimezoneOffset() * 60 * 1000;
221
- const utc = date.getTime() + offset;
222
- return new Date(utc);
223
- }
224
220
  }
225
221
 
226
222
  //# sourceMappingURL=DateUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/util/DateUtils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,OAAO,CACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAChD,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAC9C,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAC5C,CAAA;SACJ;QAED,OAAO,KAA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Utils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n let date =\n typeof mixedDate === \"string\"\n ? DateUtils.parseDateAsISO(mixedDate)\n : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n\n /**\n * Parse a date without the UTC-offset of the device\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n */\n private static parseDateAsISO(dateString: string): Date {\n const date = new Date(dateString)\n const offset = date.getTimezoneOffset() * 60 * 1000\n const utc = date.getTime() + offset\n\n return new Date(utc)\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/util/DateUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,OAAO,CACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAChD,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAC9C,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAC5C,CAAA;SACJ;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAClB,SAAwB,EACxB,QAAiB,KAAK,EACtB,eAAe,GAAG,IAAI;QAEtB;;;;;;;;;;;;;WAaG;QACH,IAAI,IAAI,GACJ,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAEnE,IAA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C,KAAK,CAAC,CAAA;SAC1B;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,4EAA4E;IAC5E,yBAAyB;IACzB,4EAA4E;IAE5E;;OAEG;IACK,MAAM,CAAC,mBAAmB,CAAC,KAAa,EAAE,WAAW,GAAG,CAAC;QAC7D,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QAEnC,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;CACJ","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { parseISO } from \"date-fns\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\" ? parseISO(mixedDate) : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot":".."}
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "typeorm", "private": false, "version": "0.3.13-dev.4fa14e3", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">= 12.9.0" }, "exports": { ".": { "types": "./index.d.ts", "node": { "import": "./index.mjs", "require": "./index.js", "types": "./index.d.ts" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": { "types": "./index.d.ts", "default": "./browser/index.js" }, "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "homepage": "https://typeorm.io", "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "spanner", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm", "cloud-spanner", "cloud-spanner-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.3.4", "@types/chai-as-promised": "^7.1.5", "@types/debug": "^4.1.7", "@types/js-yaml": "^4.0.5", "@types/mkdirp": "^1.0.2", "@types/mocha": "^10.0.1", "@types/node": "^18.13.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^10.0.13", "@types/source-map-support": "^0.5.6", "@types/uuid": "^9.0.0", "@types/xml2js": "^0.4.11", "@types/yargs": "^17.0.22", "better-sqlite3": "^8.1.0", "chai": "^4.3.7", "chai-as-promised": "^7.1.1", "class-transformer": "^0.5.1", "conventional-changelog-angular": "^5.0.13", "conventional-changelog-cli": "^2.2.2", "del": "6.1.1", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.1.4", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^8.0.3", "mocha": "^10.2.0", "mongodb": "^3.7.3", "mssql": "^9.1.1", "mysql": "^2.18.1", "mysql2": "^3.1.1", "pg": "^8.9.0", "pg-query-stream": "^4.3.0", "prettier": "^2.8.3", "redis": "^4.6.4", "remap-istanbul": "^0.13.0", "rimraf": "^4.1.2", "sinon": "^15.0.1", "sinon-chai": "^3.7.0", "source-map-support": "^0.5.21", "sql.js": "^1.8.0", "sqlite3": "^5.1.4", "ts-node": "^10.9.1", "typeorm-aurora-data-api-driver": "^2.4.4", "typescript": "^4.9.5" }, "peerDependencies": { "@google-cloud/spanner": "^5.18.0", "@sap/hana-client": "^2.12.25", "better-sqlite3": "^7.1.2 || ^8.0.0", "hdb-pool": "^0.1.6", "ioredis": "^5.0.4", "mongodb": "^3.6.0", "mssql": "^9.1.1", "mysql2": "^2.2.5 || ^3.0.1", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1 || ^4.0.0", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@google-cloud/spanner": { "optional": true }, "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.5", "app-root-path": "^3.1.0", "buffer": "^6.0.3", "chalk": "^4.1.2", "cli-highlight": "^2.1.11", "debug": "^4.3.4", "dotenv": "^16.0.3", "glob": "^8.1.0", "js-yaml": "^4.1.0", "mkdirp": "^2.1.3", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.5.0", "uuid": "^9.0.0", "xml2js": "^0.4.23", "yargs": "^17.6.2" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
1
+ { "name": "typeorm", "private": false, "version": "0.3.13-dev.98f2205", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">= 12.9.0" }, "exports": { ".": { "types": "./index.d.ts", "node": { "import": "./index.mjs", "require": "./index.js", "types": "./index.d.ts" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": { "types": "./index.d.ts", "default": "./browser/index.js" }, "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "homepage": "https://typeorm.io", "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "spanner", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm", "cloud-spanner", "cloud-spanner-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.3.4", "@types/chai-as-promised": "^7.1.5", "@types/debug": "^4.1.7", "@types/js-yaml": "^4.0.5", "@types/mkdirp": "^1.0.2", "@types/mocha": "^10.0.1", "@types/node": "^18.13.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^10.0.13", "@types/source-map-support": "^0.5.6", "@types/uuid": "^9.0.0", "@types/xml2js": "^0.4.11", "@types/yargs": "^17.0.22", "better-sqlite3": "^8.1.0", "chai": "^4.3.7", "chai-as-promised": "^7.1.1", "class-transformer": "^0.5.1", "conventional-changelog-angular": "^5.0.13", "conventional-changelog-cli": "^2.2.2", "del": "6.1.1", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.1.4", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^8.0.3", "mocha": "^10.2.0", "mongodb": "^3.7.3", "mssql": "^9.1.1", "mysql": "^2.18.1", "mysql2": "^3.1.1", "pg": "^8.9.0", "pg-query-stream": "^4.3.0", "prettier": "^2.8.3", "redis": "^4.6.4", "remap-istanbul": "^0.13.0", "rimraf": "^4.1.2", "sinon": "^15.0.1", "sinon-chai": "^3.7.0", "source-map-support": "^0.5.21", "sql.js": "^1.8.0", "sqlite3": "^5.1.4", "ts-node": "^10.9.1", "typeorm-aurora-data-api-driver": "^2.4.4", "typescript": "^4.9.5" }, "peerDependencies": { "@google-cloud/spanner": "^5.18.0", "@sap/hana-client": "^2.12.25", "better-sqlite3": "^7.1.2 || ^8.0.0", "hdb-pool": "^0.1.6", "ioredis": "^5.0.4", "mongodb": "^3.6.0", "mssql": "^7.3.0", "mysql2": "^2.2.5 || ^3.0.1", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1 || ^4.0.0", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@google-cloud/spanner": { "optional": true }, "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.5", "app-root-path": "^3.1.0", "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", "js-yaml": "^4.1.0", "mkdirp": "^2.1.3", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.5.0", "uuid": "^9.0.0", "xml2js": "^0.4.23", "yargs": "^17.6.2" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
@@ -55,16 +55,4 @@ export declare class DateUtils {
55
55
  * Formats given number to "0x" format, e.g. if it is 1 then it will return "01".
56
56
  */
57
57
  private static formatMilliseconds;
58
- /**
59
- * Parse a date without the UTC-offset of the device
60
- *
61
- * The problem here is with wrong timezone.
62
- *
63
- * For example:
64
- *
65
- * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
66
- * in my timezone, which is not true for my timezone (GMT-0300). It should
67
- * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
68
- */
69
- private static parseDateAsISO;
70
58
  }
package/util/DateUtils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DateUtils = void 0;
4
+ const date_fns_1 = require("date-fns");
4
5
  /**
5
6
  * Provides utilities to transform hydrated and persisted data.
6
7
  */
@@ -35,9 +36,21 @@ class DateUtils {
35
36
  * Converts given value into date object.
36
37
  */
37
38
  static mixedDateToDate(mixedDate, toUtc = false, useMilliseconds = true) {
38
- let date = typeof mixedDate === "string"
39
- ? DateUtils.parseDateAsISO(mixedDate)
40
- : mixedDate;
39
+ /**
40
+ * new Date(ISOString) is not a reliable parser to date strings.
41
+ * It's better to use 'date-fns' parser to parser string in ISO Format.
42
+ *
43
+ * The problem here is with wrong timezone.
44
+ *
45
+ * For example:
46
+ *
47
+ * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
48
+ * in my timezone, which is not true for my timezone (GMT-0300). It should
49
+ * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
50
+ *
51
+ * https://stackoverflow.com/a/2587398
52
+ */
53
+ let date = typeof mixedDate === "string" ? (0, date_fns_1.parseISO)(mixedDate) : mixedDate;
41
54
  if (toUtc)
42
55
  date = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
43
56
  if (!useMilliseconds)
@@ -207,23 +220,6 @@ class DateUtils {
207
220
  return String(value);
208
221
  }
209
222
  }
210
- /**
211
- * Parse a date without the UTC-offset of the device
212
- *
213
- * The problem here is with wrong timezone.
214
- *
215
- * For example:
216
- *
217
- * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`
218
- * in my timezone, which is not true for my timezone (GMT-0300). It should
219
- * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.
220
- */
221
- static parseDateAsISO(dateString) {
222
- const date = new Date(dateString);
223
- const offset = date.getTimezoneOffset() * 60 * 1000;
224
- const utc = date.getTime() + offset;
225
- return new Date(utc);
226
- }
227
223
  }
228
224
  exports.DateUtils = DateUtils;
229
225
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/DateUtils.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,OAAO,CACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAChD,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAC9C,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAC5C,CAAA;SACJ;QAED,OAAO,KAAK,CAAA;IAChB,C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Utils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n let date =\n typeof mixedDate === \"string\"\n ? DateUtils.parseDateAsISO(mixedDate)\n : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n\n /**\n * Parse a date without the UTC-offset of the device\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n */\n private static parseDateAsISO(dateString: string): Date {\n const date = new Date(dateString)\n const offset = date.getTimezoneOffset() * 60 * 1000\n const utc = date.getTime() + offset\n\n return new Date(utc)\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/util/DateUtils.ts"],"names":[],"mappings":";;;AACA,uCAAmC;AAEnC;;GAEG;AACH,MAAa,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,OAAO,CACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAChD,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAC9C,GAAG;gBACH,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAC5C,CAAA;SACJ;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAClB,SAAwB,EACxB,QAAiB,KAAK,EACtB,eAAe,GAAG,IAAI;QAEtB;;;;;;;;;;;;;WAaG;QACH,IAAI,IAAI,GACJ,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,mBAAQ,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAEnE,IAAI,KAAK;YACL,IAAI,GAAG,IAAI,IA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AAO,KAAK,CAAA;IAChB,CAAC;IAED,4EAA4E;IAC5E,yBAAyB;IACzB,4EAA4E;IAE5E;;OAEG;IACK,MAAM,CAAC,mBAAmB,CAAC,KAAa,EAAE,WAAW,GAAG,CAAC;QAC7D,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QAEnC,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;CACJ;AAnRD,8BAmRC","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { parseISO } from \"date-fns\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\" ? parseISO(mixedDate) : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot":".."}