Sha256: 12748736400e0f005c542a07d2952f433bb20222c4ab22e11294820bacdddff0

Contents?: true

Size: 742 Bytes

Versions: 18

Compression:

Stored size: 742 Bytes

Contents

# frozen_string_literal: true

module Fugit

  DAY_S = (24 * 3600).freeze
  YEAR_S = (365 * DAY_S).freeze

  class << self

    def isostamp(show_date, show_time, show_usec, time)

      t = time || Time.now
      s = StringIO.new

      s << t.strftime('%Y-%m-%d') if show_date
      s << t.strftime('T%H:%M:%S') if show_time
      s << sprintf('.%06d', t.usec) if show_time && show_usec
      s << 'Z' if show_time && time.utc?

      s.string
    end

    def time_to_s(t)

      isostamp(true, true, false, t)
    end

    def time_to_plain_s(t=Time.now, z=true)

      t.strftime('%Y-%m-%d %H:%M:%S') + (z && t.utc? ? ' Z' : '')
    end

    def time_to_zone_s(t=Time.now)

      t.strftime('%Y-%m-%d %H:%M:%S %Z %z')
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
fugit-1.11.1 lib/fugit/misc.rb
fugit-1.11.0 lib/fugit/misc.rb
fugit-1.10.1 lib/fugit/misc.rb
fugit-1.10.0 lib/fugit/misc.rb
fugit-1.9.0 lib/fugit/misc.rb
fugit-1.8.1 lib/fugit/misc.rb
fugit-1.8.0 lib/fugit/misc.rb
fugit-1.7.2 lib/fugit/misc.rb
fugit-1.7.1 lib/fugit/misc.rb
fugit-1.7.0 lib/fugit/misc.rb
fugit-1.6.0 lib/fugit/misc.rb
fugit-1.5.3 lib/fugit/misc.rb
fugit-1.5.2 lib/fugit/misc.rb
fugit-1.5.1 lib/fugit/misc.rb
fugit-1.5.0 lib/fugit/misc.rb
fugit-1.4.5 lib/fugit/misc.rb
fugit-1.4.4 lib/fugit/misc.rb
fugit-1.4.3 lib/fugit/misc.rb