Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
human_date
allows you to display times and dates in a human format.
date = Date.current # 2012-08-28
human_date(date) # Today
human_date(date + 1.day) # Tomorrow
human_date(date - 1.day) # Yesterday
human_date(date - 2.days) # Aug 26
human_date(date - 1.year) # Aug 28, 2011
# it works with times, too
time = Time.now # 2012-08-28 17:20:54
human_time(time) # 5:20 pm
human_time(time - 1.day) # Yesterday
# ...
human_date
provides you with 5 states for your Time/Date objects:
today
displays Today
for Date and time for Time (5:20 pm
)
tomorrow
displays: Tomorrow
yesterday
displays: Yesterday
current_year
displays the month and the day: Aug 26
other_year
displays the month, the day and the year: Aug 28, 2011
The default values can be overwritten in the locale file. See the I18n section for details.
Add this line to your application's Gemfile:
gem 'human_date'
And then execute:
$ bundle
Or install it yourself as:
$ gem install human_date
human_date
for dates
human_time
for times
human_time_tag
generates HTML5 <time>
tag
date = Date.current
# 2012-08-28
human_date(date)
# Today
human_time_tag(date)
# <time datetime="2012-08-28">Today</time>
human_time_tag(date, pubdate: true)
# <time datetime="2012-08-28" pubdate="pubdate">Today</time>
time = Time.zone.now
# 2012-08-28 17:20:54
human_time(time)
# 5:20 pm
human_time_tag(time)
# <time datetime="2012-08-28T17:20:54">5:20 PM</time>
If you have several models and want each of them to have a different format (for example, for a Post
you want to display 'Today' if it was posted today, but for a Comment
you want to display something like '5:20 pm'), you can use namespaces.
# config/locales/en.yml
en:
posts:
time:
formats:
today: "Today"
comments:
time:
formats:
today: "%l:%M %p"
time = Time.now
# 2012-08-28 17:20:54
human_time(time, :posts)
# Today
human_time(time, :comments)
# 5:20 pm
human_time_tag(time, :posts)
# <time datetime="2012-08-28T17:20:54">Today</time>
human_time_tag(time, :comments)
# <time datetime="2012-08-28T17:20:54">5:20 pm</time>
human_time_tag(time, :comments, pubdate: true)
# <time datetime="2012-08-28T17:20:54" pubdate="pubdate">5:20 pm</time>
You can overwrite the default values in your locale file.
# config/locales/en.yml
en:
date:
formats:
today: "Today"
tomorrow: "Tomorrow"
yesterday: "Yesterday"
current_year: "%h %e"
other_year: "%h %e, %Y"
time:
formats:
today: "%l:%M %p"
tomorrow: "Tomorrow"
yesterday: "Yesterday"
current_year: "%h %e"
other_year: "%h %e, %Y"
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that human_date demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.