aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>2022-08-19 16:06:35 +0200
committersonartech <sonartech@sonarsource.com>2022-08-23 20:03:04 +0000
commit4fcbf609f5f2da8185c16aa7ef57ee627b6cada4 (patch)
tree279b9474e1b5bd3fa6b5eed6b8291f98e4ca20d9 /server/sonar-web/src
parent48bf61180dee30ea7dfe7484daad3cdc2427c84c (diff)
downloadsonarqube-4fcbf609f5f2da8185c16aa7ef57ee627b6cada4.tar.gz
sonarqube-4fcbf609f5f2da8185c16aa7ef57ee627b6cada4.zip
[NO JIRA] Upgrade date-fns
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts9
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx3
-rw-r--r--server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx4
-rw-r--r--server/sonar-web/src/main/js/components/intl/DateFromNow.tsx2
-rw-r--r--server/sonar-web/src/main/js/components/intl/dateUtils.ts4
-rw-r--r--server/sonar-web/src/main/js/helpers/dates.ts3
6 files changed, 15 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts
index 191de3056cc..e718aaa7bdc 100644
--- a/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts
+++ b/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts
@@ -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;
diff --git a/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx b/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx
index 7962c731b69..fb54325b30c 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx
@@ -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 = [
diff --git a/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx b/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx
index 524b719f227..4d3aee13173 100644
--- a/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx
+++ b/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx
@@ -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')}
diff --git a/server/sonar-web/src/main/js/components/intl/DateFromNow.tsx b/server/sonar-web/src/main/js/components/intl/DateFromNow.tsx
index a8fdadc45a1..76ec0f6ce55 100644
--- a/server/sonar-web/src/main/js/components/intl/DateFromNow.tsx
+++ b/server/sonar-web/src/main/js/components/intl/DateFromNow.tsx
@@ -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'));
}
diff --git a/server/sonar-web/src/main/js/components/intl/dateUtils.ts b/server/sonar-web/src/main/js/components/intl/dateUtils.ts
index bd1d8f039d7..75a24b16561 100644
--- a/server/sonar-web/src/main/js/components/intl/dateUtils.ts
+++ b/server/sonar-web/src/main/js/components/intl/dateUtils.ts
@@ -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) {
diff --git a/server/sonar-web/src/main/js/helpers/dates.ts b/server/sonar-web/src/main/js/helpers/dates.ts
index 5840f36bde4..297a180c258 100644
--- a/server/sonar-web/src/main/js/helpers/dates.ts
+++ b/server/sonar-web/src/main/js/helpers/dates.ts
@@ -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 {