Skip to content

Commit

Permalink
fix: test now pass
Browse files Browse the repository at this point in the history
  • Loading branch information
noa.santo committed Jan 9, 2024
1 parent 23e49d4 commit 125cb47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getSunlightPercentage = (
if (totalDaylightMinutes <= 0) {
return 20;
}
const currentMinutes = time - sunriseTime + 86400000;
const currentMinutes = time - sunriseTime;
const sunlightPercentage = (currentMinutes / totalDaylightMinutes) * 100;

if (sunlightPercentage < 0) {
Expand All @@ -29,7 +29,7 @@ export const getNighttimePercentage = (
if (totalNighttimeMinutes <= 0) {
return 0;
}
const currentMinutes = time - sunsetTime + 86400000;
const currentMinutes = time - sunsetTime;
const nighttimePercentage = (currentMinutes / totalNighttimeMinutes) * 100;

if (nighttimePercentage < 0) {
Expand Down
12 changes: 8 additions & 4 deletions src/components/content/heroes/aurora/weather-easter-egg/sun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,22 @@ export const Sun = () => {
setSunrise(sunriseTime);
setSunset(sunsetTime);
setTimePercent(
getSunlightPercentage(sunriseTime, sunsetTime, +new Date()),
getSunlightPercentage(sunriseTime, sunsetTime, +new Date() + 86400000),
);
setNightTimePercent(
getNighttimePercentage(sunriseTime, sunsetTime, +new Date()),
getNighttimePercentage(sunriseTime, sunsetTime, +new Date() + 86400000),
);
};

fetchData();

const interval = setInterval(() => {
setTimePercent(getSunlightPercentage(sunrise, sunset, +new Date()));
setNightTimePercent(getNighttimePercentage(sunrise, sunset, +new Date()));
setTimePercent(
getSunlightPercentage(sunrise, sunset, +new Date() + 86400000),
);
setNightTimePercent(
getNighttimePercentage(sunrise, sunset, +new Date() + 86400000),
);
}, 10000);

return () => {
Expand Down

0 comments on commit 125cb47

Please sign in to comment.