wiser_timezone 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +16 -1
- data/app/assets/javascripts/wiser_timezone.js +13 -4
- data/app/assets/stylesheets/wiser_timezone.css +5 -1
- data/app/controllers/wiser_timezone/wiser_timezone_controller.rb +6 -2
- data/app/helpers/wiser_timezone/wiser_timezone_helper.rb +17 -9
- data/lib/wiser_timezone/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWY0ZDI0OTA5NjY2NmFkMGQ1NTVjZDIxODFjZmI4ZjMxMmIyOGI3OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTg1ZGJkOTAzNGZiNTA5MGQxYjY1NDIwZGJlZjlhZWZkNTE0NjczZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGMwYzNkMDhkZTkxYzc1ZWUwOGIzMWNiMDU0MzExYjM2MWZiYmRmNzhlY2I3
|
10
|
+
NWJkZDhmYTlkZjQyNmMwNWIyNDgwNjZhMGUwMjkwMTU2ZjdiODkxZTQwOWVi
|
11
|
+
NDdlODRhMGY0NDEwN2U3YTU2MjgwYmUzNDkxZTQ5OTUzZGUxZjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWRjOGQ1YWNkMDBhOTMyMDRlN2MzNjU3OWM0MDkwODNkZTRlN2VhOWU4YmEy
|
14
|
+
YzFmN2RjNzUzZmIwMzY0NjE5MTIwYTNjYTcxODgxODI3NjQyZjcxNTI5YTUw
|
15
|
+
NjZmMTc4ODc3MmJlN2YwODkyYmQzZDU1YzY1YmQwNzQ0NmY0MmU=
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ You can do normal gem installation for `wiser_timezone` from your terminal:
|
|
16
16
|
|
17
17
|
or add this line in your Gemfile:
|
18
18
|
|
19
|
-
gem 'wiser_timezone'
|
19
|
+
gem 'wiser_timezone', '~> 0.1.1'
|
20
20
|
|
21
21
|
Be sure to restart your application if it is already running.
|
22
22
|
|
@@ -85,6 +85,15 @@ Or even format the value:
|
|
85
85
|
<%= wiser_timezone(@post.created_at).strftime('%Y-%m-%d %H:%M:%S') %>
|
86
86
|
// Return: 2014-03-15 02:37:07
|
87
87
|
|
88
|
+
### Expand
|
89
|
+
|
90
|
+
You can use the *WiserTimezone* helpers in your controller, just include the library in your `ApplicationController`:
|
91
|
+
|
92
|
+
include WiserTimezone::WiserTimezoneHelper
|
93
|
+
class ApplicationController < ActionController::Base
|
94
|
+
# More Codes
|
95
|
+
end
|
96
|
+
|
88
97
|
### Extra
|
89
98
|
|
90
99
|
You can get the current timezone using the `current_timezone` method:
|
@@ -93,6 +102,12 @@ You can get the current timezone using the `current_timezone` method:
|
|
93
102
|
<%= current_timezone %>
|
94
103
|
// Return: (GMT+08:00) Beijing
|
95
104
|
|
105
|
+
You can get the current timezone offset using the `current_timezone_offset` method:
|
106
|
+
|
107
|
+
My timezone is:
|
108
|
+
<%= current_timezone_offset %>
|
109
|
+
// Return: GMT+8
|
110
|
+
|
96
111
|
|
97
112
|
## Contributing
|
98
113
|
|
@@ -1,5 +1,11 @@
|
|
1
1
|
$(document).ready(function(){
|
2
2
|
wiser_timezone_reload();
|
3
|
+
|
4
|
+
$(window).resize(function(){
|
5
|
+
if($('#wiser_timezone_container').is(':visible')){
|
6
|
+
$('body').css('margin-top', $('#wiser_timezone_container').height() + 'px')
|
7
|
+
}
|
8
|
+
})
|
3
9
|
});
|
4
10
|
|
5
11
|
var wiser_timezone_reload = function(){
|
@@ -7,12 +13,15 @@ var wiser_timezone_reload = function(){
|
|
7
13
|
browser_offset = (-(new Date()).getTimezoneOffset() / 60).toString();
|
8
14
|
setting_offset = $('#wiser_timezone_space').data('offset')
|
9
15
|
|
10
|
-
|
11
16
|
if(browser_offset != setting_offset){
|
12
|
-
$(
|
13
|
-
$('#wiser_timezone_container').show()
|
17
|
+
$(window).resize()
|
14
18
|
url = $('#wiser_timezone_link').attr('href')
|
15
|
-
|
19
|
+
if(!$('#wiser_timezone_link').hasClass('wiser_timezone_link')){
|
20
|
+
$('#wiser_timezone_link').addClass('wiser_timezone_link')
|
21
|
+
$('#wiser_timezone_link').attr('href', url + '?offset=' + encodeURIComponent(browser_offset))
|
22
|
+
hours_offset = (new Date()).getTimezoneOffset() / -60
|
23
|
+
$('#wiser_timezone_space').html($('#wiser_timezone_space').html().replace('~TZ~','GMT+' + hours_offset))
|
24
|
+
}
|
16
25
|
}else{
|
17
26
|
$('#wiser_timezone_container').remove()
|
18
27
|
}
|
@@ -10,11 +10,12 @@
|
|
10
10
|
#wiser_timezone_container #wiser_timezone_space {
|
11
11
|
/* Layout */
|
12
12
|
padding: 10px 15px;
|
13
|
+
line-height: 1.2em;
|
13
14
|
/* Font */
|
14
15
|
font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;
|
15
16
|
color: #555;
|
16
17
|
/* Border */
|
17
|
-
border-bottom: 1px solid #
|
18
|
+
border-bottom: 1px solid #ddd;
|
18
19
|
/* Background */
|
19
20
|
background: #f5f9ff;
|
20
21
|
}
|
@@ -27,4 +28,7 @@
|
|
27
28
|
/* Font */
|
28
29
|
text-decoration: none;
|
29
30
|
color: #3e5e71;
|
31
|
+
}
|
32
|
+
.no_wrap {
|
33
|
+
white-space: nowrap;
|
30
34
|
}
|
@@ -2,8 +2,12 @@ module WiserTimezone
|
|
2
2
|
class WiserTimezoneController < ApplicationController
|
3
3
|
def set_timezone
|
4
4
|
if params[:offset].present?
|
5
|
-
if current_user.present?
|
6
|
-
|
5
|
+
if current_user.present?
|
6
|
+
begin
|
7
|
+
current_user.update_attribute(:timezone, params[:offset])
|
8
|
+
rescue
|
9
|
+
raise "You probably need to run the migration. Please review the documentation."
|
10
|
+
end
|
7
11
|
else
|
8
12
|
cookies[:wiser_timezone_offset] = params[:offset]
|
9
13
|
end
|
@@ -5,6 +5,12 @@ module WiserTimezone
|
|
5
5
|
return ActiveSupport::TimeZone[offset.to_i]
|
6
6
|
end
|
7
7
|
|
8
|
+
def current_timezone_offset
|
9
|
+
timezone_str = current_timezone.to_s
|
10
|
+
offset_str = timezone_str[timezone_str.index('(')+1..-1].split(':').first()
|
11
|
+
return "#{offset_str[0..3]}#{offset_str[4..-1].to_i}"
|
12
|
+
end
|
13
|
+
|
8
14
|
def wiser_timezone(date)
|
9
15
|
begin
|
10
16
|
date_time = date.to_datetime
|
@@ -17,26 +23,28 @@ module WiserTimezone
|
|
17
23
|
def wiser_timezone_initialize
|
18
24
|
link = link_to('Click Here', set_timezone_path, :method => 'post', :data => {:offset => "#{offset}"}, :id => 'wiser_timezone_link')
|
19
25
|
if offset.present?
|
20
|
-
msg = "Your computer's timezone does not appear to match the current setting #{current_timezone}.
|
26
|
+
msg = "Your computer's timezone does not appear to match the current setting #{current_timezone}. <span class='no_wrap'>#{link} to update the timezone to ~TZ~.</span>"
|
21
27
|
else
|
22
|
-
msg = "You do not have timezone in your user
|
28
|
+
msg = "You do not have timezone in your user settings. <span class='no_wrap'>#{link} to set your timezone to ~TZ~.</span>"
|
23
29
|
end
|
24
30
|
space = "<div id='wiser_timezone_space' data-offset='#{offset}'>#{msg}</div>"
|
25
|
-
html = "<div id='wiser_timezone_container' style='display:
|
31
|
+
html = "<div id='wiser_timezone_container' style='display:block;'>#{space}</div>"
|
26
32
|
return html.html_safe
|
27
33
|
end
|
28
34
|
|
29
35
|
private
|
30
36
|
|
31
37
|
def offset
|
32
|
-
if current_user.present?
|
33
|
-
|
38
|
+
if current_user.present?
|
39
|
+
if current_user.try(:timezone).present?
|
40
|
+
@timezone_offset ||= current_user.timezone
|
41
|
+
else
|
42
|
+
@timezone_offset = nil
|
43
|
+
end
|
34
44
|
elsif cookies[:wiser_timezone_offset].present?
|
35
|
-
|
36
|
-
else
|
37
|
-
offset = 0
|
45
|
+
@timezone_offset ||= cookies[:wiser_timezone_offset]
|
38
46
|
end
|
39
|
-
return
|
47
|
+
return @timezone_offset
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiser_timezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth John Balgos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|