]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Upgrade date-fns
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Fri, 19 Aug 2022 14:06:35 +0000 (16:06 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 23 Aug 2022 20:03:04 +0000 (20:03 +0000)
server/sonar-web/package.json
server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts
server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx
server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx
server/sonar-web/src/main/js/components/intl/DateFromNow.tsx
server/sonar-web/src/main/js/components/intl/dateUtils.ts
server/sonar-web/src/main/js/helpers/dates.ts
server/sonar-web/yarn.lock

index 3658e3197475a773198b3cbde9365443bf736c42..9122f528e8a2ba627dd99aa256ab565c22038507 100644 (file)
@@ -16,7 +16,7 @@
     "d3-selection": "1.4.1",
     "d3-shape": "1.3.7",
     "d3-zoom": "1.8.3",
-    "date-fns": "1.30.1",
+    "date-fns": "2.29.2",
     "dompurify": "2.3.10",
     "formik": "1.2.0",
     "lodash": "4.17.21",
index 191de3056ccd0350bcbd726f4e16a86ff0ac45dd..e718aaa7bdcfcdbe92e8dca8e3a9e58b899084bb 100644 (file)
@@ -19,6 +19,7 @@
  */
 import { differenceInMilliseconds, isAfter, isBefore } from 'date-fns';
 import { cloneDeep, groupBy, sortBy } from 'lodash';
+import { parseDate } from '../../helpers/dates';
 import { mockTask } from '../../helpers/mocks/tasks';
 import { ActivityRequestParameters, Task, TaskStatuses, TaskTypes } from '../../types/tasks';
 import {
@@ -100,9 +101,11 @@ export default class ComputeEngineServiceMock {
         (data.component && task.componentKey !== data.component) ||
         (data.status && !data.status.split(',').includes(task.status)) ||
         (data.type && task.type !== data.type) ||
-        (data.minSubmittedAt && isBefore(task.submittedAt, data.minSubmittedAt)) ||
+        (data.minSubmittedAt &&
+          isBefore(parseDate(task.submittedAt), parseDate(data.minSubmittedAt))) ||
         (data.maxExecutedAt &&
-          (!task.executedAt || isAfter(task.executedAt, data.maxExecutedAt))) ||
+          (!task.executedAt ||
+            isAfter(parseDate(task.executedAt), parseDate(data.maxExecutedAt)))) ||
         (data.q &&
           !task.id.includes(data.q) &&
           !task.componentName?.includes(data.q) &&
@@ -148,7 +151,7 @@ export default class ComputeEngineServiceMock {
               case TaskStatuses.Pending:
                 stats.pendingTime = Math.max(
                   stats.pendingTime,
-                  differenceInMilliseconds(task.submittedAt, Date.now())
+                  differenceInMilliseconds(parseDate(task.submittedAt), Date.now())
                 );
                 stats.pending += 1;
                 break;
index 7962c731b69bd4f5094ac0a5a8bae680f0f99b78..fb54325b30caa38f212fcefbc97c3bff87908066 100644 (file)
@@ -25,6 +25,7 @@ import Measure from '../../../../components/measure/Measure';
 import CoverageRating from '../../../../components/ui/CoverageRating';
 import DuplicationsRating from '../../../../components/ui/DuplicationsRating';
 import Rating from '../../../../components/ui/Rating';
+import { parseDate } from '../../../../helpers/dates';
 import { translate, translateWithParameters } from '../../../../helpers/l10n';
 import { isDefined } from '../../../../helpers/types';
 import { ComponentQualifier } from '../../../../types/component';
@@ -166,7 +167,7 @@ export default function ProjectCardMeasures(props: ProjectCardMeasuresProps) {
   }
 
   const newCodeTimespan = newCodeStartingDate
-    ? differenceInMilliseconds(Date.now(), newCodeStartingDate)
+    ? differenceInMilliseconds(Date.now(), parseDate(newCodeStartingDate))
     : 0;
 
   const measureList = [
index 524b719f2274effc11ab077f74e3e14fa0ee2ce5..4d3aee13173631528079bbcbf518dfb9d6af341c 100644 (file)
@@ -69,7 +69,7 @@ export default class DateRangeInput extends React.PureComponent<Props> {
           data-test="from"
           highlightTo={this.to}
           minDate={minDate}
-          maxDate={maxDate && this.to ? min(maxDate, this.to) : maxDate || this.to}
+          maxDate={maxDate && this.to ? min([maxDate, this.to]) : maxDate || this.to}
           onChange={this.handleFromChange}
           placeholder={translate('start_date')}
           value={this.from}
@@ -79,7 +79,7 @@ export default class DateRangeInput extends React.PureComponent<Props> {
           currentMonth={this.from}
           data-test="to"
           highlightFrom={this.from}
-          minDate={minDate && this.from ? max(minDate, this.from) : minDate || this.from}
+          minDate={minDate && this.from ? max([minDate, this.from]) : minDate || this.from}
           maxDate={maxDate}
           onChange={this.handleToChange}
           placeholder={translate('end_date')}
index a8fdadc45a12eda53c19f19008ac8c325f002aea..76ec0f6ce550435afe0674cceae934f1f61768e9 100644 (file)
@@ -45,7 +45,7 @@ export default function DateFromNow(props: DateFromNowProps) {
     return <>{originalChildren(translate('never'))}</>;
   }
 
-  if (hourPrecision && differenceInHours(Date.now(), date) < 1) {
+  if (hourPrecision && differenceInHours(Date.now(), parseDate(date)) < 1) {
     children = () => originalChildren(translate('less_than_1_hour_ago'));
   }
 
index bd1d8f039d72ea11d17036734d3d1b85dc40536d..75a24b165616cb1ab142bacb4b313e5b278955d8 100644 (file)
@@ -24,13 +24,15 @@ import {
   differenceInYears
 } from 'date-fns';
 import { FormattedRelativeTime } from 'react-intl';
+import { parseDate } from '../../helpers/dates';
 import { ParsableDate } from '../../types/dates';
 
 const UPDATE_INTERVAL_IN_SECONDS = 10;
 
 export function getRelativeTimeProps(
-  date: ParsableDate
+  parsableDate: ParsableDate
 ): Pick<FormattedRelativeTime['props'], 'unit' | 'value' | 'updateIntervalInSeconds'> {
+  const date = parseDate(parsableDate);
   const y = differenceInYears(date, Date.now());
 
   if (Math.abs(y) > 0) {
index 5840f36bde431c030254f8310f3181571177539d..297a180c258fe7f8e06069fe8e1bf5d5ec4e142b 100644 (file)
@@ -17,7 +17,6 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { parse } from 'date-fns';
 import { ParsableDate } from '../types/dates';
 
 function pad(number: number) {
@@ -28,7 +27,7 @@ function pad(number: number) {
 }
 
 export function parseDate(rawDate: ParsableDate): Date {
-  return parse(rawDate);
+  return new Date(rawDate);
 }
 
 export function toShortNotSoISOString(rawDate: ParsableDate): string {
index 6b461cd75bbf245af3e6696655a2a9d5d610b4ff..94d62542c2f72aba44b8d765ca9ade7556505d92 100644 (file)
@@ -2346,7 +2346,7 @@ __metadata:
     d3-selection: 1.4.1
     d3-shape: 1.3.7
     d3-zoom: 1.8.3
-    date-fns: 1.30.1
+    date-fns: 2.29.2
     dompurify: 2.3.10
     enzyme: 3.11.0
     enzyme-adapter-react-16: 1.15.6
@@ -3818,10 +3818,10 @@ __metadata:
   languageName: node
   linkType: hard
 
-"date-fns@npm:1.30.1":
-  version: 1.30.1
-  resolution: "date-fns@npm:1.30.1"
-  checksum: 86b1f3269cbb1f3ee5ac9959775ea6600436f4ee2b78430cd427b41a0c9fabf740b1a5d401c085f3003539a6f4755c7c56c19fbd70ce11f6f673f6bc8075b710
+"date-fns@npm:2.29.2":
+  version: 2.29.2
+  resolution: "date-fns@npm:2.29.2"
+  checksum: 08bebcceb0a5dbadae4c55e6592b9d5c07dbd7833433c7e9a1d4a424300db32589b8b48e5979b32863c9b00a48d9bab6663e580c2a4f9f203d46cbf9113b5664
   languageName: node
   linkType: hard