Skip to content

Commit

Permalink
Merge pull request #97 from casper-network/better-news-post-date-hand…
Browse files Browse the repository at this point in the history
…ling

MODIFIED: better news post date handling
  • Loading branch information
sd-ditoy authored Aug 8, 2024
2 parents 60db79a + bc06f88 commit f091429
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/atoms/PostItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</router-link>
</div>
<div class="content" :class="`postType-${type}`">
<div class="time" v-if="type === 'news'">
<div class="time" v-if="type === 'news'" :title="date">
<SVGClock />
{{ getRelativeDate }}
<time :datetime="date">{{ getRelativeDate }}</time>
</div>
<h3 v-if="type === 'news'">{{postItemData.content[0].title}}</h3>
<h3 v-else>{{postItemData.title}}</h3>
Expand Down Expand Up @@ -89,7 +89,16 @@ export default {
//---------------------------------------------------
computed: {
getRelativeDate() {
return dayjs().to(this.postItemData.publish_date);
const time = (new Date()).toISOString().split('T')[1];
const publishDate = this.postItemData?.publish_date;
if (publishDate) {
const relative = dayjs().to(`${publishDate}T${time}`);
return relative === 'a few seconds ago' ? 'Today' : relative;
}
return 'Today';
},
date() {
return this.postItemData?.publish_date || '';
},
postImage() {
if (this.type === 'news') {
Expand Down

0 comments on commit f091429

Please sign in to comment.