Convert UTC time to specified timezone


I have a log with events from different timezones, where the timestamps are all UTC. I also have the names of the timezones, e.g. "Europe/Madrid". I want to check if the event occurred during office hours in the local time zone, i.e. first convert the timestamp to the local timezone and then check if the converted time is between , for example, 9 and 17. Assuming 7-day work-week. I am looking for something like this:

ruby {
  code =>
  localTime = event.get('timestamp').time.convert( event.get('timeZone') )
  if localTime.hour > 8 && localTime.hour < 18
    event.set('duringOfficeHours', true)

where the convert-function is unknown to me, i.e. what I am looking for. I have seen a reference to a DateTime.in_time_zone method in some forums, but it does not seem to exist in my logstash 5.2.2.

Is this possible to accomplish? Thanks in advance!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.