All code stolen from lucky framework time_helpers, but added the Chinese support.
Only EN and ZH_CN supported for now, PR is welcome.
-
Add the dependency to your
shard.yml
:dependencies: time_in_words: github: crystal_china/time_in_words
-
Run
shards install
require "time_in_words"
alias TimeHelper = TimeInWords::Helpers(TimeInWords::I18n::ZH_CN)
TimeHelper.from(past_time: Time.local - 13.months) # => "大约一年前"
from_time = Time.local
TimeHelper.distance(from: from_time, to: from_time + 50.minutes) # => "大约一个小时前"
TimeHelper.distance(from: from_time, to: from_time + 35.minutes) # => "35 分钟前"
span = 4.minutes
TimeHelpers.distance(span: span) # => "四分钟前"
Check the time_in_words_en_spec.cr for usage about English time words.
TODO: Write development instructions here
- Fork it (https://github.com/zw963/time_in_words/fork)
- Run
make
to ensure spec passed. - Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Run
make
again to ensure spec passed. - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Billy.Zheng - creator and maintainer