def stationTimeZone(stationFeature): timeZoneId = stationFeature['timeZoneId'] timeZoneUTC = stationFeature['timeZoneUTC'] tz = None if timeZoneId: tz = QTimeZone(QByteArray(timeZoneId.encode())) if not tz.isValid(): tz = None if not tz: tz = QTimeZone(QByteArray(timeZoneUTC.encode())) return tz
def convert_to_time_zone(values, feature, parent): """Converts the given datetime to a time zone.<br> <br> convert_to_time_zone(datetime, utcId[, ianaId])<br> <br> datetime -- a datetime to convert<br> utcId -- a required string UTC offset, e.g. 'UTC+01:00' ianaId -- an optional IANA timezone ID, e.g. 'America/Chicago' """ dt = values[0] utcId = values[1] tz = None if len(values) >= 3: ianaId = values[2] if ianaId: tz = QTimeZone(QByteArray(ianaId.encode())) # if we have IANA, we'll try it if not tz.isValid(): tz = None # wasn't available on our system, we guess if not tz: tz = QTimeZone(QByteArray(utcId.encode())) # our fallback position is to use UTC return dt.toTimeZone(tz)