-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added calorie information, meal timer.
- Loading branch information
1 parent
c76afe5
commit 9cec951
Showing
4 changed files
with
129 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const mealTimesWeekday = [ | ||
{ start: "08:00", end: "09:15" }, | ||
{ start: "11:30", end: "14:00" }, | ||
{ start: "17:00", end: "19:00" } | ||
]; | ||
|
||
const mealTimesWeekend = [ | ||
{ start: "09:00", end: "10:00" }, | ||
{ start: "12:00", end: "13:30" }, | ||
{ start: "17:00", end: "19:00" } | ||
]; | ||
|
||
function getMealTimes() { | ||
const now = new Date(); | ||
const day = now.getDay(); | ||
return (day === 0 || day === 6) ? mealTimesWeekend : mealTimesWeekday; | ||
} | ||
|
||
function timeStringToDate(timeString) { | ||
const now = new Date(); | ||
const [hours, minutes] = timeString.split(":").map(Number); | ||
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes); | ||
} | ||
|
||
function updateTimer() { | ||
const now = new Date(); | ||
const mealTimes = getMealTimes(); | ||
let nextMeal = null; | ||
let message = ""; | ||
|
||
for (const mealTime of mealTimes) { | ||
const start = timeStringToDate(mealTime.start); | ||
const end = timeStringToDate(mealTime.end); | ||
|
||
if (now >= start && now <= end) { | ||
message = "Şu an yemek zamanı!"; | ||
break; | ||
} else if (now < start) { | ||
nextMeal = start; | ||
break; | ||
} | ||
} | ||
|
||
if (!message) { | ||
if (nextMeal) { | ||
const diff = nextMeal - now; | ||
const hours = Math.floor(diff / 1000 / 60 / 60); | ||
const minutes = Math.floor((diff / 1000 / 60) % 60); | ||
if (hours > 0) { | ||
message = `Bir sonraki yemek <strong>${hours} saat ${minutes} dakika</strong> sonra.`; | ||
} else { | ||
message = `Bir sonraki yemek <strong>${minutes} dakika</strong> sonra.`; | ||
} | ||
} else { | ||
message = "Bugün için yemek saati bitti."; | ||
} | ||
} | ||
|
||
document.getElementById("timer").innerHTML = `${message} <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>`; | ||
} | ||
|
||
setInterval(updateTimer, 1000); | ||
updateTimer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,21 +12,33 @@ | |
|
||
<body> | ||
<div class="container"> | ||
<br> | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert" id="timer"> | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<ul class="list-group mt-4"> | ||
{% for meal in meals %} | ||
<li class="list-group-item {% if loop.index0 == 0 %}active{% endif %}"> | ||
<h3 class="mb-3">{{ meal.date }}</h2> | ||
<ul> | ||
{% for m in meal.meals %} | ||
<li>{{ m }}</li> | ||
{% endfor %} | ||
</ul> | ||
<h3 class="mb-3">{{ meal.date }}</h3> | ||
<ul> | ||
{% for m in meal.meals %} | ||
<li>{{ m }}</li> | ||
{% endfor %} | ||
</ul> | ||
<hr class="line {% if loop.index0 == 0 %}.active{% endif %}"> | ||
<p> | ||
<small> | ||
Toplam Kalori: <strong>{{ meal.calories }} kcal</strong> | ||
</small> | ||
</p> | ||
</li><br> | ||
{% endfor %} | ||
</ul> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<div class="col-sm-6 mb-4 mb-sm-0"> | ||
<div class="card text-center"> | ||
<div class="card-header"> | ||
<h5>Hafta İçi Yemek Saatleri</h5> | ||
|
@@ -38,10 +50,11 @@ <h5>Hafta İçi Yemek Saatleri</h5> | |
</ul> | ||
</div> | ||
</div> | ||
|
||
<div class="col-sm-6"> | ||
<div class="card text-center"> | ||
<div class="card-header"> | ||
<h5>Hafta Sonu (ve tatil günleri) Yemek Saatleri</h5> | ||
<h5>Hafta Sonu Yemek Saatleri</h5> | ||
</div> | ||
<ul class="list-group list-group-flush"> | ||
<li class="list-group-item">09.00 – 10.00</li> | ||
|
@@ -51,18 +64,27 @@ <h5>Hafta Sonu (ve tatil günleri) Yemek Saatleri</h5> | |
</div> | ||
</div> | ||
</div> | ||
|
||
<footer class="py-3 my-4"> | ||
<p class="text-center text-muted">Made with ❤ by <a href="https://github.com/mertatilgan" class="me">Mert | ||
Kemal Atılgan</a></p> | ||
<p class="text-center text-muted">Bread Icon created by <a href="https://www.flaticon.com/free-icons/bread" | ||
title="bread icons" class="me">Freepik - Flaticon</a></p> | ||
<p class="text-center text-muted"> | ||
<strong>Not: </strong> Verilerin girişinde üniversiteden kaynaklı olarak bazı yemeklerin | ||
detayları gösterilmeyebilir. | ||
</p> | ||
<hr> | ||
<p class="text-center text-muted"> | ||
<a href=" https://github.com/mertatilgan" class="me">Mert Kemal Atılgan</a> tarafından ❤ ile yapıldı. | ||
</p> | ||
<p class="text-center text-muted"> | ||
Ekmek ikonu <a href="https://www.flaticon.com/free-icons/bread" title="bread icons" class="me">Freepik - | ||
Flaticon</a>'dan. | ||
</p> | ||
|
||
</footer> | ||
</div> | ||
|
||
<script src="{{url_for('static', filename='mealtimer.js')}}"></script> | ||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> | ||
</body> | ||
|
||
</html> | ||
</html> |