<commit_before>require 'delegate'

# Delegator with some handy shortcuts
class Event < SimpleDelegator
  # Time it starts at day, or '...'
  def start_time_f day
    #puts "start #{start_time} : #{start_time.class} #{start_time.to_date} #{day}"
    if dtstart.class == Date
      # whole day
      ""
    elsif start_time.to_date == day.to_date
      start_time.strftime('%H:%M')
    else
      "..."
    end
  end

  # Time it finishes at day, or '...'
  def finish_time_f day
    if dtend.class == Date
      # whole day
      ""
    elsif finish_time.to_date == day.to_date
      finish_time.strftime('%H:%M')
    else
      return "..."
    end
  end

  # Time it finishes and or starts at day, or '...'
  def time_f day
    start = start_time_f day
    finish = finish_time_f day
    if start == finish && start == ""
      # whole day
      ""
    elsif start == finish && start == "..."
      "..."
    else
      "#{start_time_f day} - #{finish_time_f day}"
    end
  end

  # Date and time from and to
  def from_to_f
    return "#{dtstart.to_datetime.strftime("%d.%m. %H:%M")} - #{dtend.to_datetime.strftime("%d.%m. %H:%M")}"
  end

  # Create DateTime from yyyymmdd + h + m .
  def self.start_time_from_params params
    start_day = Date.parse(params['start_day'])
    if !params[:start_time]
      return start_day
    end

    hour, minute = params[:start_time].match(/(\d\d):(\d\d)/)[1,2]
    start_time = DateTime.new(start_day.year,
      start_day.month, start_day.day, hour.to_i, minute.to_i)
  end

  def self.start_date_from params
    Date.parse(params['start_day'])
  end


  def update params
    begin
      hour, minute = params[:start_time].match(/(\d\d):(\d\d)/)[1,2]
      start_day = Date.parse(params['start_day'])
      start_time = DateTime.new(start_day.year,
        start_day.month, start_day.day, hour.to_i, minute.to_i)
      self.dtstart = start_time
      minutes = EventParamHelper.duration params['duration']
      self.dtend = start_time + minutes
    rescue
      STDERR.puts "event#update params: problems with (up)date."
    end
    
    self.summary     = params['summary']     if params['summary']
    self.description = params['description'] if params['description']
    self.location    = params['location']    if params['location']
  end

  # Create a new event from params as given by new_event form of kalindar.<commit_msg>fix event#update<commit_after>require 'delegate'

# Delegator with some handy shortcuts
class Event < SimpleDelegator
  # Time it starts at day, or '...'
  def start_time_f day
    #puts "start #{start_time} : #{start_time.class} #{start_time.to_date} #{day}"
    if dtstart.class == Date
      # whole day
      ""
    elsif start_time.to_date == day.to_date
      start_time.strftime('%H:%M')
    else
      "..."
    end
  end

  # Time it finishes at day, or '...'
  def finish_time_f day
    if dtend.class == Date
      # whole day
      ""
    elsif finish_time.to_date == day.to_date
      finish_time.strftime('%H:%M')
    else
      return "..."
    end
  end

  # Time it finishes and or starts at day, or '...'
  def time_f day
    start = start_time_f day
    finish = finish_time_f day
    if start == finish && start == ""
      # whole day
      ""
    elsif start == finish && start == "..."
      "..."
    else
      "#{start_time_f day} - #{finish_time_f day}"
    end
  end

  # Date and time from and to
  def from_to_f
    return "#{dtstart.to_datetime.strftime("%d.%m. %H:%M")} - #{dtend.to_datetime.strftime("%d.%m. %H:%M")}"
  end

  # Create DateTime from yyyymmdd + h + m .
  def self.start_time_from_params params
    start_day = Date.parse(params['start_day'])
    if !params[:start_time]
      return start_day
    end

    hour, minute = params[:start_time].match(/(\d\d):(\d\d)/)[1,2]
    start_time = DateTime.new(start_day.year,
      start_day.month, start_day.day, hour.to_i, minute.to_i)
  end

  def self.start_date_from params
    Date.parse(params['start_day'])
  end


  def update params
    begin
      hour, minute = params['start_time'].match(/(\d\d):(\d\d)/)[1,2]
      start_day = Date.parse(params['start_day'])
      start_time = DateTime.new(start_day.year,
        start_day.month, start_day.day, hour.to_i, minute.to_i)
      self.dtstart = start_time
      minutes = EventParamHelper.duration params['duration']
      self.dtend = start_time + Rational(minutes, 1440)
    rescue => e
      STDERR.puts "event#update params: problems with (up)date #{e.message}"
    end
    
    self.summary     = params['summary']     if params['summary']
    self.description = params['description'] if params['description']
    self.location    = params['location']    if params['location']
  end

  # Create a new event from params as given by new_event form of kalindar.
{'fraction_non_alphanumeric': 0.13578441612701064, 'fraction_numerical': 0.0025067892208063504, 'mean_word_length': 2.6944444444444446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1266804', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1611, 'n_words': 395}