time_in_words

time_in_words

All code stolen from lucky framework time_helpers, but added the Chinese support.

Only EN and ZH_CN supported for now, PR is welcome.

The locale name will follow name in this file.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      time_in_words:
        github: crystal_china/time_in_words
    
  2. Run shards install

Usage

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.

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/zw963/time_in_words/fork)
  2. Run make to ensure spec passed.
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Run make again to ensure spec passed.
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

Contributors

Repository

time_in_words

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 0
  • 10 days ago
  • April 29, 2025
License

MIT License

Links
Synced at

Fri, 23 May 2025 07:57:02 GMT

Languages