Giter Site home page Giter Site logo

Comments (3)

michaeldv avatar michaeldv commented on August 18, 2024

Hi,

What is your version of Rails/ActiveSupport? What exactly doesn't print correctly? Please let me know how I could to reproduce the issue.

Michael

from awesome_print.

0xradical avatar 0xradical commented on August 18, 2024

Hi Michael, I'm using Rails 3.1.3. On my machine, with awesome_print turned on:

(main):0 > Date.new
#<Date:0x7fc6316e0ee8
    @__ca__ = {},
    @of = 0,
    @sg = 2299161,
    attr_reader :ajd = -0.5
>
(main):0 > Date.new.inspect
"Mon, 01 Jan -4712"
(main):0 > Time.new
2011-12-02 13:43:02 -0200 # greenish
(main):0 > Time.new.inspect
"2011-12-02 13:43:31 -0200"
(main):0 > ActiveSupport::TimeZone.new('Eastern Time (US & Canada)').now
Fri, 02 Dec 2011 10:39:37 EST -05:00 #greenish
(main):0 > ActiveSupport::TimeZone.new('Eastern Time (US & Canada)').now.inspect
"Fri, 02 Dec 2011 10:44:02 EST -05:00"

I made this monkey-patch and it worked as expected afterwards:

  module AwesomePrint
    module TimeClasses

      def self.included(base)
        base.send :alias_method, :cast_without_time_classes, :cast
        base.send :alias_method, :cast, :cast_with_time_classes
      end

      def cast_with_time_classes(object,type)
        cast = cast_without_time_classes(object,type)
        if object.is_a?(::Date)
          cast = :date
        end
        cast
      end

      def awesome_date(object)
        colorize(object.inspect, :time)
      end

    end
  end

  AwesomePrint::Formatter.send(:include,AwesomePrint::TimeClasses)

Hope that helped

from awesome_print.

michaeldv avatar michaeldv commented on August 18, 2024

Thanks! Looks like the latest ActiveSupport sticks in instance vars into the Date object so the date gets formatted as an object. Changing:

17: if object.is_a?(::ActiveSupport::TimeWithZone)
to
17: if object.is_a?(::ActiveSupport::TimeWithZone) || object.is_a?(::Date)

in ext/active_support.rb seems to fix it. I'm going to add a spec and make it part of 1.0.2 release.

Thanks again ;-)

Michael

from awesome_print.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.