Class: Pyk::DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/pyk/date_time.rb

Class Method Summary collapse

Class Method Details

.end_of_day(date_object) ⇒ Object

Pyk::DateTime.end_of_day(date_object)



4
5
6
# File 'lib/pyk/date_time.rb', line 4

def self.end_of_day(date_object)
  Date.new(date_object.year, date_object.month, date_object.day).to_time + 86340
end

.get_end_date_from_tag(tag) ⇒ Object

Pyk::Date.get_end_date_from_tag(tag)



26
27
28
29
30
31
32
33
34
# File 'lib/pyk/date_time.rb', line 26

def self.get_end_date_from_tag(tag)
  if tag == "last_month"
    lm = (Time.now - 1.month)
    sdt = Date.new(lm.strftime("%Y").to_i, lm.strftime("%m").to_i, 1)
    ed = (sdt + 1.month - 1.day).to_time
  else #if tag == "this_month" or tag == "last_30" or tag == "last_7"
    return Time.now
  end
end

.get_start_date_from_tag(tag, default_year = nil, default_month = nil) ⇒ Object

Pyk::Date.get_start_date_from_tag(tag, default_year=nil, default_month=nil)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pyk/date_time.rb', line 9

def self.get_start_date_from_tag(tag, default_year=nil, default_month=nil)
  if tag == "this_month"
    return Date.new(Time.now.strftime("%Y").to_i, Time.now.strftime("%m").to_i, 1).to_time
  elsif tag == "last_30"
    return (Date.today - 30).to_time
  elsif tag == "last_month"
    lm = (Time.now - 1.month)
    sdt = Date.new(lm.strftime("%Y").to_i, lm.strftime("%m").to_i, 1)
    return Date.new(lm.strftime("%Y").to_i, lm.strftime("%m").to_i, 1).to_time
  elsif tag == "last_7"
    return (Date.today - 7).to_time
  else
    return Date.new(default_year, default_month, 1).to_time
  end
end