Closed MattVwaves closed 1 year ago
Just a note on this: With the format in this post it will display Month day -> today will be December 5
, yesterday will be December 4
so it will not be in the format shown in the example. I would suggest to add an accurate example on how the day will look like or update the format. You can see the formats in the documentation of date-fns: https://date-fns.org/v2.29.3/docs/format
ah actually getting today and yesterday is just to check if it is today or yesterday.
When I said 'the current date logic' that meant what is already in the app:
const date = format(parseISO(post.createdAt), 'MMMM d, yyyy h:mm a')
to be clearer I mean I'm checking today
and yesterday
with postDay
Requirements
today at 12.45
yesterday at 12.45
Implementation
date-fns
to extract today's date, yesterday's date and the date of the post:const today = format(new Date(), 'MMMM d')
const yesterday = isYesterday(new Date(today)
const postDay = format(parseISO(post.createdAt), 'MMMM d')
today
/yesterday
withat (time)