Class: Date

Inherits:
Object show all
Defined in:
lib/spiderfw/utils/monkey/date_time.rb,
lib/spiderfw/utils/json.rb

Overview

A couple of monkey-patched utility methods. – (partially from Rails)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.lparse(string, format = :default, locale = nil, options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 25

def self.lparse(string, format = :default, locale=nil, options={})
    locale ||= Spider.locale
    options[:return] = self <= DateTime ? :datetime : :date 
    Spider::I18n.parse_dt(locale, string, format, options)
end

Instance Method Details

#as_jsonObject



2
3
4
# File 'lib/spiderfw/utils/json.rb', line 2

def as_json
    strftime("%Y-%m-%d")
end

#cloneObject

Custom clone for home_run gem



32
33
34
35
36
37
38
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 32

def clone
    if self.respond_to?(:hour)
        self.class.civil(self.year, self.month, self.day, self.hour, self.min, self.sec, self.offset)
    else
        self.class.civil(self.year, self.month, self.day)
    end
end

#lformat(format = :default, locale = nil, options = {}) ⇒ Object



20
21
22
23
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 20

def lformat(format = :default, locale=nil, options={})
    locale ||= Spider.locale
    Spider::I18n.localize(locale, self, format, options)
end

#to_dateObject



16
17
18
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 16

def to_date
    ::Date.new(year, month, day)
end

#to_gm_timeObject

Converts to a Time object in the GMT timezone.



7
8
9
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 7

def to_gm_time
    to_time(new_offset, :gm)
end

#to_local_timeObject

Converts to a Time object in the local timezone.



12
13
14
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 12

def to_local_time
    conv_to_time(new_offset(DateTime.now.offset), :local)
end