From 89441ecfaef94f763abab5dab20efe19c41c4011 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Tue, 19 Nov 2024 16:42:02 +0100 Subject: [PATCH] Update to dateformat 5.0.3 Version 4 contains significant performance improvements, and version 5 changes the import format, but reduces the bundle size, so update to that verison. This upgrade uncovered some type errors in DiffTool.tsx, so I converted the JulianDates to JavaScript Dates when they are known to be defined values. --- .../Ows/WebMapServiceCapabilitiesStratum.ts | 3 +-- .../BottomDock/Timeline/DateTimePicker.tsx | 2 +- lib/ReactViews/Tools/DiffTool/DatePicker.tsx | 2 +- lib/ReactViews/Tools/DiffTool/DiffTool.tsx | 19 +++++++++++++------ package.json | 5 ++--- yarn.lock | 16 ++++++++-------- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts b/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts index 3c9069a2e65..71caa684d69 100644 --- a/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts +++ b/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts @@ -44,8 +44,7 @@ import WebMapServiceCapabilities, { getRectangleFromLayer } from "./WebMapServiceCapabilities"; import WebMapServiceCatalogItem from "./WebMapServiceCatalogItem"; - -const dateFormat = require("dateformat"); +import dateFormat from "dateformat"; /** Transforms WMS GetCapabilities XML into WebMapServiceCatalogItemTraits */ export default class WebMapServiceCapabilitiesStratum extends LoadableStratum( diff --git a/lib/ReactViews/BottomDock/Timeline/DateTimePicker.tsx b/lib/ReactViews/BottomDock/Timeline/DateTimePicker.tsx index 870151b3984..42752c32d30 100644 --- a/lib/ReactViews/BottomDock/Timeline/DateTimePicker.tsx +++ b/lib/ReactViews/BottomDock/Timeline/DateTimePicker.tsx @@ -21,8 +21,8 @@ import { scrollBars } from "../../../Styled/mixins"; import Spacing from "../../../Styled/Spacing"; import Icon from "../../../Styled/Icon"; import { formatDateTime } from "./DateFormats"; +import dateFormat from "dateformat"; -const dateFormat = require("dateformat"); const DatePicker = require("react-datepicker").default; function daysInMonth(month: number, year: number) { diff --git a/lib/ReactViews/Tools/DiffTool/DatePicker.tsx b/lib/ReactViews/Tools/DiffTool/DatePicker.tsx index af5934d106b..1cc46a6ee76 100644 --- a/lib/ReactViews/Tools/DiffTool/DatePicker.tsx +++ b/lib/ReactViews/Tools/DiffTool/DatePicker.tsx @@ -13,7 +13,7 @@ import Text, { TextSpan } from "../../../Styled/Text"; import Box from "../../../Styled/Box"; import Button from "../../../Styled/Button"; import Spacing from "../../../Styled/Spacing"; -const dateFormat = require("dateformat"); +import dateFormat from "dateformat"; interface PropsType extends WithTranslation { heading: string; diff --git a/lib/ReactViews/Tools/DiffTool/DiffTool.tsx b/lib/ReactViews/Tools/DiffTool/DiffTool.tsx index cddffb0d93e..79c9e6e0ca4 100644 --- a/lib/ReactViews/Tools/DiffTool/DiffTool.tsx +++ b/lib/ReactViews/Tools/DiffTool/DiffTool.tsx @@ -53,8 +53,7 @@ import DatePicker from "./DatePicker"; import LocationPicker from "./LocationPicker"; import { CLOSE_TOOL_ID } from "../../Map/MapNavigation/registerMapNavigations"; import updateModelFromJson from "../../../Models/Definition/updateModelFromJson"; - -const dateFormat = require("dateformat"); +import dateFormat from "dateformat"; type DiffableItem = DiffableMixin.Instance; @@ -250,8 +249,8 @@ class Main extends React.Component { if (!firstDate || !secondDate) { return name; } else { - const d1 = dateFormat(firstDate, format); - const d2 = dateFormat(secondDate, format); + const d1 = dateFormat(JulianDate.toDate(firstDate), format); + const d2 = dateFormat(JulianDate.toDate(secondDate), format); return `${name} - difference for dates ${d1}, ${d2}`; } } @@ -567,7 +566,11 @@ class Main extends React.Component { {this.leftDate && ( - (A) {dateFormat(this.leftDate, "dd/mm/yyyy")} + (A){" "} + {dateFormat( + JulianDate.toDate(this.leftDate), + "dd/mm/yyyy" + )} )} {!this.leftDate && ( @@ -580,7 +583,11 @@ class Main extends React.Component { {this.rightDate && ( - (B) {dateFormat(this.rightDate, "dd/mm/yyyy")} + (B){" "} + {dateFormat( + JulianDate.toDate(this.rightDate), + "dd/mm/yyyy" + )} )} {!this.rightDate && ( diff --git a/package.json b/package.json index c1faa4d53f9..f9a68458a42 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@types/d3-scale-chromatic": "^3.0.3", "@types/d3-selection": "^3.0.10", "@types/d3-transition": "^3.0.8", - "@types/dateformat": "^3.0.1", + "@types/dateformat": "^5.0.1", "@types/dompurify": "^2.3.1", "@types/file-saver": "^1.3.0", "@types/flexsearch": "^0.7.1", @@ -109,7 +109,7 @@ "d3-shape": "^3.2.0", "d3-transition": "^3.0.1", "d3-zoom": "^3.0.0", - "dateformat": "^3.0.3", + "dateformat": "^5.0.3", "dompurify": "^2.3.3", "fetch-mock": "^9.11.0", "file-loader": "^3.0.1", @@ -193,7 +193,6 @@ "devDependencies": { "@babel/eslint-parser": "^7.23.3", "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "@types/dateformat": "^3.0.1", "@types/node": "^18.15.11", "@types/webpack": "4.41.33", "@typescript-eslint/eslint-plugin": "^6.12.0", diff --git a/yarn.lock b/yarn.lock index 5fad2b89736..3f5f440aefc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1863,10 +1863,10 @@ dependencies: "@types/d3-selection" "*" -"@types/dateformat@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@types/dateformat/-/dateformat-3.0.1.tgz#98d747a2e5e9a56070c6bf14e27bff56204e34cc" - integrity sha512-KlPPdikagvL6ELjWsljbyDIPzNCeliYkqRpI+zea99vBBbCIA5JNshZAwQKTON139c87y9qvTFVgkFd14rtS4g== +"@types/dateformat@^5.0.1": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@types/dateformat/-/dateformat-5.0.2.tgz#876f06431ce6f411dbaca3f81d95a8784c9ab82a" + integrity sha512-M95hNBMa/hnwErH+a+VOD/sYgTmo15OTYTM2Hr52/e0OdOuY+Crag+kd3/ioZrhg0WGbl9Sm3hR7UU+MH6rfOw== "@types/dompurify@^2.3.1": version "2.3.3" @@ -4795,10 +4795,10 @@ date-format@^4.0.14: resolved "https://registry.yarnpkg.com/date-format/-/date-format-4.0.14.tgz#7a8e584434fb169a521c8b7aa481f355810d9400" integrity sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg== -dateformat@^3.0.3: - version "3.0.3" - resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae" - integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q== +dateformat@^5.0.3: + version "5.0.3" + resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-5.0.3.tgz#fe2223eff3cc70ce716931cb3038b59a9280696e" + integrity sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA== debounce@^1.2.1: version "1.2.1"