Sha256: bc815ec6975d9299c78518dbd0aee2b957656d58b467df47b97dee59e669a8fb

Contents?: true

Size: 1.05 KB

Versions: 196

Compression:

Stored size: 1.05 KB

Contents

module Origen
  module Utility
    # Collection of methods related to time and dates
    module TimeAndDate
      # Returns the current time in this format:
      # 05-Jun-2010 10:05AM
      def time_now(options = {})
        options = { underscore:   false,
                    format:       :human,
                    include_time: true
        }.merge(options)

        # Nice description of time format options
        # http://wesgarrison.us/2006/03/12/ruby-strftime-options-for-date-formatting/

        if options[:format] == :human
          Time.now.strftime('%d-%b-%Y %H:%M%p')
        elsif options[:format] == :universal
          time = options[:underscore] ? Time.now.strftime('_%H_%M') : Time.now.strftime('%H%M')
          date = options[:underscore] ? Time.now.strftime('%Y_%m_%d') : Time.now.strftime('%Y%m%d')
          options[:include_time] ? date + time : date
        elsif options[:format] == :timestamp
          Time.now.strftime('%Y%m%d%H%M%S')
        else
          fail 'Unknown date format requested!'
        end
      end
    end
  end
end

Version data entries

196 entries across 196 versions & 1 rubygems

Version Path
origen-0.60.7 lib/origen/utility/time_and_date.rb
origen-0.60.6 lib/origen/utility/time_and_date.rb
origen-0.60.5 lib/origen/utility/time_and_date.rb
origen-0.60.4 lib/origen/utility/time_and_date.rb
origen-0.60.3 lib/origen/utility/time_and_date.rb
origen-0.60.2 lib/origen/utility/time_and_date.rb
origen-0.60.1 lib/origen/utility/time_and_date.rb
origen-0.60.0 lib/origen/utility/time_and_date.rb
origen-0.59.8 lib/origen/utility/time_and_date.rb
origen-0.59.7 lib/origen/utility/time_and_date.rb
origen-0.59.6 lib/origen/utility/time_and_date.rb
origen-0.59.5 lib/origen/utility/time_and_date.rb
origen-0.59.4 lib/origen/utility/time_and_date.rb
origen-0.59.3 lib/origen/utility/time_and_date.rb
origen-0.59.2 lib/origen/utility/time_and_date.rb
origen-0.59.1 lib/origen/utility/time_and_date.rb
origen-0.59.0 lib/origen/utility/time_and_date.rb
origen-0.58.0 lib/origen/utility/time_and_date.rb
origen-0.57.2 lib/origen/utility/time_and_date.rb
origen-0.57.1 lib/origen/utility/time_and_date.rb