diff options
| -rw-r--r-- | app/templates/index.html | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/app/templates/index.html b/app/templates/index.html index c690525..1714ddb 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -9,8 +9,8 @@ </div> <div class="d-flex gap-2 align-items-center"> <a href="/?week={{ prev_week }}" class="btn btn-outline-secondary btn-sm"><i class="bi bi-chevron-left"></i></a> - <input type="week" id="weekPicker" class="form-control form-control-sm" style="width:160px" - value="{{ week_start.strftime('%G-W%V') }}"> + <input type="date" id="weekPicker" class="form-control form-control-sm" style="width:150px" + value="{{ week_start.isoformat() }}" title="Pick any day in the week you want"> {% if not is_current_week %} <a href="/" class="btn btn-outline-secondary btn-sm">Today</a> {% endif %} @@ -123,13 +123,11 @@ const todayStr = '{{ today_str }}'; document.getElementById('weekPicker').addEventListener('change', function() { if (!this.value) return; - // value is "YYYY-Www" — convert to Mon of that ISO week - const [year, week] = this.value.split('-W').map(Number); - const jan4 = new Date(year, 0, 4); // Jan 4 is always in week 1 - const dayOfWeek = jan4.getDay() || 7; // Mon=1..Sun=7 - const mon = new Date(jan4); - mon.setDate(jan4.getDate() - (dayOfWeek - 1) + (week - 1) * 7); - const iso = mon.toISOString().split('T')[0]; + // Rewind picked date to Monday of that week + const d = new Date(this.value + 'T00:00:00'); + const day = d.getDay() || 7; // Sun=0→7, Mon=1 + d.setDate(d.getDate() - (day - 1)); + const iso = d.toISOString().split('T')[0]; window.location.href = '/?week=' + iso; }); </script> |
