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.
226 227 228 |
# File 'lib/nose/model/fields.rb', line 226 def initialize(name, **) super(name, 8, **) end |
Class Method Details
.value_from_string(string) ⇒ Time
Parse a DateTime from the provided parameter
232 233 234 235 236 237 238 239 240 |
# File 'lib/nose/model/fields.rb', line 232 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
244 245 246 247 248 249 250 251 252 |
# File 'lib/nose/model/fields.rb', line 244 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_dates from: prev_year, to: next_year end |