Skip to content

Commit

Permalink
Fix humanizar fechas de varios tipos
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Restrepo committed Jul 21, 2023
1 parent edd1b73 commit 46347e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
16 changes: 8 additions & 8 deletions student-blogs/dfrestrepo-1489/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="21-07-2023"></time>
<div class="card-description">
<p>Delve into the wonderful world of bears and uncover the secrets of their lives in this
exciting post. Join us on a journey through dense forests and majestic mountains as we
Expand All @@ -94,7 +94,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="20-06-2023"></time>
<div class="card-description">
<p>Discover how bears interact with their environment, from foraging for food to building their
cozy homes in the depths of nature. Learn about their social behaviors and how they
Expand All @@ -118,7 +118,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="01-06-2023"></time>
<div class="card-description">
<p>you will find fascinating facts, beautiful images, and captivating stories about the
different types of bears that inhabit our planet. From the imposing polar bear to the agile
Expand All @@ -141,7 +141,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="28-05-2023"></time>
<div class="card-description">
<p>Get ready for an unforgettable adventure and learn more about the life of bears. We guarantee
you will fall in love with these magnificent animals and appreciate the importance of
Expand All @@ -164,7 +164,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="28-04-2023"></time>
<div class="card-description">
<p>Delve into the wonderful world of bears and uncover the secrets of their lives in this
exciting post. Join us on a journey through dense forests and majestic mountains as we
Expand All @@ -187,7 +187,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="28-06-2022"></time>
<div class="card-description">
<p>Discover how bears interact with their environment, from foraging for food to building their
cozy homes in the depths of nature. Learn about their social behaviors and how they
Expand All @@ -211,7 +211,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="21-05-2022"></time>
<div class="card-description">
<p>you will find fascinating facts, beautiful images, and captivating stories about the
different types of bears that inhabit our planet. From the imposing polar bear to the agile
Expand All @@ -234,7 +234,7 @@ <h2>
Bear life
</h2>
</div>
<div class="card-date"></div>
<time class="card-date" datetime="28-06-2021"></time>
<div class="card-description">
<p>Get ready for an unforgettable adventure and learn more about the life of bears. We guarantee
you will fall in love with these magnificent animals and appreciate the importance of
Expand Down
35 changes: 20 additions & 15 deletions student-blogs/dfrestrepo-1489/main.mjs
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime.js";
import customParseFormat from "dayjs/plugin/customParseFormat"

await import("dayjs/locale/en-au.js")

dayjs.locale("en-au")
dayjs.extend(relativeTime)
dayjs.extend(customParseFormat)

function toHumanize(date) {
const wrappedDate = dayjs(date)
const wrappedDate = dayjs(date, "DD-MM-YYYY")
const daysDiff = Math.abs(wrappedDate.diff(Date.now(), "days"));

const isCurrentYear = wrappedDate.year() === new Date().getFullYear();
const isCurrentYear = wrappedDate.year() === new Date().getFullYear();

if(!isCurrentYear) {
return wrappedDate.format("MMMM DD, YYYY")
} else if(daysDiff <= 30) {
return wrappedDate.fromNow();
} else {
return wrappedDate.format("MMMM DD")
}
if(!isCurrentYear) {
return wrappedDate.format("MMMM DD, YYYY")
} else if(daysDiff <= 30) {
return wrappedDate.fromNow();
} else {
return wrappedDate.format("MMMM DD")
}
}


const toPrint = toHumanize(dayjs().subtract(365, "days"))
const dates = document.querySelectorAll("time")
dates.forEach(function(date) {

const datetime = date.getAttribute("datetime")

console.log("datetime: " + datetime)

var cardDate = document.getElementsByClassName("card-date");

for (var i = 0; i < cardDate.length; i++) {
cardDate[i].innerHTML = toPrint;
}
const transformDate = toHumanize(datetime);
console.log(transformDate)
date.textContent = transformDate
})

0 comments on commit 46347e4

Please sign in to comment.