|
115 | 115 | <div id="countdown" class="fixed-width-digits">00:00:00</div> |
116 | 116 | <div class="countdown-info"> |
117 | 117 | <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 --> |
119 | 119 | </div> |
120 | 120 | </div> |
121 | 121 |
|
122 | 122 | <script> |
123 | 123 | 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'; |
125 | 125 | 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; |
127 | 127 |
|
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; |
130 | 130 |
|
131 | 131 | function z(n,len=2){return String(n).padStart(len,'0');} |
132 | 132 |
|
133 | 133 | async function loadCsv(){ |
134 | 134 | try{ |
135 | | - // Adding a cache-busting parameter to ensure the latest CSV is fetched |
136 | 135 | const res = await fetch(CSV_PATH + '?cache=' + new Date().getTime()); |
137 | 136 | if(!res.ok) throw new Error('CSV fetch error: ' + res.statusText); |
138 | 137 | const txt = await res.text(); |
139 | 138 | parseCsv(txt); |
140 | 139 | console.log("CSV data loaded successfully."); |
141 | | - return true; // Indicate success |
| 140 | + return true; |
142 | 141 | }catch(e){ |
143 | 142 | console.warn("בעיה בטעינת CSV",e); |
144 | | - return false; // Indicate failure |
| 143 | + return false; |
145 | 144 | } |
146 | 145 | } |
147 | 146 |
|
|
151 | 150 | let start = 0; |
152 | 151 | if (/date/i.test(lines[0])) start = 1; |
153 | 152 |
|
154 | | - // Clear existing map before parsing new data |
155 | 153 | sunriseMap.clear(); |
156 | 154 |
|
157 | 155 | for(let i=start;i<lines.length;i++){ |
|
171 | 169 | } |
172 | 170 |
|
173 | 171 | 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 | + |
175 | 177 | return sunriseMap.get(key) || {sunrise:DEFAULT_SUNRISE, hebrew:'—'}; |
176 | 178 | } |
177 | 179 |
|
|
184 | 186 | const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); |
185 | 187 |
|
186 | 188 | 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 | + |
187 | 192 | const hebrewDate = data.hebrew; |
188 | 193 | const [sh,sm,ss] = data.sunrise.split(':').map(n=>parseInt(n,10)); |
189 | 194 |
|
|
208 | 213 |
|
209 | 214 | document.getElementById('countdown').textContent = z(hh)+":"+z(mm)+":"+z(ss2); |
210 | 215 | 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 |
212 | 217 |
|
213 | 218 | } else { |
214 | 219 | defaultDisplay.style.display = 'flex'; |
|
219 | 224 | } |
220 | 225 | } |
221 | 226 |
|
222 | | -// Function to check for new data version |
223 | 227 | async function checkForNewVersion(){ |
224 | 228 | try { |
225 | | - // Cache-bust the version file fetch as well |
226 | 229 | const res = await fetch(VERSION_FILE_PATH + '?cache=' + new Date().getTime()); |
227 | 230 | if (!res.ok) throw new Error('Version file fetch error: ' + res.statusText); |
228 | 231 | const versionData = await res.json(); |
229 | 232 | const latestVersion = versionData.last_updated || 0; |
230 | 233 |
|
231 | 234 | if (latestVersion > currentDataVersion) { |
232 | 235 | 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(); |
234 | 237 | if (loaded) { |
235 | | - currentDataVersion = latestVersion; // Update version only if CSV loaded successfully |
| 238 | + currentDataVersion = latestVersion; |
236 | 239 | 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. |
238 | 240 | } |
239 | 241 | } |
240 | 242 | } catch (e) { |
241 | 243 | console.warn("בעיה בבדיקת גרסה או טעינת נתונים חדשים", e); |
242 | 244 | } |
243 | 245 | } |
244 | 246 |
|
245 | | - |
246 | 247 | (async function init(){ |
247 | | - // Initial load of CSV |
248 | 248 | const loaded = await loadCsv(); |
249 | 249 | if (loaded) { |
250 | | - // If initial CSV load is successful, get initial version from version.json |
251 | 250 | try { |
252 | 251 | const res = await fetch(VERSION_FILE_PATH + '?cache=' + new Date().getTime()); |
253 | 252 | if (res.ok) { |
|
260 | 259 | } |
261 | 260 | } |
262 | 261 |
|
263 | | - updateTick(); // Initial display update |
264 | | - setInterval(updateTick,1000); // Update time every second |
| 262 | + updateTick(); |
| 263 | + setInterval(updateTick,1000); |
265 | 264 |
|
266 | | - // Start periodic version checking |
267 | 265 | setInterval(checkForNewVersion, VERSION_CHECK_INTERVAL_MS); |
268 | 266 | })(); |
269 | 267 | </script> |
|
0 commit comments