https://github.com/corylown/edtf-humanize
This gem adds a humanize method to EDTF dates.
https://github.com/corylown/edtf-humanize
code4lib edtf edtf-ruby
Last synced: 2 days ago
JSON representation
This gem adds a humanize method to EDTF dates.
- Host: GitHub
- URL: https://github.com/corylown/edtf-humanize
- Owner: corylown
- License: bsd-3-clause
- Created: 2016-02-11T13:59:14.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2026-01-12T14:34:18.000Z (30 days ago)
- Last Synced: 2026-01-14T10:56:04.085Z (28 days ago)
- Topics: code4lib, edtf, edtf-ruby
- Language: Ruby
- Homepage:
- Size: 194 KB
- Stars: 16
- Watchers: 8
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# edtf-humanize
The EDTF-humanize gem adds a humanize method to EDTF::Decade, EDTF::Century, EDTF::Interval, EDTF::Set, EDTF::Season, EDTF::Unknown, and Date (ISO 8601 compliant) objects. It uses the [edtf-ruby](https://github.com/inukshuk/edtf-ruby) gem for parsing EDTF date strings into Date and EDTF objects.
See the [edtf-ruby project's documentation](https://github.com/inukshuk/edtf-ruby) for details about supported EDTF string formats and other implementation details.
This gem is used in production by Duke University Library's [digital repository](https://gitlab.oit.duke.edu/ddr/ddr-xenon/) to transform date metadata stored as Extended Date Time Format (EDTF) strings into human readable strings for display.
## Installation
In a Rails application using Bundler
Add the following to your Gemfile:
```
gem 'edtf-humanize'
```
Then run:
```
> bundle install
```
To use in other contexts install the gem and require it:
```
> gem install edtf-humanize
```
```
require 'edtf-humanize'
```
## Examples
### Date (ISO 8601)
```
> d = Date.edtf('1975-07-01')
=> Tue, 01 Jul 1975
> d.humanize
=> "July 1, 1975"
> d = Date.edtf('1981~')
=> Thu, 01 Jan 1981
> d.humanize
=> "circa 1981"
> d = Date.edtf('198u')
=> Tue, 01 Jan 1980
> d.humanize
=> "198x"
```
### EDTF::Season
```
> d = Date.edtf('1975-22')
=> #
> d.humanize
=> "summer 1975"
```
### EDTF::Decade
```
> d = Date.edtf('197x')
=> #
> d.humanize
=> "1970s"
```
### EDTF::Century
```
> d = Date.edtf('19xx')
=> #
> d.humanize
=> "1900s"
```
### EDTF::Interval
```
> d = Date.edtf('1981/1985')
=> #
> d.humanize
=> "1981 to 1985"
```
### EDTF::Set
```
> d = Date.edtf('[1888, 1889, 1891]')
=> #, @choice=true, @later=false, @earlier=false>
> d.humanize
=> "1888, 1889 or 1891"
```
### EDTF::Unknown
```
> d = Date.edtf('uuuu')
=> #
> d.humanize
=> "unknown"
```
## Internationalization
EDTF-humanize supports the use of I18n as well as language specific module overrides for more nuanced control. English, French, German, and Italian are supported.
Examples with current locale `:fr`:
```
> Date.edtf('1975-24').humanize
=> "hiver 1975"
> Date.edtf('20xx').humanize
=> "XXIe siècle"
```
Pull requests to add support for additional languages are welcome. You must add a new language module for the language and include the Default language module. A locales file with translations is also needed. The supporting files for French may be used as a reference for adding support for additional languages.:
```
edtf-humanize/lib/edtf/humanize.rb
edtf-humanize/config/locales/fr.edtf.yml
edtf-humanize/lib/edtf/humanize/language/french.rb
edtf-humanize/spec/edtf/humanize_fr_spec.rb
```
## Contributions
Contributions, especially to add support for additional languages are welcome. Tests are expected and written using RSpec. Code style is enforced with Rubocop.