48 lines
984 B
JavaScript
48 lines
984 B
JavaScript
import React from "react"
|
|
import PropTypes from "prop-types"
|
|
import moment from "moment"
|
|
|
|
const prettyDate = (input) => {
|
|
switch (typeof input) {
|
|
case "string":
|
|
if (input === "") { return "" }
|
|
break;
|
|
case "number":
|
|
if (input === 0) { return "" }
|
|
return input
|
|
default:
|
|
return input;
|
|
}
|
|
|
|
const date = moment(input);
|
|
if (!date.isValid()) { return "" }
|
|
|
|
let output = date.format("DD/MM/YYYY");
|
|
|
|
if ((date > moment().subtract(1, "month"))
|
|
&& (date < moment().add(1, "month"))) {
|
|
output += " (" + date.fromNow() + ")"
|
|
}
|
|
|
|
return output
|
|
}
|
|
|
|
export const ReleaseDate = ({ date }) => {
|
|
const formattedDate = prettyDate(date);
|
|
if (formattedDate === "") { return null }
|
|
|
|
return (
|
|
<span>
|
|
<i className="fa fa-calendar mr-1" />
|
|
{formattedDate}
|
|
</span>
|
|
);
|
|
}
|
|
ReleaseDate.propTypes = {
|
|
date: PropTypes.oneOfType([
|
|
PropTypes.string,
|
|
PropTypes.number,
|
|
]),
|
|
};
|
|
ReleaseDate.defaultProps = { date: "" };
|