Sure. I recommend DateTimeFormatter.ofPattern(). But I would move the complexity to a project script module with a DateTimeFormatter instance with your preferred pattern saved as a top level variable. Like so, perhaps:
from java.time import ZoneId
from java.time.format import DateTimeFormatter
defaultFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm")
def zonedFormat(ts, zoneid, format=None):
formatter = defaultFormatter if format is None else DateTimeFormatter.ofPattern(format)
return ts.toInstant().atZone(ZoneId.of(zoneid)).format(formatter)
If that is a project script named zoneHelper
, then your transform becomes just:
return zoneHelper.zonedFormat(value, self.session.props.timeZoneId)
Use the optional third argument to supply a different format pattern.