class ActsAsScd::Period
Attributes
end[R]
start[R]
Public Class Methods
date(date)
click to toggle source
# File lib/acts_as_scd/period.rb, line 52 def self.date(date) DateValue[date].value end
date_to_s(date)
click to toggle source
# File lib/acts_as_scd/period.rb, line 56 def self.date_to_s(date) DateValue[date].to_s end
new(from, to)
click to toggle source
# File lib/acts_as_scd/period.rb, line 68 def initialize(from, to) @start = Period.date(from || START_OF_TIME) @end = Period.date(to || END_OF_TIME) end
Public Instance Methods
current?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 122 def current? @end == END_OF_TIME end
empty?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 102 def empty? @start >= @end end
from()
click to toggle source
# File lib/acts_as_scd/period.rb, line 61 def from @start end
future_limited?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 110 def future_limited? @end < END_OF_TIME end
includes?(date)
click to toggle source
# File lib/acts_as_scd/period.rb, line 75 def includes?(date) date = Period.date(date) @start <= date && date < @end end
initial?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 118 def initial? @start == START_OF_TIME end
limited?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 114 def limited? past_limited? || future_limited? end
past_limited?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 106 def past_limited? @start > START_OF_TIME end
reference_date()
click to toggle source
# File lib/acts_as_scd/period.rb, line 126 def reference_date if @start <= START_OF_TIME if @end >= END_OF_TIME DateValue[Date.today].value else DateValue[DateValue[@end].to_date - 1].value end else @start end end
to()
click to toggle source
# File lib/acts_as_scd/period.rb, line 64 def to @end end
to_s(options={})
click to toggle source
# File lib/acts_as_scd/period.rb, line 82 def to_s(options={}) if @start<=START_OF_TIME if @end>=END_OF_TIME options[:always] || I18n.t(:"scd.period.always") || '-' else "#{options[:until] || I18n.t(:"scd.period.until") || 'to'} #{Period.date_to_s(@end)}" end else if @end>=END_OF_TIME "#{options[:since] || I18n.t(:"scd.period.from") || 'since'} #{Period.date_to_s(@start)}" else [Period.date_to_s(@start), options[:between] || I18n.t(:"scd.period.between") || '-', Period.date_to_s(@end)].compact*' ' end end end
valid?()
click to toggle source
# File lib/acts_as_scd/period.rb, line 98 def valid? @start < @end end