fix timestamp rendering

This commit is contained in:
balzack 2022-10-04 16:36:38 -07:00
parent 12b4c15c25
commit 8a17592dcf
3 changed files with 10 additions and 3 deletions

View File

@ -18,6 +18,7 @@
"expo": "~46.0.9",
"expo-splash-screen": "~0.16.2",
"expo-status-bar": "~1.4.0",
"moment": "^2.29.4",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-native": "0.69.5",

View File

@ -1,6 +1,7 @@
import { useState, useEffect, useContext } from 'react';
import { CardContext } from 'context/CardContext';
import { ProfileContext } from 'context/ProfileContext';
import moment from 'moment';
export function useTopicItem(item) {
@ -80,13 +81,13 @@ export function useTopicItem(item) {
const now = new Date();
const offset = now.getTime() - date.getTime();
if(offset < 86400000) {
timestamp = date.toLocaleTimeString([], {hour: 'numeric', minute:'2-digit'});
timestamp = moment(date).format('h:mm');
}
else if (offset < 31449600000) {
timestamp = date.toLocaleDateString("en-US", {day: 'numeric', month:'numeric'});
timestamp = moment(date).format('M/DD');
}
else {
timestamp = date.toLocaleDateString("en-US");
timestamp = moment(date).format('M/DD/YYYY');
}
updateState({ logo, name, known, message, timestamp });

View File

@ -4868,6 +4868,11 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
moment@^2.29.4:
version "2.29.4"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
ms@2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz"