Grégoire Delattre c6638376b6 Remove moment to use timeago.js
Moment is huge, timeago.js is tiny !
2021-08-28 09:32:20 -10:00

46 lines
1020 B
JavaScript

import React from "react";
import PropTypes from "prop-types";
import { format } from "timeago.js";
const prettyDate = (input) => {
if (typeof input !== "string" || input === "") {
return input;
}
const date = new Date(input);
if (isNaN(date)) {
return "";
}
const dd = date.getDay().toString().padStart(2, "0");
const mm = date.getMonth().toString().padStart(2, "0");
const yyyy = date.getFullYear();
let output = `${dd}/${mm}/${yyyy}`;
const now = new Date();
const days = Math.abs((now - date) / (24 * 60 * 60 * 1000));
if (days < 31) {
output += ` (${format(date)})`;
}
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: "" };