Class: Synthra::Types::DateTime::TimeType

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/date_time/dates.rb

Overview

TimeType type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



106
107
108
# File 'lib/synthra/types/date_time/dates.rb', line 106

def generate_edge(rng, context, args)
  ["00:00:00", "23:59:59", "12:00:00"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



110
111
112
# File 'lib/synthra/types/date_time/dates.rb', line 110

def generate_invalid(rng, context, args)
  [nil, "not a time", 123, [], {}].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ String

Generate random time

Parameters:

Options Hash (args):

  • :format (Symbol)

    time format (:full, :hour_minute, :hour_only)

Returns:

  • (String)

    generated time string



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/synthra/types/date_time/dates.rb', line 89

def generate_random(rng, context, args)
  format_type = args[:format] || :full

  hour = rng.int(0, 23)
  minute = rng.int(0, 59)
  second = rng.int(0, 59)

  case format_type
  when :hour_only
    format("%02d:00:00", hour)
  when :hour_minute
    format("%02d:%02d:00", hour, minute)
  else # :full
    format("%02d:%02d:%02d", hour, minute, second)
  end
end