From bf3ef48dc06a49de3fd01f041233ee94178d54be Mon Sep 17 00:00:00 2001 From: busma13 Date: Tue, 1 Oct 2024 14:55:08 -0700 Subject: [PATCH 1/3] update date-fns and date-fns-tz --- packages/data-mate/package.json | 2 +- .../src/transforms/field-transform.ts | 2 +- .../data-mate/test/column/column-date-spec.ts | 2 +- .../matcher/cases/document-matcher/dates.ts | 2 +- packages/utils/package.json | 4 ++-- packages/utils/src/dates.ts | 4 +--- packages/utils/test/data-entity-spec.ts | 2 +- .../test/cases/range-date-math.ts | 4 ++-- packages/xlucene-parser/test/cases/term.ts | 4 ++-- yarn.lock | 20 +++++++++---------- 10 files changed, 21 insertions(+), 25 deletions(-) diff --git a/packages/data-mate/package.json b/packages/data-mate/package.json index 26219bec0ef..9bbc4a16f36 100644 --- a/packages/data-mate/package.json +++ b/packages/data-mate/package.json @@ -35,7 +35,7 @@ "@terascope/utils": "^1.2.0", "@types/validator": "^13.12.2", "awesome-phonenumber": "^7.1.0", - "date-fns": "^2.30.0", + "date-fns": "^4.1.0", "ip-bigint": "^8.2.0", "ip6addr": "^0.2.5", "ipaddr.js": "^2.2.0", diff --git a/packages/data-mate/src/transforms/field-transform.ts b/packages/data-mate/src/transforms/field-transform.ts index e2e85f92afd..ec0d226ec15 100644 --- a/packages/data-mate/src/transforms/field-transform.ts +++ b/packages/data-mate/src/transforms/field-transform.ts @@ -1379,7 +1379,7 @@ function _parseDate(input: any, args: ParseDateConfig) { throw new Error(`Invalid parameter format, must be a string, received ${ts.getTypeOf(input)}`); } - const parsed = parse(input, format, new Date()); + const parsed = parse(ts.isNumber(input) ? input.toString() : input, format, new Date()); if (!ts.isValidDateInstance(parsed)) { throw new Error('Cannot parse date'); diff --git a/packages/data-mate/test/column/column-date-spec.ts b/packages/data-mate/test/column/column-date-spec.ts index b6ee1a9b656..790903634c4 100644 --- a/packages/data-mate/test/column/column-date-spec.ts +++ b/packages/data-mate/test/column/column-date-spec.ts @@ -1,7 +1,7 @@ import 'jest-extended'; import { getValidDate, timezoneOffset } from '@terascope/utils'; import { DateFormat, FieldType, Maybe } from '@terascope/types'; -import formatDate from 'date-fns/format'; +import { formatDate } from 'date-fns/format'; import { Column, dataFrameAdapter, functionConfigRepository, Vector } from '../../src/index.js'; diff --git a/packages/data-mate/test/matcher/cases/document-matcher/dates.ts b/packages/data-mate/test/matcher/cases/document-matcher/dates.ts index bfa235a336e..2c2c2df0252 100644 --- a/packages/data-mate/test/matcher/cases/document-matcher/dates.ts +++ b/packages/data-mate/test/matcher/cases/document-matcher/dates.ts @@ -1,4 +1,4 @@ -import addDays from 'date-fns/addDays'; +import { addDays } from 'date-fns/addDays'; import { xLuceneFieldType } from '@terascope/types'; import { TestCase } from './interfaces.js'; diff --git a/packages/utils/package.json b/packages/utils/package.json index d9b1740674c..13491970761 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -45,8 +45,8 @@ "@types/lodash-es": "^4.17.12", "@types/validator": "^13.12.2", "awesome-phonenumber": "^7.1.0", - "date-fns": "^2.30.0", - "date-fns-tz": "^1.3.7", + "date-fns": "^4.1.0", + "date-fns-tz": "^3.2.0", "datemath-parser": "^1.0.6", "debug": "^4.3.7", "geo-tz": "^8.1.1", diff --git a/packages/utils/src/dates.ts b/packages/utils/src/dates.ts index d92ef21a259..f012932a7a3 100644 --- a/packages/utils/src/dates.ts +++ b/packages/utils/src/dates.ts @@ -37,7 +37,7 @@ import { DateFormat, ISO8601DateSegment, DateTuple, DateInputTypes, GetTimeBetweenArgs } from '@terascope/types'; -import dateTimezonePkg from 'date-fns-tz'; +import { getTimezoneOffset as tzOffset } from 'date-fns-tz'; import { getTypeOf } from './deps.js'; import { bigIntToJSON, isNumber, toInteger, @@ -47,8 +47,6 @@ import { isString } from './strings.js'; import { isBoolean } from './booleans.js'; import { lookupTimezone } from './geo.js'; -const { getTimezoneOffset: tzOffset } = dateTimezonePkg; - // date-fns doesn't handle utc correctly here // https://github.com/date-fns/date-fns/issues/376 // https://github.com/date-fns/date-fns/blob/d0efa9eae1cf05c0e27461296b537b9dd46283d4/src/format/index.js#L399-L403 diff --git a/packages/utils/test/data-entity-spec.ts b/packages/utils/test/data-entity-spec.ts index c84ffc91add..4eeb041bad2 100644 --- a/packages/utils/test/data-entity-spec.ts +++ b/packages/utils/test/data-entity-spec.ts @@ -1,5 +1,5 @@ import 'jest-extended'; -import addDays from 'date-fns/addDays'; +import { addDays } from 'date-fns/addDays'; import { DataEntity, DataEncoding, __IS_DATAENTITY_KEY, __ENTITY_METADATA_KEY, DataEntityMetadata, diff --git a/packages/xlucene-parser/test/cases/range-date-math.ts b/packages/xlucene-parser/test/cases/range-date-math.ts index 742c38f95c6..e9d88e832ba 100644 --- a/packages/xlucene-parser/test/cases/range-date-math.ts +++ b/packages/xlucene-parser/test/cases/range-date-math.ts @@ -1,6 +1,6 @@ import { xLuceneFieldType } from '@terascope/types'; -import subDays from 'date-fns/subDays'; -import addDays from 'date-fns/addDays'; +import { subDays } from 'date-fns/subDays'; +import { addDays } from 'date-fns/addDays'; import { NodeType, Node } from '../../src'; import { TestCase } from './interfaces.js'; diff --git a/packages/xlucene-parser/test/cases/term.ts b/packages/xlucene-parser/test/cases/term.ts index 4313994e041..7990b09d6c2 100644 --- a/packages/xlucene-parser/test/cases/term.ts +++ b/packages/xlucene-parser/test/cases/term.ts @@ -1,5 +1,5 @@ -import subDays from 'date-fns/subDays'; -import addDays from 'date-fns/addDays'; +import { subDays } from 'date-fns/subDays'; +import { addDays } from 'date-fns/addDays'; import { xLuceneFieldType } from '@terascope/types'; import { escapeString } from '@terascope/utils'; import { NodeType, Term } from '../../src/index.js'; diff --git a/yarn.lock b/yarn.lock index 1791ae18cdc..37716deb528 100644 --- a/yarn.lock +++ b/yarn.lock @@ -844,7 +844,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.24.8" -"@babel/runtime@^7.10.2", "@babel/runtime@^7.16.3", "@babel/runtime@^7.21.0", "@babel/runtime@^7.8.4": +"@babel/runtime@^7.10.2", "@babel/runtime@^7.16.3", "@babel/runtime@^7.8.4": version "7.25.6" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.6.tgz#9afc3289f7184d8d7f98b099884c26317b9264d2" integrity sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ== @@ -5005,17 +5005,15 @@ data-view-byte-offset@^1.0.0: es-errors "^1.3.0" is-data-view "^1.0.1" -date-fns-tz@^1.3.7: - version "1.3.8" - resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-1.3.8.tgz#083e3a4e1f19b7857fa0c18deea6c2bc46ded7b9" - integrity sha512-qwNXUFtMHTTU6CFSFjoJ80W8Fzzp24LntbjFFBgL/faqds4e5mo9mftoRLgr3Vi1trISsg4awSpYVsOQCRnapQ== +date-fns-tz@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-3.2.0.tgz#647dc56d38ac33a3e37b65e9d5c4cda5af5e58e6" + integrity sha512-sg8HqoTEulcbbbVXeg84u5UnlsQa8GS5QXMqjjYIhS4abEVVKIUwe0/l/UhrZdKaL/W5eWZNlbTeEIiOXTcsBQ== -date-fns@^2.30.0: - version "2.30.0" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0" - integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw== - dependencies: - "@babel/runtime" "^7.21.0" +date-fns@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-4.1.0.tgz#64b3d83fff5aa80438f5b1a633c2e83b8a1c2d14" + integrity sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg== dateformat@^4.5.0: version "4.6.3" From b6989b03a5782555658c614bff2598534cbd2541 Mon Sep 17 00:00:00 2001 From: busma13 Date: Wed, 2 Oct 2024 09:56:08 -0700 Subject: [PATCH 2/3] ternary not needed. pull logic out of fn parameter --- packages/data-mate/src/transforms/field-transform.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/data-mate/src/transforms/field-transform.ts b/packages/data-mate/src/transforms/field-transform.ts index ec0d226ec15..0012c2e1fea 100644 --- a/packages/data-mate/src/transforms/field-transform.ts +++ b/packages/data-mate/src/transforms/field-transform.ts @@ -1379,7 +1379,9 @@ function _parseDate(input: any, args: ParseDateConfig) { throw new Error(`Invalid parameter format, must be a string, received ${ts.getTypeOf(input)}`); } - const parsed = parse(ts.isNumber(input) ? input.toString() : input, format, new Date()); + const inputStr = input.toString(); + + const parsed = parse(inputStr, format, new Date()); if (!ts.isValidDateInstance(parsed)) { throw new Error('Cannot parse date'); From 6b00efbec8c65a4c8b869847c934917956ace32c Mon Sep 17 00:00:00 2001 From: busma13 Date: Wed, 2 Oct 2024 10:43:53 -0700 Subject: [PATCH 3/3] use String() instead of toString() --- packages/data-mate/src/transforms/field-transform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-mate/src/transforms/field-transform.ts b/packages/data-mate/src/transforms/field-transform.ts index 0012c2e1fea..32a6f9d8646 100644 --- a/packages/data-mate/src/transforms/field-transform.ts +++ b/packages/data-mate/src/transforms/field-transform.ts @@ -1379,7 +1379,7 @@ function _parseDate(input: any, args: ParseDateConfig) { throw new Error(`Invalid parameter format, must be a string, received ${ts.getTypeOf(input)}`); } - const inputStr = input.toString(); + const inputStr = String(input); const parsed = parse(inputStr, format, new Date());