changement heure UTC to GMT1
This commit is contained in:
@@ -17,6 +17,8 @@ import recurring_ical_events
|
||||
import caldav
|
||||
|
||||
from mycaldav.settings import *
|
||||
import pytz
|
||||
from dateutil.parser import parse
|
||||
|
||||
Key_separator = "--"
|
||||
|
||||
@@ -53,12 +55,16 @@ class cls_caldav():
|
||||
|
||||
self.clear_data()
|
||||
|
||||
|
||||
modified_url = self.url + f"&start={int((date-timedelta(days=days_delta)).timestamp())}&end={int((date +timedelta(days=days_delta)).timestamp())}&expand=1"
|
||||
print(f"ICS CALL URL = {modified_url}")
|
||||
o_url = urllib.request.urlopen(modified_url , context=ctx)
|
||||
self.data = o_url.read()
|
||||
o_url.close()
|
||||
with urllib.request.urlopen(modified_url, context=ctx) as o_url:
|
||||
self.data = o_url.read()
|
||||
#o_url.close()
|
||||
|
||||
print(self.data)
|
||||
|
||||
return self.data
|
||||
|
||||
def get_caldav_data(self,periode=1,calendar=None, date=None):
|
||||
if date is None:
|
||||
@@ -87,7 +93,21 @@ class cls_caldav():
|
||||
events = recurring_ical_events.of(Calendar.from_ical(self.data)).between(today,endweek)
|
||||
|
||||
self.parse_data(events)
|
||||
|
||||
def convert_to_gmt1(self, dt):
|
||||
gmt1_tz = pytz.timezone('Europe/Paris')
|
||||
if dt.tzinfo is not None:
|
||||
# Convertir l'objet datetime en GMT+1
|
||||
# Utilisez le nom de votre fuseau horaire GMT+1
|
||||
dt_gmt1 = dt.astimezone(gmt1_tz)
|
||||
else:
|
||||
# L'objet datetime est naïf, ajouter l'information de fuseau horaire GMT+1
|
||||
utc_tz = pytz.utc
|
||||
dt_utc = utc_tz.localize(dt)
|
||||
dt_gmt1 = dt_utc.astimezone(gmt1_tz)
|
||||
return dt_gmt1
|
||||
def parse_data(self, events):
|
||||
desired_timezone = pytz.timezone('Europe/Paris')
|
||||
for event in events:
|
||||
item = _caldav_item()
|
||||
item.name = event["SUMMARY"]
|
||||
@@ -128,10 +148,18 @@ class cls_caldav():
|
||||
item.href = temp_str
|
||||
item.desc = item.desc.replace("{href=" + item.href + "}","")
|
||||
|
||||
item.dtstart = event["DTSTART"].dt.strftime("%d.%m.%Y %H:%M")
|
||||
item.dtstamp = int(event["DTSTART"].dt.strftime("%Y%m%d%H%M"))
|
||||
|
||||
desired_timezone = pytz.timezone('Europe/Paris')
|
||||
datetime_obj = parse(event["DTSTART"].dt.strftime("%d.%m.%Y %H:%M"))
|
||||
gmt1_datetime = datetime_obj.astimezone(desired_timezone)
|
||||
|
||||
print(f"gmt= {self.convert_to_gmt1( event['DTSTART'].dt)}")
|
||||
|
||||
|
||||
item.dtstart = self.convert_to_gmt1( event['DTSTART'].dt).strftime("%d.%m.%Y %H:%M")
|
||||
item.dtstamp = int(self.convert_to_gmt1( event['DTSTART'].dt).strftime("%Y%m%d%H%M"))
|
||||
#print(item.dtstamp)
|
||||
item.dtend = event["DTEND"].dt.strftime("%d.%m.%Y %H:%M")
|
||||
item.dtend = self.convert_to_gmt1( event['DTEND'].dt).strftime("%d.%m.%Y %H:%M")
|
||||
|
||||
|
||||
item.format_str_date()
|
||||
|
Reference in New Issue
Block a user