fix: display Updated in posts only when modDatetime > pubDatetime (#258)

* refactor: show update time when modDatetime more recently than pubDatetime

* fix: show wrong date when compare with null modeDate

* refactor: modDatetime type checking & rewrite myDatetime
This commit is contained in:
Parinya T
2024-02-19 11:08:43 +07:00
committed by GitHub
parent 8e022c7b5a
commit 25a640b728
+4 -2
View File
@@ -28,7 +28,7 @@ export default function Datetime({
<path d="M7 11h2v2H7zm0 4h2v2H7zm4-4h2v2h-2zm0 4h2v2h-2zm4-4h2v2h-2zm0 4h2v2h-2z"></path>
<path d="M5 22h14c1.103 0 2-.897 2-2V6c0-1.103-.897-2-2-2h-2V2h-2v2H9V2H7v2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2zM19 8l.001 12H5V8h14z"></path>
</svg>
{modDatetime ? (
{modDatetime && modDatetime > pubDatetime ? (
<span className={`italic ${size === "sm" ? "text-sm" : "text-base"}`}>
Updated:
</span>
@@ -46,7 +46,9 @@ export default function Datetime({
}
const FormattedDatetime = ({ pubDatetime, modDatetime }: DatetimesProps) => {
const myDatetime = new Date(modDatetime ? modDatetime : pubDatetime);
const myDatetime = new Date(
modDatetime && modDatetime > pubDatetime ? modDatetime : pubDatetime
);
const date = myDatetime.toLocaleDateString(LOCALE.langTag, {
year: "numeric",