Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks for month and year #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/components/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@ import config from '../../config';

const dateMatcher = /(\d{4})\-(\d{1,2})\-(\d{1,2})/;

const formatDate = dateObject => ((dateObject.getDate() === new Date().getDate() ? "Today, " : dateObject.getDate() === new Date().getDate() + 1 ? "Tomorrow, " : "") + new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "2-digit"
}).format(dateObject)
)
const formatDate = dateObject => {
const now = new Date();
const isToday = dateObject.getDate() === now.getDate() && dateObject.getMonth() === now.getMonth() && dateObject.getFullYear() === now.getFullYear();
const isTomorrow = dateObject.getDate() === now.getDate() + 1 && dateObject.getMonth() === now.getMonth() && dateObject.getFullYear() === now.getFullYear();

if (isToday) {
return "Today, " + new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "2-digit"
}).format(dateObject);
} else if (isTomorrow) {
return "Tomorrow, " + new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "2-digit"
}).format(dateObject);
} else {
return new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "2-digit"
}).format(dateObject);
}
};


class Home extends React.Component {
constructor(props) {
Expand Down