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.



226
227
228
# File 'lib/nose/model/fields.rb', line 226

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:



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_valueTime

A random date within 2 years surrounding today

Returns:



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