bugfixing options flow
This commit is contained in:
parent
b22d481009
commit
a4a5c14a25
@ -79,7 +79,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if rawData?.length > 0}
|
||||
<div class="grid grid-cols-1 gap-2 pb-5">
|
||||
{#each newsList as item}
|
||||
<div class="w-full flex flex-col bg-[#09090B] rounded-md m-auto">
|
||||
@ -158,5 +158,8 @@
|
||||
Load More News
|
||||
</label>
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="text-white"> No News article available yet </span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -75,14 +75,44 @@ function isSameDay(date1: Date, date2: Date): boolean {
|
||||
}
|
||||
|
||||
function isDateWithinRange(dateString: string, range: string): boolean {
|
||||
const now = new Date();
|
||||
let now = new Date();
|
||||
const expirationDate = new Date(dateString);
|
||||
const dayOfWeek = now.getDay();
|
||||
|
||||
// Special handling for "1 day" range when it's Friday, Saturday, or Sunday
|
||||
if (
|
||||
range.toLowerCase() === "1 day" &&
|
||||
(dayOfWeek === 5 || dayOfWeek === 6 || dayOfWeek === 0)
|
||||
) {
|
||||
// Calculate next Monday
|
||||
const daysUntilMonday =
|
||||
dayOfWeek === 5
|
||||
? 3 // From Friday
|
||||
: dayOfWeek === 6
|
||||
? 2 // From Saturday
|
||||
: 1; // From Sunday
|
||||
|
||||
const monday = new Date(now);
|
||||
monday.setDate(now.getDate() + daysUntilMonday);
|
||||
|
||||
// Compare with next Monday
|
||||
return isSameDay(expirationDate, monday);
|
||||
}
|
||||
|
||||
// Adjust now to Friday if it falls on a weekend (for other ranges)
|
||||
if (dayOfWeek === 6) {
|
||||
// Saturday
|
||||
now.setDate(now.getDate() - 1); // Move to Friday
|
||||
} else if (dayOfWeek === 0) {
|
||||
// Sunday
|
||||
now.setDate(now.getDate() - 2); // Move to Friday
|
||||
}
|
||||
|
||||
const timeDiff = expirationDate.getTime() - now.getTime();
|
||||
const daysDiff = timeDiff / (1000 * 60 * 60 * 24);
|
||||
|
||||
switch (range.toLowerCase()) {
|
||||
case "same day":
|
||||
// Check if the current date and expiration date are the same
|
||||
return isSameDay(now, expirationDate);
|
||||
case "1 day":
|
||||
return daysDiff >= 0 && daysDiff <= 1;
|
||||
|
||||
@ -1532,12 +1532,7 @@
|
||||
<WIIM {data} />
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="w-full mt-10 sm:mt-0 m-auto sm:pl-6 sm:pb-6 sm:pt-6 {data
|
||||
?.getNews?.length !== 0
|
||||
? ''
|
||||
: 'hidden'}"
|
||||
>
|
||||
<div class="w-full mt-10 sm:mt-0 m-auto sm:pl-6 sm:pb-6 sm:pt-6">
|
||||
<News {data} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user