0.0
No commit activity in last 3 years
No release in over 3 years
This is a simple gem that uses some simple tag generation helpers and some in-page javascript to make sure times displayed in a page are in the browser's local time zone and format.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0

Runtime

>= 0
 Project Readme

InTheZone

This is a simple gem that uses some simple tag generation helpers and some in-page javascript using RequireJS, Knockout and Moment.js to make sure times displayed in a page are in the browser's local time zone and format.

Installation

Add this line to your application's Gemfile:

gem 'in_the_zone'

And then execute:

$ bundle

Or install it yourself as:

$ gem install in_the_zone

Usage

Pretty simple:

require 'in_the_zone'

# Time
InTheZone.time_tag( Time.now.utc, format: 'L', from_now: true, live_update: true )
# => <span class="local-time" data-bind="localizeTime: { timestamp: 1400885511, format: 'L', from_now: true, live_update: true }">05/23/14</span>
InTheZone.time_tag( Time.now.utc )
# => <span class="local-time" data-bind="localizeTime: { timestamp: 1400886211, format: 'LLL' }">May 23 2014 11:03 PM</span>

# Date
InTheZone.date_tag( Date.today.to_time.utc )
# => <span class="local-time" data-bind="localizeTime: { timestamp: 1400828400, format: 'LL' }">May 23 2014</span>

Which will generate markup like:

<span class="local-time" data-bind="localizeTime: { timestamp: 1400885511, format: 'L', from_now: true, live_update: true }">05/23/14</span>
<span class="local-time" data-bind="localizeTime: { timestamp: 1400886211, format: 'LLL' }">May 23 2014 11:03 PM</span>
<span class="local-time" data-bind="localizeTime: { timestamp: 1400828400, format: 'LL' }">May 23 2014</span>

Then if you include the JS from the gem at the path gleaned from:

InTheZone.javascript_path # => "/Workspaces/in_the_zone/static_assets/javascripts/inthezone.js"

Or if you have the gem install, you can just run:

> in_the_zone_js_path
/Workspaces/in_the_zone/static_assets/javascripts/inthezone.js

# Or if you have it in your bundle:
> bundle exec in_the_zone_js_path
/Workspaces/in_the_zone/static_assets/javascripts/inthezone.js

Or, if you use RequireJS, you can add this to your config file:

requirejs.config({
  paths: {
    ko: 'path/to/knockout',
    moment: 'path/to/moment',
    inthezone: 'path/to/js/file/you/got/above'
  }
});
require.config({
  paths: {
    inthezone: 'pat/to/js/file/you/got/above',
  }

You can of course just copy the JS file to your repo as well... whatever works!

This span will automatically fill in with the time displayed in the correct format, in the correct timezone for the browser, as long as you have required the inthezone module and applied bindings.

define('test',
  ['ko', 'moment', 'inthezone'],
  function(ko,moment,zone) {
    ko.applyBindings();
  }
);

Demo

Please see the demo page at static_assets/test.html.

Contributing

  1. Fork it ( http://github.com/remotezygote/in_the_zone/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 new Pull Request