Low commit activity in last 3 years
There's a lot of open issues
A long-lived project that still receives updates
Rails helpers for handling dates and time.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Semantic DateTime Tags

Gem Version

Set of Rails helpers that mark up Date, DateTime instances and their ranges with sensible combination of (html5) tags, data attributes and CSS classes so that their display can be easily controlled via CSS.

The generated markup takes into account Date/Time formats as specified in the I18n localizations.

This allows, for example, highlighting today's dates:

time.date.semantic.current_date {
  background-color: yellow;
}

Hiding current year via CSS:

time.date.semantic.current_year {
  span.year {
    display: none;
  }
}

Or, in the case of date ranges, avoiding repetition of year in both dates:

span.date_range.semantic.same_year {
  time.date.semantic.from {
    span.year {
      display: none;
    }
  }
}

See the included SCSS example for more.

Installation

Add this line to your application's Gemfile:

gem 'semantic_date_time_tags'

And then execute:

$ bundle

Or install it yourself as:

$ gem install semantic_date_time_tags

If you want to use the default css you can include it like this:

/*
 *= require 'semantic_date_time_tags/default'
 */

Or if you like to use some of the mixins, import them like this:

@import "semantic_date_time_tags/partials/mixins";

Usage

In your views:

Date

<%= semantic_date_tag(Date.today) %>

Will result in the following markup:

<time class="date semantic current_date current_year" datetime="2014-09-26">
  <span class="day d">26</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span>
</time>

DateTime

<%= semantic_date_time_tag(DateTime.now) %>

Will result in the following markup:

<time class="date_time semantic current_date current_year" datetime="2014-09-26T15:35:56+02:00">
  <span class="day d">26</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span> <span class="hours H">15</span><span class="sep">:</span><span class="minutes M">35</span>
</time>

Date Range

<%= semantic_date_range_tag(Date.today, Date.tomorrow) %>

Will result in the following markup:

<span class="date_range semantic same_year same_month">
  <time class="date semantic current_date current_year from">
    <span class="day d">26</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span>
  </time>
  <span class="date_range_separator"></span>
  <time class="date semantic current_year to">
    <span class="day d">27</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span>
  </time>
</span>

Contributing

  1. Fork it ( https://github.com/tomasc/semantic_date_time_tags/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request