<commit_before>module GTFS
  class Realtime
    class StopTime < GTFS::Realtime::Model
      many_to_one :trip
      many_to_one :stop

      attr_accessor :actual_arrival_time, :actual_arrival_delay, :actual_departure_time, :actual_departure_delay

      def live?
        actual_arrival_time || actual_arrival_delay || actual_departure_time || actual_departure_delay
      end

      def arrival_time
        actual_arrival_time || scheduled_arrival_time
      end

      def departure_time
        actual_departure_time || scheduled_departure_time
      end

      def scheduled_arrival_time
        self.class.parse_time(self[:arrival_time])
      end

      def scheduled_departure_time
        self.class.parse_time(self[:departure_time])
      end

      def set(val)
        return super(val) unless val.is_a?(GTFS::Realtime::StopTimeUpdate)

        @actual_arrival_time = val.arrival_time
        @actual_arrival_delay = val.arrival_delay
        @actual_departure_time = val.departure_time
        @actual_departure_delay = val.departure_delay
      end

      private

      def self.parse_time(time, date = Date.today)
        # TODO: handle case where date != Date.today
        day_adjustment = 0
        hour = time[0...2].to_i

        # handle timestamps like "24:30"
        if hour > 24
          days = hour / 24
          time[0...2] = (hour % 24).to_s.rjust(2, '0')
        end

        Time.parse(time) + day_adjustment * 60 * 60 * 24
      end
    end
  end
end<commit_msg>Fix bug w/ 24:xx timestamps<commit_after>module GTFS
  class Realtime
    class StopTime < GTFS::Realtime::Model
      many_to_one :trip
      many_to_one :stop

      attr_accessor :actual_arrival_time, :actual_arrival_delay, :actual_departure_time, :actual_departure_delay

      def live?
        actual_arrival_time || actual_arrival_delay || actual_departure_time || actual_departure_delay
      end

      def arrival_time
        actual_arrival_time || scheduled_arrival_time
      end

      def departure_time
        actual_departure_time || scheduled_departure_time
      end

      def scheduled_arrival_time
        self.class.parse_time(self[:arrival_time])
      end

      def scheduled_departure_time
        self.class.parse_time(self[:departure_time])
      end

      def set(val)
        return super(val) unless val.is_a?(GTFS::Realtime::StopTimeUpdate)

        @actual_arrival_time = val.arrival_time
        @actual_arrival_delay = val.arrival_delay
        @actual_departure_time = val.departure_time
        @actual_departure_delay = val.departure_delay
      end

      private

      def self.parse_time(time, date = Date.today)
        # TODO: handle case where date != Date.today
        day_adjustment = 0
        hour = time[0...2].to_i

        # handle timestamps like "24:30"
        if hour >= 24
          days = hour / 24
          time[0...2] = (hour % 24).to_s.rjust(2, '0')
        end

        Time.parse(time) + day_adjustment * 60 * 60 * 24
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07738292925938227, 'fraction_numerical': 0.015941547658585187, 'mean_word_length': 2.4780600461893765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2861301', 'n_tokens_mistral': 1048, 'n_tokens_neox': 963, 'n_words': 193}