Skip to content

Commit

Permalink
format last checked string to include hours and days
Browse files Browse the repository at this point in the history
  • Loading branch information
henb13 committed Feb 24, 2022
1 parent f263ed0 commit d1c9d19
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
6 changes: 2 additions & 4 deletions client/src/components/AmountMissing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styles from "./AmountMissing.module.css";
import getClientLocalTime from "../lib/getClientLocalTime";
import formatTimeString from "../lib/formatTimeString";
import { ReactComponent as Checkmark } from "../icons/AmountMissingIcon.svg";
import SkeletonText from "../skeletons/SkeletonText";

Expand All @@ -18,11 +19,8 @@ const AmountMissing = ({ data, showSkeleton }) => {
? Math.floor((new Date(now) - new Date(lastChecked)) / 60000)
: 0;

const lastCheckedString = formatTimeString(lastCheckedMinutes);
const lastCheckedDate = getClientLocalTime(lastChecked, "PP HH:mm");
const lastCheckedString =
lastCheckedMinutes === 0
? "less than a minute ago"
: `${lastCheckedMinutes} minute${lastCheckedMinutes != 1 ? "s" : ""} ago`;

const dateTime = getClientLocalTime(lastChecked, "yyyy-MM-dd HH:mm:ss.sss");

Expand Down
1 change: 1 addition & 0 deletions client/src/components/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

.right {
display: flex;
align-items: flex-start;
margin: 11rem 0rem 9rem 56vw;
}

Expand Down
10 changes: 10 additions & 0 deletions client/src/components/Sort.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
.sort {
position: fixed;
display: flex;
height: min-content;
}

.option {
cursor: pointer;
}

.option .selected {
border: 1px solid var(--color-white);
}
Expand Down
24 changes: 24 additions & 0 deletions client/src/lib/formatTimeString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default function formatTimeString(time) {
if (time < 1) {
return "less than a minute ago";
}

if (time < 60) {
const minutesString = time === 1 ? "minute" : "minutes";
return `${time} ${minutesString} ago`;
}
if (time >= 60 && time < 1440) {
const hours = Math.floor(time / 60);
const hoursString = hours === 1 ? "hour" : "hours";
const minutes = time % 60;
const minutesString = minutes === 1 ? "minute" : "minutes";

return `${hours} ${hoursString} ${
minutes === 0 ? "" : `and ${minutes} ${minutesString} `
}ago`;
}

const days = Math.floor(time / (60 * 60 * 24));
const daysString = days === 1 ? "day" : "days";
return `${days} ${daysString} ago`;
}
1 change: 1 addition & 0 deletions server/lib/getSpotifyEpisodeNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const SpotifyWebApi = require("spotify-web-api-node");
require("dotenv").config();

const JRE_SHOW_ID = "4rOoJ6Egrf8K2IrywzwOMk";

async function getSpotifyEpisodeNames() {
try {
const spotifyApi = new SpotifyWebApi({
Expand Down

0 comments on commit d1c9d19

Please sign in to comment.