TimeCompact
Displays time compactly.
for example:
# default locale
2014/1/2 # when other year.
1/2 # when same year.
8:16 # when same day.
# 日本語ロケール
2014年1月2日 # 違う年の時
1月2日 # 同じ年の時
8時16分 # 同じ日の時
Installation
Add this line to your application's Gemfile:
gem 'time_compact'
And then execute:
$ bundle
Or install it yourself as:
$ gem install time_compact
Usage
require 'time_compact'
include TimeCompact
time_compact Time.new(2014, 1, 1, 0, 0, 0) # => 5/2
In rails
<%= time_compact @post.created_at %>
You can customize the format.
# config/locales/en.yml:
en:
time_compact:
same_year: '%{month}/%{day}'
same_month: '%{month}/%{day}'
same_day: '%{hour}:%{min}'
same_hour: '%{min} min'
other: '%{year}/%{month}/%{day}'
Contributing
- Fork it ( https://github.com/komagata/time_compact/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request