
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@perfectlynormal/local-time
Advanced tools
Local Time makes it easy to display times and dates to users in their local time. Its Rails helpers render <time> elements in UTC (making them cache friendly), and its JavaScript component immediately converts those elements from UTC to the browser's local time.
Add gem 'local_time' to your Gemfile.
Include local-time.js in your application's JavaScript bundle.
Using the asset pipeline:
//= require local-time
Using the local-time npm package:
import LocalTime from "local-time"
LocalTime.start()
> comment.created_at
"Wed, 27 Nov 2013 18:43:22 EST -0500"
<%= local_time(comment.created_at) %>
Renders:
<time data-format="%B %e, %Y %l:%M%P"
data-local="time"
datetime="2013-11-27T23:43:22Z">November 27, 2013 11:43pm</time>
And is converted client-side to:
<time data-format="%B %e, %Y %l:%M%P"
data-local="time"
datetime="2013-11-27T23:43:22Z"
title="November 27, 2013 6:43pm EDT"
data-localized="true">November 27, 2013 6:43pm</time>
(Line breaks added for readability)
<%= local_time(time) %>
Format with a strftime string (default format shown here)
<%= local_time(time, '%B %e, %Y %l:%M%P') %>
Alias for local_time with a month-formatted default
<%= local_date(time, '%B %e, %Y') %>
To set attributes on the time tag, pass a hash as the second argument with a :format key and your attributes.
<%= local_time(time, format: '%B %e, %Y %l:%M%P', class: 'my-time') %>
To use a strftime format already defined in your app, pass a symbol as the format.
<%= local_time(date, :long) %>
I18n.t("time.formats.#{format}"), I18n.t("date.formats.#{format}"), Time::DATE_FORMATS[format], and Date::DATE_FORMATS[format] will be scanned (in that order) for your format.
Note: The included strftime JavaScript implementation is not 100% complete. It supports the following directives: %a %A %b %B %c %d %e %H %I %l %m %M %p %P %S %w %y %Y %Z
<%= local_time_ago(time) %>
Displays the relative amount of time passed. With age, the descriptions transition from {quantity of seconds, minutes, or hours} to {date + time} to {date}. The <time> elements are updated every 60 seconds.
Examples (in quotes):
Preset time and date formats that vary with age. The available types are date, time-ago, time-or-date, and weekday. Like the local_time helper, :type can be passed a string or in an options hash.
<%= local_relative_time(time, 'weekday') %>
<%= local_relative_time(time, type: 'time-or-date') %>
Available :type options
date Includes the year unless it's current. "Apr 11" or "Apr 11, 2013"time-ago See above. local_time_ago calls local_relative_time with this :type option.time-or-date Displays the time if it occurs today or the date if not. "3:26pm" or "Apr 11"weekday Displays "Today", "Yesterday", or the weekday (e.g. Wednesday) if the time is within a week of today.weekday-or-date Displays the weekday if it occurs within a week or the date if not. "Yesterday" or "Apr 11"Internationalization (I18n)
Local Time includes a set of default en translations which can be updated directly. Or, you can provide an entirely new set in a different locale:
LocalTime.config.i18n["es"] = {
date: {
dayNames: [ … ],
monthNames: [ … ],
…
},
time: {
…
},
datetime: {
…
}
}
LocalTime.config.locale = "es"
2.0.0 (August 7, 2017)
MutationObserver instead of listening for various DOM, Turbolinks, and jQuery eventslocal_time.js to local-time.js1.0.3
%Z time zone parsing1.0.2 (February 3, 2015)
1.0.1 (December 3, 2014)
weekday-or-date option [Chew Choon Keat]1.0.0 (April 12, 2014)
local_relative_time helper with several built in types:format (and :type) option as a bare string or value in hashrelativeDate, relativeTimeOrDate, relativeWeekday and run to the APIpopstate event listener0.3.0 (February 9, 2014)
0.2.0 (December 10, 2013)
textContent over innerText for Firefox compatibilityoptions argument to local_time_ago helper0.1.0 (November 29, 2013)
FAQs
Local <time> elements
We found that @perfectlynormal/local-time 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.