<commit_before>require "hour/version"

module Hour
  class Hour
    attr_reader :hours, :minutes, :to_seconds, :to_days, :to_hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time

    def initialize(hours, minutes = 0)
      hours, minutes = hours.split(':') if hours.is_a? String
      @minutes = [0, minutes.to_i, 59].sort[1]          # Constrains assignment to the middle value, w/o the #Clamp method
      @to_a = [@hours = hours.to_i, @minutes]
      @to_s = "#{'%02d' % @hours}:#{'%02d' % @minutes}" # Formats single-digits such that '1' will be '01'
      @to_seconds = (@hours * 60 + @minutes) * 60
      @to_days = @hours / 24 || 0
      @to_hours_less_days = @hours - 24 * @to_days
      @to_formatted_s = "#{@to_days} day#{'s' unless @to_days == 1}, " +
                        "#{@to_hours_less_days} hour#{'s' unless @to_hours_less_days == 1}, " +
                        "#{@minutes} minute#{'s' unless @minutes == 1}"
      @to_time = Time.new(
        0,                   #year
        1,                   #month
        1 + @to_days,        #day
        @to_hours_less_days, #hour
        @minutes,            #minute
        0,                   #second
        0                    #UTC    #TODO: gracefully handle both the new Time.zone format and the deprecated UTC
      )
    end

    def self.from_time(time_obj)
      hour = time_obj.hour + (time_obj.day - 1) * 24 if time_obj.year == 0 # Note that we expect Time input to be year 0 and day to take 1 as 24 hours, so that a day value of 2 and an hour value of 4 will be interpreted as "28 hours".
      self.new(hour || time_obj.hour, time_obj.min)
    end

  end
end<commit_msg>on_this_day instance method added<commit_after>  require "hour/version"

module Hour
  class Hour
    attr_reader :hours, :minutes, :to_seconds, :days, :hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time

    def initialize(hours, minutes = 0)
      hours, minutes = hours.split(':') if hours.is_a? String
      @minutes = [0, minutes.to_i, 59].sort[1]          # Constrains assignment to the middle value, w/o the #Clamp method
      @to_a = [@hours = hours.to_i, @minutes]
      @to_s = "#{'%02d' % @hours}:#{'%02d' % @minutes}" # Formats single-digits such that '1' will be '01'
      @to_seconds = (@hours * 60 + @minutes) * 60
      @days = @hours / 24 || 0
      @hours_less_days = @hours - 24 * @days
      @to_formatted_s = "#{@days} day#{'s' unless @days == 1}, " +
                        "#{@hours_less_days} hour#{'s' unless @hours_less_days == 1}, " +
                        "#{@minutes} minute#{'s' unless @minutes == 1}"
      @to_time = Time.new(
        0,                   #year
        1,                   #month
        1 + @days,        #day
        @hours_less_days, #hour
        @minutes,            #minute
        0,                   #second
        0                    #UTC    #TODO: handle both Time.zone format & deprecated UTC default?
      )
    end

    def on_this_day(day_elect = Time.now)
      day_elect.change(day:  day_elect.day + @days,
                       hour: @hours_less_days,
                       min:  @minutes)
    end

    def self.from_time(time_obj)
      hour = time_obj.hour + (time_obj.day - 1) * 24 if time_obj.year == 0 # Note that we expect Time input to be year 0, month 1 (minimum values). Incrementing day to a value above 1 means "add 24 * x hours", where x is the number of days above 1, so that a day value of 1 and hour value of 4 will be interpreted as "4 hours", whereas a day value of 2 and an hour value of 4 will be interpreted as "28 hours".
      self.new(hour || time_obj.hour, time_obj.min)
    end


  end
end
{'fraction_non_alphanumeric': 0.12195788898003829, 'fraction_numerical': 0.02378999179655455, 'mean_word_length': 2.0869198312236286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3768820', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1182, 'n_words': 380}