Skip to content

noesya/i18n_date_range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 24, 2024
f7b460a · May 24, 2024

History

30 Commits
Sep 8, 2023
Sep 8, 2023
Nov 2, 2023
May 24, 2024
May 24, 2024
May 21, 2024
Sep 8, 2023
Nov 2, 2023
Nov 2, 2023
Sep 10, 2023
May 24, 2024
Sep 8, 2023
May 24, 2024
Sep 8, 2023
Sep 10, 2023
Sep 10, 2023

Repository files navigation

I18nDateRange

The purpose of this gem is to add a helper needed to display proper Date range informations.
For example: "Du 3 au 5 octobre 2024" or "Du 3 octobre 2023 au 12 janvier 2024"

Installation

Add this line to your application's Gemfile:

gem 'i18n_date_range'

And then execute:

$ bundle install

Usage

This gem comes with an integrated view helper: date_range_i18n which takes 3 parameters:

  • date_from
  • date_to (optional)
  • a hash of additional formatting options(optional)

The options hash currently support 2 arguments:

  • format: can be :short or :long (default is :short)
  • layout: can be :one_lineor :two_lines (default is :one_line)

"Short" format means without the explicit day name (September 8, 2024).
"Long" format means with it (Friday, September 8, 2024).

"One line" layout means the string will be displayed on one line only (From September 8, 2024 to September 8, 2025) "Two lines" layout means the result will be displayed on 2 lines,separated with <br> (September 8, 2024
September 8, 2025)

Change texts or formats

This gem is based on I18n. Feel free to overwrite any key you want.
Refer to config/locales/fr.yml to see what can be edited.

Tests

Tests are done with RSpec, and Combustion is used to simulate the Rails app. Rubocop is used to check the syntax.

  • bundle exec rspec to launch the tests
  • rake rubocop to launch Rubocop
  • rake to launch both (default)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/noesya/i18n_date_range.

License

The gem is available as open source under the terms of the MIT License.

Bibliography

https://coderwall.com/p/fkg-ng/display-date-ranges-in-text-in-rails