20 lines
598 B
Python
20 lines
598 B
Python
#!/usr/bin/env python3
|
|
|
|
from datetime import datetime, tzinfo, timedelta
|
|
|
|
|
|
class TZMadrid(tzinfo):
|
|
def utcoffset(self, dt):
|
|
return timedelta(hours=1) + self.dst(dt)
|
|
|
|
def dst(self, dt):
|
|
dston = datetime.date(dt.year, 4, 1)
|
|
dstoff = datetime.date(dt.year, 10, 27)
|
|
# Code to set dston and dstoff to the time zone's DST
|
|
# transition times based on the input dt.year, and expressed
|
|
# in standard local time.
|
|
|
|
if dston <= dt.replace(tzinfo=None) < dstoff:
|
|
return timedelta(hours=1)
|
|
else:
|
|
return timedelta(0)
|