Skip to content

Commit

Permalink
ref(ts): Refactor DateTime component (#14235)
Browse files Browse the repository at this point in the history
* ref(ts): Refactor DateTime component
  • Loading branch information
MeredithAnya committed Aug 7, 2019
1 parent 85816a9 commit 2616adb
Showing 1 changed file with 13 additions and 6 deletions.
Expand Up @@ -5,7 +5,16 @@ import _ from 'lodash';

import ConfigStore from 'app/stores/configStore';

class DateTime extends React.Component {
type Props = {
date: moment.MomentInput;
dateOnly?: boolean;
timeOnly?: boolean;
shortDate?: boolean;
seconds?: boolean;
utc?: boolean;
};

class DateTime extends React.Component<Props> {
static propTypes = {
date: PropTypes.any.isRequired,
dateOnly: PropTypes.bool,
Expand All @@ -19,7 +28,7 @@ class DateTime extends React.Component {
seconds: true,
};

getFormat = ({clock24Hours}) => {
getFormat = ({clock24Hours}: {clock24Hours: boolean}): string => {
const {dateOnly, timeOnly, seconds, shortDate} = this.props;

// October 26, 2017
Expand Down Expand Up @@ -63,13 +72,11 @@ class DateTime extends React.Component {
const options = user ? user.options : {};
const format = this.getFormat(options);

const coercedDate = _.isString(date) || _.isNumber(date) ? new Date(date) : date;

return (
<time {...carriedProps}>
{utc
? moment.utc(coercedDate).format(format)
: moment.tz(coercedDate, options.timezone).format(format)}
? moment.utc(date).format(format)
: moment.tz(date, options.timezone).format(format)}
</time>
);
}
Expand Down

0 comments on commit 2616adb

Please sign in to comment.