All Projects → mamantoha → humanize_time

mamantoha / humanize_time

Licence: MIT License
Adds the humanize method to reports the approximate distance in time between two Time. humanize supports i18n translations too so it can be used in internationalized apps.

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to humanize time

Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-15%)
Mutual labels:  i18n, time
Moment.php
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Stars: ✭ 900 (+4400%)
Mutual labels:  i18n, time
vue-translated
Internationalization (i18n) and localization (l10n) library for Vue.js v2.
Stars: ✭ 19 (-5%)
Mutual labels:  i18n, time
archived-bot
A Discord music bot serving music in over 3 million discord servers
Stars: ✭ 496 (+2380%)
Mutual labels:  i18n
translation
👅 Translations (symfony/translation) to Nette Framework (@nette)
Stars: ✭ 55 (+175%)
Mutual labels:  i18n
rktree.cljc
Trees where leaves are located both in time and space
Stars: ✭ 15 (-25%)
Mutual labels:  time
macos-receiver
A MacOS TabBar (StatusBar) application that securely receives one-time passwords (OTPs) that you tapped in Raivo for iOS.
Stars: ✭ 44 (+120%)
Mutual labels:  time
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (+45%)
Mutual labels:  time
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (+105%)
Mutual labels:  time
kick-off-web-scraping-python-selenium-beautifulsoup
A tutorial-based introduction to web scraping with Python.
Stars: ✭ 18 (-10%)
Mutual labels:  time
GetCurrency
List all currencies available in NSLocale programmatically using swift 3
Stars: ✭ 18 (-10%)
Mutual labels:  i18n
acts as localized
Localization accessor mechanism for AR models
Stars: ✭ 12 (-40%)
Mutual labels:  i18n
react-put
A flexible formatter and i18n interface for React.
Stars: ✭ 23 (+15%)
Mutual labels:  i18n
extract-react-intl
Extract react-intl messages
Stars: ✭ 18 (-10%)
Mutual labels:  i18n
Yort.Ntp
A cross platform NTP client library for .Net platforms. Allows you to easily retrieve an accurate, current date & time from internet NTP servers.
Stars: ✭ 35 (+75%)
Mutual labels:  time
cftime
Time-handling functionality from netcdf4-python.
Stars: ✭ 53 (+165%)
Mutual labels:  time
MD DS3231
DS3231 Real Time Clock Library
Stars: ✭ 29 (+45%)
Mutual labels:  time
address-formatter
Universal international address formatter in Javascript
Stars: ✭ 65 (+225%)
Mutual labels:  i18n
v-page
A simple pagination bar, including length Menu, i18n support, based on Vue2.x
Stars: ✭ 85 (+325%)
Mutual labels:  i18n
time-api
Nodejs API for Wobbly Time Tracker for the Teams
Stars: ✭ 24 (+20%)
Mutual labels:  time

humanize_time

Crystal CI GitHub release Commits Since Last Release License

Reports the approximate distance in time between two Time objects. Pass include_seconds: true if you want more detailed approximations when distance < 1 min, 29 secs.

humanize_time supports i18n translations too so it can be used in internationalized apps.

humanize_time implementation is heavily inspired by (read: stolen) distance_of_time_in_words method. Many thanks to Rails community!

Distances are reported based on the following table:

Value Result
0 <-> 29 secs less than a minute
30 secs <-> 1 min, 29 secs 1 minute
1 min, 30 secs <-> 44 mins, 29 secs [2..44] minutes
44 mins, 30 secs <-> 89 mins, 29 secs about 1 hour
89 mins, 30 secs <-> 23 hrs, 59 mins, 29 secs about [2..24] hours
23 hrs, 59 mins, 30 secs <-> 41 hrs, 59 mins, 29 secs 1 day
41 hrs, 59 mins, 30 secs <-> 29 days, 23 hrs, 59 mins, 29 secs [2..29] days
29 days, 23 hrs, 59 mins, 30 secs <-> 44 days, 23 hrs, 59 mins, 29 secs about 1 month
44 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs about 2 months
59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec [2..12] months
1 yr <-> 1 yr, 3 months about 1 year
1 yr, 3 months <-> 1 yr, 9 months over 1 year
1 yr, 9 months <-> 2 yr minus 1 sec almost 2 years
2 yrs <-> max time or date (same rules as 1 yr)

Installation

Add this to your application's shard.yml:

dependencies:
  humanize_time:
    github: mamantoha/humanize_time

Usage

require "humanize_time"

HumanizeTime.locale = "es" # or `I18n.locale = "es"`

HumanizeTime.distance_of_time_in_words(42.minutes.ago, Time.local)
# => 42 minutos
HumanizeTime.distance_of_time_in_words(3.seconds.ago, Time.local, include_seconds: true)
# => menos de 5 segundos

Available locales

Locale data synced with rails-i18n repository from files found in rails/locale directory.

Available locales:

["de-CH", "ml", "nl", "fr-CH", "ka", "sq", "id", "ur", "es-CO", "en", "es-US", "bn", "gl", "de-DE", "ms", "is", "hr", "ca", "lv", "zh-TW", "en-TT", "cy", "az", "en-GB", "el", "cs", "he", "en-CA", "es-NI", "tl", "sw", "wo", "es", "sr", "el-CY", "es-419", "fr-FR", "mr-IN", "uz", "sl", "es-AR", "sk", "ug", "zh-CN", "it-CH", "zh-YUE", "kn", "et", "en-CY", "en-AU", "nb", "it", "mn", "fr", "bg", "nn", "tt", "ko", "eo", "km", " hu", "da", "bs", "de-AT", "pap-CW", "pl", "es-MX", "mk", "sv-SE", "pap-AW", "af", "es-CL", "ja", "es-PE", "eu", "es-PA", "be", "pt", "st", "ru", "uk", "fa", "ta", "hi-IN", "zh-HK", "en-US", "pt-BR", "or", "en-ZA", "es-ES", "en-IN", "es-EC", "de", "ne", "mg", "vi", "lo", "lt", "rm", "hi", "th", "fr-CA", "oc", "fi", "ar", "es-CR", "en-NZ", "pa", "sv", "lb", "en-IE", "ro", "tr", "es-VE", "te"]

To re-sync locales run:

crystal tool/sync_locales.cr

Contributing

  1. Fork it (https://github.com/mamantoha/humanize_time/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • mamantoha Anton Maminov - creator, maintainer

Special thanks

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].