Class: Date
- 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
- #as_json ⇒ Object
-
#clone ⇒ Object
Custom clone for home_run gem.
- #lformat(format = :default, locale = nil, options = {}) ⇒ Object
- #to_date ⇒ Object
-
#to_gm_time ⇒ Object
Converts to a Time object in the GMT timezone.
-
#to_local_time ⇒ Object
Converts to a Time object in the local timezone.
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, ={}) locale ||= Spider.locale [:return] = self <= DateTime ? :datetime : :date Spider::I18n.parse_dt(locale, string, format, ) end |
Instance Method Details
#as_json ⇒ Object
2 3 4 |
# File 'lib/spiderfw/utils/json.rb', line 2 def as_json strftime("%Y-%m-%d") end |
#clone ⇒ Object
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, ={}) locale ||= Spider.locale Spider::I18n.localize(locale, self, format, ) end |
#to_date ⇒ Object
16 17 18 |
# File 'lib/spiderfw/utils/monkey/date_time.rb', line 16 def to_date ::Date.new(year, month, day) end |
#to_gm_time ⇒ Object
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_time ⇒ Object
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 |