{"record":{"id":"a7907898edea3c0e","repo":"faker-ruby/faker","slug":"invalid-period","errorCode":null,"errorMessage":"invalid period","messagePattern":"invalid period","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faker/default/time.rb","lineNumber":129,"sourceCode":"      #     #=> \"14 Oct 07:44\"\n      #\n      # @faker.version 1.5.0\n      def backward(days: 365, period: :all, format: nil)\n        time_with_format(date_with_random_time(Faker::Date.backward(days: days), period), format)\n      end\n\n      private\n\n      def date_with_random_time(date, period)\n        ::Time.local(date.year, date.month, date.day, hours(period), minutes, seconds)\n      end\n\n      def time_with_format(time, format)\n        format.nil? ? time : I18n.localize(time, format: format)\n      end\n\n      def hours(period)\n        raise ArgumentError, 'invalid period' unless TIME_RANGES.key? period\n\n        sample(TIME_RANGES[period].to_a)\n      end\n\n      def minutes\n        seconds\n      end\n\n      def seconds\n        sample((0..59).to_a)\n      end\n\n      def get_time_object(time)\n        time = ::Time.parse(time) if time.is_a? String\n        time = time.to_time if time.respond_to?(:to_time)\n        time\n      end\n    end","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/time.rb#L111-L147","documentation":"Raised by the private hours helper in Faker::Time, reached from every public generator that takes period: — between_dates, forward, and backward — when period is not a key of TIME_RANGES. Valid symbols are exactly :all, :day, :night, :morning, :afternoon, :evening, :midnight; the lookup is a Hash key comparison, so strings ('morning'), symbols with typos (:morn), or synonyms like :dawn/:dusk/:noon raise ArgumentError.","triggerScenarios":"Faker::Time.forward(days: 5, period: 'morning') (string instead of symbol), period: :dusk, or period: :am raises 'invalid period'; period: :morning or omitting period (defaults to :all) works. between_dates(from: ..., to: ..., period: :noon) raises too.","commonSituations":"Passing period values read from params/config where they arrive as strings; using natural synonyms (dawn/dusk) that TIME_RANGES does not define; copying the option name from another library (e.g. Date naming) rather than Faker's list.","solutions":["Pass one of :all, :day, :night, :morning, :afternoon, :evening, :midnight as a Symbol.","Convert config/param strings: period: params[:period].to_sym (after whitelist-checking).","Pick the closest defined range for synonyms you want (e.g. use :morning for 'dawn' since it starts at 6h, or :midnight for 0..4)."],"exampleFix":"# before\nFaker::Time.between_dates(from: from_d, to: to_d, period: params[:period]) # 'morning' String -> ArgumentError\n\n# after\nperiod = params[:period].presence&.to_sym || :all\nFaker::Time.between_dates(from: from_d, to: to_d, period: period)","handlingStrategy":"validation","validationCode":"VALID_PERIODS = %i[all day night morning afternoon evening midnight].freeze\nperiod = period.to_sym if period.is_a?(String)\nperiod = :all unless VALID_PERIODS.include?(period)\nFaker::Time.between_dates(from: from_d, to: to_d, period: period)","typeGuard":"def valid_faker_period?(period)\n  Faker::Time::TIME_RANGES.key?(period)\nend","tryCatchPattern":"begin\n  Faker::Time.forward(days: days, period: period)\nrescue ArgumentError\n  Faker::Time.forward(days: days) # default :all\nend","preventionTips":["period must be a Symbol from TIME_RANGES; convert strings with to_sym after whitelisting.","Use Faker::Time::TIME_RANGES.key? as the source of truth, not a copied list.","No dawn/dusk/am/pm aliases exist — map synonyms to the nearest defined range."],"tags":["faker","argument-error","enum-whitelist","time-generation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"cca4184947e09fdd02afb8b89d25a9c8ebc7274e","analyzedAt":"2026-08-21T16:25:39.145Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}