QEMU QEMU USB Tablet
 ö    ‹      Å”QoÚ0…ßû+<?ì-¹R:µŽ§Ž �¢TÓ4M“‰�ÄšG¶)t¿~†€J'P·‡i/‰¾÷œ;äM:,¾Ì†èãânŒfÆ£ÂÀçÞ  ]¤íDvº Ã	F¸t®¹X¯×áºjSÀb¥«TÖ™¹�;ŽéÙ¾£ˆ”‚qGÄI§Õ\l�Îè•³’‹è0 ®+VÔ<—J„\T:,m˜iÝø\g6°VèVÖ€’KØ¼ëïÇ�’õjõ
ŠL×�í5¨4_)aCN íïÁ^Yjþ´UÚý�ª|ó]8l¹·J\‰™’E�`§L‰¬
dM–`�¾‚…¥bõ�°�9FL¹¦ß<®Ü®¦„¡Òˆ<ÁïÉäfš¤˜NX%°ÓÌ�gn13ë�W's)øYø¾…ïåÏóÓ–I…ÍŒlœÔõ3
Þâ±ÕL+Û0ïõÒ;(Í1Õ"üµ4Xö"ŒÙí|8Y¤£y	ß–xV÷¯¿1¦3fDíP*�Èœ6O{ë­Ž·õÒ67‡G´7fdQ:L
ÐIò/Òh?ÎÃg}2‰»1g˜w]ç˜ž›9vò›ô¨õƒNDW(Š®»1Bç<^ö>�÷ø‡ûö'†Àîhÿ7¿ ÒAÔAÒ    D   ˆl–Ãa¾”*i?u8 …p/Üiå1hß�þc�¥œp–F^uà¾OçÏƒï¹Î_�uÐb&=LyZËcõÃÍ ´    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'icalendar/tzinfo'

class CalendarSubscriptions

  attr_reader :time_zone

  def initialize(user)
    @user        = user
    @time_zone   = Setting.get('timezone_default')
    @preferences = Service::User::CalendarSubscription::Preferences.with_current_user(@user).execute
  end

  def all
    to_ical @preferences
      .keys
      .map { |object_name| generic_call(object_name) }
      .flatten
  end

  def generic(object_name, method_name = 'all')
    to_ical generic_call(object_name, method_name)
  end

  def generic_call(object_name, method_name = 'all')
    return [] if @preferences[ object_name ].blank?

    sub_class_name = object_name.to_s.capitalize
    object         = "CalendarSubscriptions::#{sub_class_name}".constantize
    instance       = object.new(@user, @preferences[ object_name ], time_zone)

    raise Exceptions::UnprocessableContent, __('An unknown method name was requested.') if object::ALLOWED_METHODS.exclude?(method_name)

    instance.send(method_name)
  end

  def to_ical(events_data)
    cal = Icalendar::Calendar.new
    tz  = ActiveSupport::TimeZone.find_tzinfo(time_zone)

    # https://github.com/zammad/zammad/issues/3989
    # https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.19
    if events_data.any?
      first_start = event_start_utc(events_data.first)

      # Resolve the period from UTC, local times can be ambiguous or missing around DST changes.
      cal.add_timezone tz.ical_timezone(tz.utc_to_local(first_start), tz.period_for_utc(first_start).dst?)
    end

    events_data.each do |event_data|

      cal.event do |e|
        dtstart = DateTime.parse(event_data[:dtstart].to_s)
        dtend   = DateTime.parse(event_data[:dtend].to_s)

        # by design all new/open ticket events are scheduled at midnight:
        # skip adding TZ offset
        if event_data[:type] != 'new_open'
          dtstart = tz.utc_to_local(dtstart)
          dtend = tz.utc_to_local(dtend)
        end

        e.dtstart = Icalendar::Values::DateTime.new(dtstart, 'tzid' => time_zone)
        e.dtend   = Icalendar::Values::DateTime.new(dtend, 'tzid' => time_zone)
        if event_data[:alarm]
          e.alarm do |a|
            a.action  = 'DISPLAY'
            a.summary = event_data[:alarm][:summary]
            a.trigger = event_data[:alarm][:trigger]
          end
        end
        e.summary     = event_data[:summary]
        e.description = event_data[:description]
        e.ip_class    = 'PRIVATE'
      end

    end

    cal.to_ical
  end

  private

  # New/open ticket events carry a local date, all other events the UTC wall clock
  # labelled with the offset of the time zone, which has to be dropped.
  def event_start_utc(event_data)
    return ActiveSupport::TimeZone[time_zone].parse(event_data[:dtstart].to_s).utc if event_data[:type] == 'new_open'

    DateTime.parse(event_data[:dtstart].to_s).change(offset: '+00:00')
  end

end
  6   ˆl–Ü4ý('ÜZÔâ€vã"¸Å£�þ^yåœl�É#N¶ãR¹üÿÑƒ^kÐÄÎ ˆ    H¤œC�‘ûlðp·j    Ÿè%ò‹–QÎ  h  YARB      h         2   ¤     l  )#i‹+ÿ+ÿ+€   3#€+‰# ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿ)#i‹-ý-ý‰ÿ	      7'		+ÿ+‰' ÿÿÿÿÿÿÿÿ)#i‹/û/û‡ý	       9)-ý-‡) ÿÿÿÿÿÿÿÿ)#i	‹1ù1ù…û	       9)/û/	…) ÿÿÿÿÿÿÿÿk'‹K÷K÷ƒ