Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80bf6f4

Browse files
committedJan 11, 2021
fix: date range formatting
Cover the cases when not all dates are defined.
1 parent 4a47733 commit 80bf6f4

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed
 

‎src/routes/MyTeamsDetails/components/TeamMembers/index.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import React, { useState, useCallback, useMemo } from "react";
77
import PT from "prop-types";
88
import "./styles.module.scss";
99
import _ from "lodash";
10-
import moment from "moment";
1110
import User from "components/User";
1211
import CardHeader from "components/CardHeader";
1312
// import Rating from "components/Rating";
1413
import SkillsSummary from "components/SkillsSummary";
1514
import ActionsMenu from "components/ActionsMenu";
1615
import Button from "components/Button";
1716
import Pagination from "components/Pagination";
18-
import { DAY_FORMAT, TEAM_MEMBERS_PER_PAGE } from "constants";
17+
import { TEAM_MEMBERS_PER_PAGE } from "constants";
1918
import {
19+
formatDateRange,
2020
formatMoney,
2121
formatReportIssueUrl,
2222
formatRequestExtensionUrl,
@@ -121,8 +121,7 @@ const TeamMembers = ({ team }) => {
121121
<div styleName="table-group-first-inner">
122122
<div styleName="table-cell cell-role">{member.job.title}</div>
123123
<div styleName="table-cell cell-date">
124-
{moment(member.startDate).format(DAY_FORMAT)} -{" "}
125-
{moment(member.endDate).format(DAY_FORMAT)}
124+
{formatDateRange(member.startDate, member.endDate)}
126125
</div>
127126
<div styleName="table-cell cell-money">
128127
{member.customerRate && member.customerRate > 0

‎src/routes/MyTeamsDetails/components/TeamPositions/index.jsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
*/
66
import React from "react";
77
import PT from "prop-types";
8-
import moment from "moment";
98
import CardHeader from "components/CardHeader";
109
import SkillsList, { skillShape } from "components/SkillsList";
1110
import Button from "components/Button";
12-
import {
13-
DAY_FORMAT,
14-
POSITION_STATUS,
15-
POSITION_STATUS_TO_TEXT,
16-
RATE_TYPE,
17-
} from "constants";
11+
import { POSITION_STATUS, POSITION_STATUS_TO_TEXT, RATE_TYPE } from "constants";
1812
import "./styles.module.scss";
13+
import { formatDateRange } from "utils/format";
1914

2015
const TeamPositions = ({ teamId, positions }) => {
2116
return (
@@ -33,8 +28,7 @@ const TeamPositions = ({ teamId, positions }) => {
3328
</div>
3429
<div styleName="table-group-first-inner">
3530
<div styleName="table-cell cell-date">
36-
{moment(position.startDate).format(DAY_FORMAT)} -{" "}
37-
{moment(position.endDate).format(DAY_FORMAT)}
31+
{formatDateRange(position.startDate, position.endDate)}
3832
</div>
3933
<div styleName="table-cell cell-money">
4034
{/* Hide rate as we don't have data for it */}

‎src/routes/MyTeamsList/components/TeamCard/index.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import IconClock from "../../../../assets/images/icon-clock.svg";
1414
import IconMoney from "../../../../assets/images/icon-money.svg";
1515
import IconPeople from "../../../../assets/images/icon-people.svg";
1616
import {
17+
formatDateRange,
1718
formatMoney,
1819
formatRemainingTimeForTeam,
1920
formatReportIssueUrl,
@@ -45,14 +46,9 @@ const TeamCard = ({ team }) => {
4546

4647
<div styleName="data-items">
4748
<DataItem title="Start - End Date" icon={<IconCalendar />}>
48-
{team.startDate && team.endDate ? (
49-
<>
50-
{moment(team.startDate).format(DAY_FORMAT)} -{" "}
51-
{moment(team.endDate).format(DAY_FORMAT)}
52-
</>
53-
) : (
54-
<>TBD</>
55-
)}
49+
{team.startDate && team.endDate
50+
? formatDateRange(team.startDate, team.endDate)
51+
: "TBD"}
5652
</DataItem>
5753

5854
<DataItem title="Time Remaining" icon={<IconClock />}>

‎src/utils/format.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import _ from "lodash";
55
import { RATE_TYPE } from "constants";
66
import { EMAIL_REPORT_ISSUE, EMAIL_REQUEST_EXTENSION } from "../../config";
77
import moment from "moment";
8+
import { DAY_FORMAT } from "constants/";
89

910
/**
1011
* Formats number with base word in singular or plural form depend on the number.
@@ -133,3 +134,18 @@ export const formatRequestExtensionUrl = (subject) => {
133134
subject
134135
)}`;
135136
};
137+
138+
/**
139+
* Form date range
140+
*
141+
* @param {string|Date|moment.Moment} startDate start date
142+
* @param {string|Date|moment.Moment} endDate end date
143+
*
144+
* @returns {string} formatted date range
145+
*/
146+
export const formatDateRange = (startDate, endDate) => {
147+
const startDateStr = startDate ? moment(startDate).format(DAY_FORMAT) : "";
148+
const endDateStr = endDate ? moment(endDate).format(DAY_FORMAT) : "";
149+
150+
return `${startDateStr} - ${endDateStr}`;
151+
};

0 commit comments

Comments
 (0)