Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 23 lines (19 sloc) 0.486 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/env ruby
# http://redd.it/16z9oj
# - UziMonkey

module TimeFormatter
  def l; "%03d" % (usec / 1000); end
  def s; "%02d" % sec; end
  def m; "%02d" % min; end
  def h; hour % 12; end
  def H; hour; end
  def c; hour < 12 ? 'AM' : 'PM'; end
  def d; day; end
  def M; month; end
  def y; year; end

  REGEXP = Regexp.union instance_methods.map{|m| "%#{m}" }

  def format(s)
    s.gsub(REGEXP) {|k| send k[-1] }
  end
end

puts Time.now.extend(TimeFormatter).format(ARGV[0])
Something went wrong with that request. Please try again.