Class: NoSE::Fields::DateField

Inherits:
Field show all
Defined in:
lib/nose/model/fields.rb

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

Instance Method Summary collapse

Methods inherited from Field

#*, #==, #cardinality, #hash, #id, #to_color, #to_s

Methods included from Supertype

included

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, **options)
  super(name, 8, **options)
end

Class Method Details

.value_from_string(string) ⇒ Time

Parse a DateTime from the provided parameter

Returns:



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_valueTime

A random date within 2 years surrounding today

Returns:



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