Sha256: acfe067d298fc97ab6d819133c710a6146a941351476d0151bea1fc8994285a8

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

# A couple of monkey-patched utility methods.
#--
# (partially from Rails)
class Date

    # Converts to a Time object in the GMT timezone.
    def to_gm_time
        to_time(new_offset, :gm)
    end

    # Converts to a Time object in the local timezone.
    def to_local_time
        to_time(new_offset(DateTime.now.offset), :local)
    end
    
    def lformat(format = :default, locale=nil, options={})
        locale ||= Spider.locale
        Spider::I18n.localize(locale, self, format, options)
    end
    
    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

    private
    def to_time(dest, method)
        #Convert a fraction of a day to a number of microseconds
        usec = (dest.sec_fraction * 60 * 60 * 24 * (10**6)).to_i
        Time.send(method, dest.year, dest.month, dest.day, dest.hour, dest.min,
        dest.sec, usec)
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spiderfw-0.5.9 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.7 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.6 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.5 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.4 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.3 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.2 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5.1 lib/spiderfw/utils/monkey/date_time.rb
spiderfw-0.5 lib/spiderfw/utils/monkey/date_time.rb