Skip to content

Commit c77b954

Browse files
authored
Update index.html
1 parent 1d3f5e2 commit c77b954

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

index.html

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,33 +115,32 @@
115115
<div id="countdown" class="fixed-width-digits">00:00:00</div>
116116
<div class="countdown-info">
117117
<div>שעה נוכחית: <span id="nowSmall" class="fixed-width-digits">--:--:--</span></div>
118-
<div>שעת נץ: <span id="sunriseSmall" class="fixed-width-digits">--:--</span></div>
118+
<div>שעת נץ: <span id="sunriseSmall" class="fixed-width-digits">--:--:--</span></div> <!-- Changed default value to include seconds -->
119119
</div>
120120
</div>
121121

122122
<script>
123123
const CSV_PATH = './sunrise_times.csv';
124-
const VERSION_FILE_PATH = './version.json'; // Path to the version indicator file
124+
const VERSION_FILE_PATH = './version.json';
125125
const DEFAULT_SUNRISE = '06:00:00';
126-
const VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1000; // Check for new version every 5 minutes
126+
const VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1000;
127127

128-
let sunriseMap = new Map(); // 'YYYY-MM-DD' -> { sunrise:'HH:MM:SS', hebrew:'...' }
129-
let currentDataVersion = 0; // Stores the timestamp of the currently loaded data
128+
let sunriseMap = new Map();
129+
let currentDataVersion = 0;
130130

131131
function z(n,len=2){return String(n).padStart(len,'0');}
132132

133133
async function loadCsv(){
134134
try{
135-
// Adding a cache-busting parameter to ensure the latest CSV is fetched
136135
const res = await fetch(CSV_PATH + '?cache=' + new Date().getTime());
137136
if(!res.ok) throw new Error('CSV fetch error: ' + res.statusText);
138137
const txt = await res.text();
139138
parseCsv(txt);
140139
console.log("CSV data loaded successfully.");
141-
return true; // Indicate success
140+
return true;
142141
}catch(e){
143142
console.warn("בעיה בטעינת CSV",e);
144-
return false; // Indicate failure
143+
return false;
145144
}
146145
}
147146

@@ -151,7 +150,6 @@
151150
let start = 0;
152151
if (/date/i.test(lines[0])) start = 1;
153152

154-
// Clear existing map before parsing new data
155153
sunriseMap.clear();
156154

157155
for(let i=start;i<lines.length;i++){
@@ -171,7 +169,11 @@
171169
}
172170

173171
function getDataForDate(dateObj){
174-
const key = dateObj.toISOString().slice(0,10);
172+
const year = dateObj.getFullYear();
173+
const month = z(dateObj.getMonth() + 1); // getMonth() is 0-indexed
174+
const day = z(dateObj.getDate());
175+
const key = `${year}-${month}-${day}`;
176+
175177
return sunriseMap.get(key) || {sunrise:DEFAULT_SUNRISE, hebrew:'—'};
176178
}
177179

@@ -184,6 +186,9 @@
184186
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
185187

186188
const data = getDataForDate(today);
189+
console.log("Current date being checked (local):", today.getFullYear()+"-"+z(today.getMonth()+1)+"-"+z(today.getDate())); // For debugging
190+
console.log("Data retrieved for today (local):", data); // For debugging
191+
187192
const hebrewDate = data.hebrew;
188193
const [sh,sm,ss] = data.sunrise.split(':').map(n=>parseInt(n,10));
189194

@@ -208,7 +213,7 @@
208213

209214
document.getElementById('countdown').textContent = z(hh)+":"+z(mm)+":"+z(ss2);
210215
document.getElementById('nowSmall').textContent = formatTime(now);
211-
document.getElementById('sunriseSmall').textContent = z(sh)+":"+z(sm);
216+
document.getElementById('sunriseSmall').textContent = z(sh)+":"+z(sm)+":"+z(ss); // FIX: Added seconds here
212217

213218
} else {
214219
defaultDisplay.style.display = 'flex';
@@ -219,35 +224,29 @@
219224
}
220225
}
221226

222-
// Function to check for new data version
223227
async function checkForNewVersion(){
224228
try {
225-
// Cache-bust the version file fetch as well
226229
const res = await fetch(VERSION_FILE_PATH + '?cache=' + new Date().getTime());
227230
if (!res.ok) throw new Error('Version file fetch error: ' + res.statusText);
228231
const versionData = await res.json();
229232
const latestVersion = versionData.last_updated || 0;
230233

231234
if (latestVersion > currentDataVersion) {
232235
console.log(`New data version detected: ${latestVersion}. Current: ${currentDataVersion}. Reloading CSV.`);
233-
const loaded = await loadCsv(); // Attempt to load new CSV
236+
const loaded = await loadCsv();
234237
if (loaded) {
235-
currentDataVersion = latestVersion; // Update version only if CSV loaded successfully
238+
currentDataVersion = latestVersion;
236239
console.log("CSV data updated from new version.");
237-
// No need to call updateTick explicitly here, as setInterval(updateTick, 1000) will pick up new data.
238240
}
239241
}
240242
} catch (e) {
241243
console.warn("בעיה בבדיקת גרסה או טעינת נתונים חדשים", e);
242244
}
243245
}
244246

245-
246247
(async function init(){
247-
// Initial load of CSV
248248
const loaded = await loadCsv();
249249
if (loaded) {
250-
// If initial CSV load is successful, get initial version from version.json
251250
try {
252251
const res = await fetch(VERSION_FILE_PATH + '?cache=' + new Date().getTime());
253252
if (res.ok) {
@@ -260,10 +259,9 @@
260259
}
261260
}
262261

263-
updateTick(); // Initial display update
264-
setInterval(updateTick,1000); // Update time every second
262+
updateTick();
263+
setInterval(updateTick,1000);
265264

266-
// Start periodic version checking
267265
setInterval(checkForNewVersion, VERSION_CHECK_INTERVAL_MS);
268266
})();
269267
</script>

0 commit comments

Comments
 (0)