localtime-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40f28b6d20fe10b9d94fcb3eb0589930dbb67e21
4
+ data.tar.gz: ba2d82575c75c10e2405ae577c5a927739b569a7
5
+ SHA512:
6
+ metadata.gz: d5677931d33d8762329cc4f2f2d93d6a034ce59b0e8f1c832200b6d4526e8e08f83d22f9a99e89547b7ff52802c203b42a07112803422ef31d4776b9289abfad
7
+ data.tar.gz: a80dd56de8cb284b356fa27cc1e4103c2aad2da9a12256459d0e4427d46df8056d9c09aeeee0117b16ba106c275d2412e0845be97691c1825a6f88c1a9e18880
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Localtime::Rails
2
+
3
+ This gem just packages up some javascript that will help turn server timestamps (i.e. created_at) to local browser time.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'localtime-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install localtime-rails
18
+
19
+ ## Usage
20
+
21
+ Let's say you're listing users...
22
+
23
+ %table
24
+ - @users.each do |user|
25
+ %tr
26
+ %td= user.name
27
+ %td= user.created_at
28
+
29
+ ...user.created_at will yield something like this:
30
+
31
+ 2013-11-12 21:10:02 UTC
32
+
33
+ Now, you can take that "created_at" server time stamp, and make it relevant to the user...
34
+
35
+ %table
36
+ - @users.each do |user|
37
+ %tr
38
+ %td= user.name
39
+ %td.local-time
40
+ = user.created_at
41
+
42
+
43
+ ...now user.created_at will look something like this:
44
+
45
+ 11/12/2013 7:10 AM
46
+
47
+ If you have some sort of asynchronous Javascript that's executing after the initial page load, you can always call the function...
48
+
49
+ localizeTime();
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "localtime/rails/version"
2
+
3
+ module Localtime
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Localtime
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ $(document).ready(function(){
2
+ localizeTime();
3
+ });
4
+
5
+ $(document).on('page:load', localizeTime);
6
+
7
+ function localizeTime(){
8
+ $('.local-time').each(function() {
9
+ // localize servertime of the record and make it a Date Object
10
+ var now = new Date();
11
+ var utcOffset = now.getTimezoneOffset() * 1000 * 60;
12
+ var serverTime = $(this).text();
13
+ var newTimeObject = new Date(serverTime);
14
+ if (isNaN(newTimeObject.getFullYear())) {
15
+ return;
16
+ }
17
+ var localizedTime = new Date(newTimeObject - utcOffset);
18
+
19
+ //Get displayable data from the Date Object
20
+ var year = localizedTime.getFullYear();
21
+ var month = localizedTime.getMonth() + 1;
22
+ var day = localizedTime.getDate();
23
+ var hours = localizedTime.getHours();
24
+
25
+ //Tweaks: 24hour clock to 12, add a leading 0 to minutes less than 10, etc.
26
+ var ampm = hours >= 12 ? 'PM' : 'AM'
27
+ hours = hours % 12;
28
+ hours = hours ? hours : 12;
29
+ var minutes = (localizedTime.getMinutes() < 10 ? '0' : '') + localizedTime.getMinutes();
30
+
31
+ if ($(this).text() != "") {
32
+ $(this).text(month + "/" + day + "/" + year + " " + hours + ":" + minutes + " " + ampm);
33
+ $(this).removeClass('local-time');
34
+ }
35
+ });
36
+ }
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: localtime-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - johncox00
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Localize server times in your view.
42
+ email:
43
+ - john@mach19.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/localtime/rails/version.rb
49
+ - lib/localtime/rails.rb
50
+ - vendor/assets/javascripts/localtime.js
51
+ - README.md
52
+ homepage: https://github.com/johncox00/localtime-rails
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.0.6
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Easy way to localize times in a UI by implementing a .local-time class.
76
+ test_files: []