Hi @fgiron, according to the definition of CET/CEST, timezone +02:00 is applied in 210 days between 01:00 UTC on the last Sunday of March and 01:00 UTC on the last Sunday of October, otherwise timezone +01:00 is applied. Therefore, if you get start and end dates of the CEST duration in the year, you can determine the correct timezone for a specific datetime by testing the datetime is within the duration.
This screenshot illustrates a possible way.

Alternatively, a PythonCaller with this script works as well.
from datetime import datetime, timedelta
class CESTStartEndDatetimeCalculator(object):
def __init__(self):
self.cestStartEnd = {}
def input(self, feature):
def getCestStartEnd(year):
s = datetime(int(year), 3, 25, 1)
while s.strftime('%w') != '0':
s = s + timedelta(days=1)
e = s + timedelta(days=210)
return (
s.strftime('%Y%m%d%H%M%S') + '+00:00',
e.strftime('%Y%m%d%H%M%S') + '+00:00'
)
year = str(feature.getAttribute('_timestamp_utc'))[:4]
s, e = self.cestStartEnd.setdefault(year, getCestStartEnd(year))
feature.setAttribute('_cest_start_datetime', s) # 01:00 UTC, the last Sunday of March
feature.setAttribute('_cest_end_datetime', e) # 01:00 UTC, the last Sunday of October
self.pyoutput(feature)
def close(self):
pass
Dateutil has a timezone module so another python solution
import fme
import fmeobjects
from datetime import datetime
from dateutil import tz
def convertUTC(feature):
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('Europe/Paris')
utc = datetime.strptime(str(feature.getAttribute('date')), '%Y%m%d%H%M%S')
# set date to UTC
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
central = utc.astimezone(to_zone)
feature.setAttribute("converted_date", central.strftime('%Y%m%d%H%M%S%z'))

Hi @fgiron, according to the definition of CET/CEST, timezone +02:00 is applied in 210 days between 01:00 UTC on the last Sunday of March and 01:00 UTC on the last Sunday of October, otherwise timezone +01:00 is applied. Therefore, if you get start and end dates of the CEST duration in the year, you can determine the correct timezone for a specific datetime by testing the datetime is within the duration.
This screenshot illustrates a possible way.

Alternatively, a PythonCaller with this script works as well.
from datetime import datetime, timedelta
class CESTStartEndDatetimeCalculator(object):
def __init__(self):
self.cestStartEnd = {}
def input(self, feature):
def getCestStartEnd(year):
s = datetime(int(year), 3, 25, 1)
while s.strftime('%w') != '0':
s = s + timedelta(days=1)
e = s + timedelta(days=210)
return (
s.strftime('%Y%m%d%H%M%S') + '+00:00',
e.strftime('%Y%m%d%H%M%S') + '+00:00'
)
year = str(feature.getAttribute('_timestamp_utc'))[:4]
s, e = self.cestStartEnd.setdefault(year, getCestStartEnd(year))
feature.setAttribute('_cest_start_datetime', s) # 01:00 UTC, the last Sunday of March
feature.setAttribute('_cest_end_datetime', e) # 01:00 UTC, the last Sunday of October
self.pyoutput(feature)
def close(self):
pass
Hi @takashi, thanks a lot for your answer!
It hadn't occurred to me that summer time always lasts the same. Nor had I thought about replicating the algorithm (last Sunday of March/October) in FME. I love it!!
Dateutil has a timezone module so another python solution
import fme
import fmeobjects
from datetime import datetime
from dateutil import tz
def convertUTC(feature):
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('Europe/Paris')
utc = datetime.strptime(str(feature.getAttribute('date')), '%Y%m%d%H%M%S')
# set date to UTC
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
central = utc.astimezone(to_zone)
feature.setAttribute("converted_date", central.strftime('%Y%m%d%H%M%S%z'))

Hi @ebygomm, very nice and simple python script. It looks like a very simple possible addition to the DateTimeCalculator. Thank you!!