Class: NoSE::Fields::DateField
Overview
Field holding a date
Constant Summary collapse
- TYPE =
Time is used to store timestamps
Time
Instance Attribute Summary
Attributes inherited from Field
#name, #parent, #primary_key, #size
Class Method Summary collapse
-
.value_from_string(string) ⇒ Time
Parse a DateTime from the provided parameter.
Instance Method Summary collapse
-
#initialize(name, **options) ⇒ DateField
constructor
A new instance of DateField.
-
#random_value ⇒ Time
A random date within 2 years surrounding today.
Methods inherited from Field
#*, #==, #cardinality, #hash, #id, #to_color, #to_s
Methods included from Supertype
Constructor Details
#initialize(name, **options) ⇒ DateField
Returns a new instance of DateField.
215 216 217 |
# File 'lib/nose/model/fields.rb', line 215 def initialize(name, **) super(name, 8, **) end |
Class Method Details
.value_from_string(string) ⇒ Time
Parse a DateTime from the provided parameter
221 222 223 224 225 226 227 228 229 |
# File 'lib/nose/model/fields.rb', line 221 def self.value_from_string(string) # rubocop:disable Style/RedundantBegin begin DateTime.parse(string).to_time rescue ArgumentError raise TypeError end # rubocop:enable Style/RedundantBegin end |
Instance Method Details
#random_value ⇒ Time
A random date within 2 years surrounding today
233 234 235 236 237 238 239 240 241 |
# File 'lib/nose/model/fields.rb', line 233 def random_value prev_year = DateTime.now.prev_year prev_year = prev_year.new_offset(Rational(0, 24)) next_year = DateTime.now.next_year next_year = next_year.new_offset(Rational(0, 24)) Faker::Time.between prev_year, next_year end |