class NoSE::Fields::DateField
Field
holding a date
Constants
- TYPE
Time
is used to store timestamps
Public Class Methods
new(name, **options)
click to toggle source
Calls superclass method
NoSE::Fields::Field::new
# File lib/nose/model/fields.rb, line 226 def initialize(name, **options) super(name, 8, **options) end
value_from_string(string)
click to toggle source
Parse a DateTime from the provided parameter @return [Time]
# 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
Public Instance Methods
random_value()
click to toggle source
A random date within 2 years surrounding today @return [Time]
# 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