Improve timezone handling to take DST into account
This commit is contained in:
		
							parent
							
								
									47b438bd0b
								
							
						
					
					
						commit
						4284deb17a
					
				
					 1 changed files with 2 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
import re
 | 
			
		||||
from datetime import timezone, timedelta
 | 
			
		||||
 | 
			
		||||
from pytz import timezone
 | 
			
		||||
import requests
 | 
			
		||||
from dateutil.parser import parse
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +68,7 @@ def build_reply(departures: list) -> list:
 | 
			
		|||
    reply = [f'Next departures for station: {departures[0]["currentStation"]["title"]}']
 | 
			
		||||
    for departure in departures:
 | 
			
		||||
        reply_text = f'{departure["train"]["name"]} to "{departure["destination"]}" at ' \
 | 
			
		||||
                     f'{parse(departure["departure"]["time"]).astimezone(timezone(timedelta(hours=1))).strftime("%H:%M")}'
 | 
			
		||||
                     f'{parse(departure["departure"]["time"]).astimezone(timezone("Europe/Berlin")).strftime("%H:%M")}'
 | 
			
		||||
 | 
			
		||||
        if 'delay' in departure['departure']:
 | 
			
		||||
            reply_text += f' (+{str(departure["departure"]["delay"])})'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue