Explorar o código

impl formatDateToDisplay util

itizawa %!s(int64=5) %!d(string=hai) anos
pai
achega
709a10b367
Modificáronse 2 ficheiros con 17 adicións e 3 borrados
  1. 3 3
      src/client/js/components/Navbar/AuthorInfo.jsx
  2. 14 0
      src/lib/util/date-utils.js

+ 3 - 3
src/client/js/components/Navbar/AuthorInfo.jsx

@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
-
 import { userPageRoot } from '@commons/util/path-utils';
+import { formatDateToDisplay } from '../../../../lib/util/date-utils';
 
 import UserPicture from '../User/UserPicture';
 
@@ -21,7 +21,7 @@ const AuthorInfo = (props) => {
     : <i>Unknown</i>;
 
   if (locate === 'footer') {
-    return <p>{infoLabelForFooter} {date} by <UserPicture user={user} size="sm" /> {userLabel}</p>;
+    return <p>{infoLabelForFooter} {formatDateToDisplay(date)} by <UserPicture user={user} size="sm" /> {userLabel}</p>;
   }
 
   return (
@@ -31,7 +31,7 @@ const AuthorInfo = (props) => {
       </div>
       <div>
         <div>{infoLabelForSubNav} {userLabel}</div>
-        <div className="text-muted text-date">{date}</div>
+        <div className="text-muted text-date">{formatDateToDisplay(date)}</div>
       </div>
     </div>
   );

+ 14 - 0
src/lib/util/date-utils.js

@@ -0,0 +1,14 @@
+const { format } = require('date-fns');
+
+/**
+ * Format any text
+ * @param {*} date string
+ * @param {*} formatType string
+ */
+const formatDateToDisplay = (date, formatType = 'yyyy/MM/dd HH:mm') => {
+  return format(new Date(date), formatType);
+};
+
+module.exports = {
+  formatDateToDisplay,
+};