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



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

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

#occurrences_of_frequency(occurrences, freq) ⇒ Object



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

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



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

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

#occurrences_of_frequency_ahead(occurrences, freq) ⇒ Object



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

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

#ranging_until(date) ⇒ Object



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

def ranging_until(date)
  self..date
end

#start_of_frequency(freq) ⇒ Object



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

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