sonic-pi
https://github.com/sonic-pi-net/sonic-pi
C++
Code. Music. Live.
Time#to_formatted_s
Converts to a formatted string. See DATE_FORMATS for builtin formats.
This method is aliased to <tt>to_s</tt>.
time = Time.now # => Thu Jan 18 06:10:17 CST 2007
time.to_formatted_s(:time) # => "06:10"
time.to_s(:time) # => "06:10"
time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
time.to_formatted_s(:number) # => "20070118061017"
time.to_formatted_s(:short) # => "18 Jan 06:10"
time.to_formatted_s(:long) # => "January 18, 2007 06:10"
time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10"
time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
time.to_formatted_s(:iso8601) # => "2007-01-18T06:10:17-06:00"
== Adding your own time formats to +to_formatted_s+
You can add your own formats to the Time::DATE_FORMATS hash.
Use the format name as the hash key and either a strftime string
or Proc instance that takes a time argument as the value.
# config/initializers/time_formats.rb
Time::DATE_FORMATS[:month_and_year] = '%B %Y'
Time::DATE_FORMATS[:short_ordinal] = ->(time) { time.strftime("%B #{time.day.ordinalize}") }Edit
git clone [email protected]:sonic-pi-net/sonic-pi.git
cd sonic-pi
open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/time/conversions.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Time-to_formatted_s-for-pr
# Commit to gitgit add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/time/conversions.rbgit commit -m "better docs for Time#to_formatted_s"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Time-to_formatted_s-for-pr
hub pull-request
# Celebrate!