Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/quandl/operation/core_ext/date.rb

Instance Method Summary collapse

Instance Method Details

#end_of_frequency(freq) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/quandl/operation/core_ext/date.rb', line 16

def end_of_frequency(freq)
  case freq.to_sym
  when :daily     then self
  when :weekly    then self.end_of_week
  when :monthly   then self.end_of_month
  when :quarterly then self.end_of_quarter
  when :annual    then self.end_of_year
  when :annually  then self.end_of_year
  else
    self
  end
end

#occurrences_of_frequency(occurrences, freq) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/quandl/operation/core_ext/date.rb', line 41

def occurrences_of_frequency( occurrences, freq )
  # ensure occurrences is an integer
  occurrences = occurrences.to_i
  case freq.try(:to_sym)
  when :weekly    then self - occurrences.weeks
  when :monthly   then self - occurrences.months
  when :quarterly then self - ( occurrences * 3 ).months
  when :annual    then self - occurrences.years
  when :annually  then self - occurrences.years
  else 
    self - occurrences
  end
end

#occurrences_of_frequency_ago(occurrences, freq) ⇒ Object



37
38
39
# File 'lib/quandl/operation/core_ext/date.rb', line 37

def occurrences_of_frequency_ago( occurrences, freq )
  occurrences_of_frequency( occurrences, freq )
end

#occurrences_of_frequency_ahead(occurrences, freq) ⇒ Object



33
34
35
# File 'lib/quandl/operation/core_ext/date.rb', line 33

def occurrences_of_frequency_ahead( occurrences, freq )
  occurrences_of_frequency_ago( occurrences.to_i * -1, freq )
end

#ranging_until(date) ⇒ Object



29
30
31
# File 'lib/quandl/operation/core_ext/date.rb', line 29

def ranging_until( date )
  self..date
end

#start_of_frequency(freq) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/quandl/operation/core_ext/date.rb', line 3

def start_of_frequency(freq)
  case freq.to_sym
  when :daily     then self
  when :weekly    then self.beginning_of_week
  when :monthly   then self.beginning_of_month
  when :quarterly then self.beginning_of_quarter
  when :annual    then self.beginning_of_year
  when :annually  then self.beginning_of_year
  else
    self
  end
end