Fix date handling on API request
This commit is contained in:
		
							parent
							
								
									220f6666a5
								
							
						
					
					
						commit
						04e2019afe
					
				
					 3 changed files with 6 additions and 3 deletions
				
			
		
							
								
								
									
										2
									
								
								sw.js
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								sw.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
const VERSION = 'v19'
 | 
			
		||||
const VERSION = 'v20'
 | 
			
		||||
const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/'
 | 
			
		||||
const API_TRAINS = `${API_ORIGIN}v3/trains`
 | 
			
		||||
const API_STATIONS = `${API_ORIGIN}v3/stations`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,8 +110,10 @@ function refresh() {
 | 
			
		|||
			refresh()
 | 
			
		||||
		}, timeout || 90000)
 | 
			
		||||
	}
 | 
			
		||||
	var reqDate = new Date(date.valueOf())
 | 
			
		||||
	reqDate.setMinutes(0, 0, 0)
 | 
			
		||||
	return fetch(
 | 
			
		||||
		`https://scraper.infotren.dcdev.ro/v3/stations/${station}?date=${date.getFullYear().toString()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`,
 | 
			
		||||
		`https://scraper.infotren.dcdev.ro/v3/stations/${station}?date=${reqDate.toISOString()}`,
 | 
			
		||||
		{
 | 
			
		||||
			cache: 'no-store',
 | 
			
		||||
		},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -417,8 +417,9 @@ function refresh() {
 | 
			
		|||
	if (yesterday) {
 | 
			
		||||
		reqDate.setDate(reqDate.getDate() - 1)
 | 
			
		||||
	}
 | 
			
		||||
	reqDate.setMinutes(0, 0, 0)
 | 
			
		||||
	return fetch(
 | 
			
		||||
		`https://scraper.infotren.dcdev.ro/v3/trains/${trainNumber}?date=${reqDate.getFullYear().toString()}-${(reqDate.getMonth() + 1).toString().padStart(2, "0")}-${reqDate.getDate().toString().padStart(2, "0")}`,
 | 
			
		||||
		`https://scraper.infotren.dcdev.ro/v3/trains/${trainNumber}?date=${reqDate.toISOString()}`,
 | 
			
		||||
		{
 | 
			
		||||
			cache: 'no-store',
 | 
			
		||||
		},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue