time_in_words

Version, currently master branch1 version
  • master branchlatestSep 18, 2026

github.com/crystal-china/time_in_words

No description declared in shard.yml.

1 stars
1 dependent
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  time_in_words:
    github: crystal-china/time_in_words
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.16.0
License
MIT
Author
Billy.Zheng

Dependencies

This version declares no dependencies.

README

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