
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
{}[http://badge.fury.io/rb/timepiece]
= Timepiece
Timepiece is a Rails plugin providing a simple digital clock, accurate to your server's time and maintained by jQuery.
== Installation
Add Timepiece to your application's Gemfile
gem 'timepiece'
Require timepiece in app/assets/javascripts/application.js
//= require timepiece
If you want to use the new analog clock, you also need to require timepiece in your css
*= require 'timepiece'
or if you're using SCSS
@import 'timepiece';
Note: If you're using Turbolinks with your Rails project, you should also install jquery-turbolinks to ensure functionality is maintained between page loads.
== Usage
Add a functional clock to your views
<%= timepiece %>
Pass a timezone paramater (Defaults to 'UTC')
<%= timepiece('London') %>
Show a 12 hour clock by specifying its type:
explicitly
<%= timepiece('London', type: '12') %>
=== 12 Hour Clock Options
By default the 12 hour clock displays time without any leading character, in the format '1:23pm'. You can add either a zero, as present on the 24 hour clock, or a leading space character the size of a numerical digit - useful for keeping your clocks aligned. To achieve this, set the Timepiece's lead:
To add a leading zero to hour values less than ten
<%= timepiece('London', type: '12', lead: '0') %>
or
<%= timepiece('London', type: '12', lead: 'zero') %>
To add a space character
<%= timepiece('London', type: '12', lead: '_') %>
or
<%= timepiece('London', type: '12', lead: 'space') %>
You can apply your own styles to any part of the Timepiece clock. For instance, you can capitalize the AM/PM abbreviation by targeting the span with class 'timepiece-abbr'. By default, the abbreviations are displayed without punctuation. To add punctuation, you can specify it with the abbr_sep:
option.
Add punctuation to am/pm abbreviation
<%= timepiece('London', type: '12', abbr_sep: '.') %>
== Analog
New to version 0.2.0+, you can now include analog clocks in your projects.
The helper takes the same timezone parameter as the digital version (defaults to 'UTC'):
<%= analog('London') %>
To specify a certain size for the clock, use the size
parameter (defaults to 10em):
<%= analog('London', :size => '100px') %>
Note that if you pass a percentage, the size will be set as a percentage of the containing div.
== Timer
It is now also possible to make use of a basic timer. To start a count from Time.now
, simply include timer
in your Rails projects.
The helper also takes a time object as a parameter, for example:
<%= timer(User.first.created_at) %>
== Countdown
There is also a basic countdown implementation. To start a countdown to 2016, simply include countdown
in your Rails projects.
The helper also takes a time object as a parameter, for example:
<%= countdown(Time.new(2016, 3, 14)) %> <%# My birthday and, of course, Pi day %>
FAQs
Unknown package
We found that timepiece 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
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.