From 8fe8836bc263be11895fafa958409499c9e9fc9d Mon Sep 17 00:00:00 2001 From: Filip785 Date: Wed, 8 Jul 2020 19:46:18 +0200 Subject: Updates to PR as requested --- ui/src/utils.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ui/src/utils.ts') diff --git a/ui/src/utils.ts b/ui/src/utils.ts index f65ca4e3..3ccaae12 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -53,6 +53,7 @@ import emojiShortName from 'emoji-short-name'; import Toastify from 'toastify-js'; import tippy from 'tippy.js'; import EmojiButton from '@joeattardi/emoji-button'; +import moment from 'moment'; export const repoUrl = 'https://github.com/LemmyNet/lemmy'; export const helpGuideUrl = '/docs/about_guide.html'; @@ -489,6 +490,16 @@ export function showAvatars(): boolean { ); } +export function isCakeDay(creator_published: string): boolean { + const userCreationDate = moment.utc(creator_published).local(); + const currentDate = moment(new Date()); + + return ( + userCreationDate.date() === currentDate.date() && + userCreationDate.month() === currentDate.month() + ); +} + // Converts to image thumbnail export function pictrsImage(hash: string, thumbnail: boolean = false): string { let root = `/pictrs/image`; -- cgit v1.2.3 From 7c35fc546bb148047087db6ed95b1579bab08238 Mon Sep 17 00:00:00 2001 From: Filip785 Date: Thu, 9 Jul 2020 17:19:30 +0200 Subject: Create new migration to add `creator_published` field to the `post_view` and `comment_view` --- ui/src/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui/src/utils.ts') diff --git a/ui/src/utils.ts b/ui/src/utils.ts index a418c569..e38834aa 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -503,7 +503,9 @@ export function showAvatars(): boolean { } export function isCakeDay(creator_published: string): boolean { - const userCreationDate = moment.utc(creator_published).local(); + // moment(undefined) or moment.utc(undefined) returns the current date/time + // moment(null) or moment.utc(null) returns null + const userCreationDate = moment.utc(creator_published || null).local(); const currentDate = moment(new Date()); return ( -- cgit v1.2.3 From d222c60cef289b57f0ce350e9f24ce2df4792ef5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 9 Jul 2020 19:59:02 -0400 Subject: A few cake day fixes. #916 --- ui/src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/src/utils.ts') diff --git a/ui/src/utils.ts b/ui/src/utils.ts index e38834aa..22536043 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -502,10 +502,10 @@ export function showAvatars(): boolean { ); } -export function isCakeDay(creator_published: string): boolean { +export function isCakeDay(published: string): boolean { // moment(undefined) or moment.utc(undefined) returns the current date/time // moment(null) or moment.utc(null) returns null - const userCreationDate = moment.utc(creator_published || null).local(); + const userCreationDate = moment.utc(published || null).local(); const currentDate = moment(new Date()); return ( -- cgit v1.2.3