wiser_timezone 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +54 -12
- data/app/assets/javascripts/wiser_timezone.js +33 -19
- data/app/assets/stylesheets/wiser_timezone.css +41 -2
- data/app/controllers/wiser_timezone/wiser_timezone_controller.rb +25 -7
- data/app/helpers/wiser_timezone/wiser_timezone_helper.rb +35 -6
- data/config/routes.rb +1 -1
- data/lib/wiser_timezone/version.rb +1 -1
- data/wiser_timezone.gemspec +1 -1
- metadata +41 -20
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDI2YzQzNTk5Y2QxODljZDkxY2NlZjRkYjI4ZjEwMTI1YTY3Y2FkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmUzMDY3ZDkyNWU1YTFmMzBhNDE3YjA2NjY2M2M0YTQzNDU4ZTU0NQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODYxMjc0MTRmNmI0NjVkMTc5YzYzYzk1OTkzZTYyYjhjZGFlNWUzZWVlMTU1
|
10
|
+
NmZjZWQ0ODQzNmVhYWViMTI5YWFhYmI3N2U5MzFmYWU0MGQ3OTEyYjUwMTQ0
|
11
|
+
YWY4NGJjNzZiMDY3MGIxYjNmZjdjZDdmNTkzODc4YjVlNGFmNjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTk3OGUzNjUyZjdmMGJhMWEwNmU5Nzg5Y2NiNDU4NmJlMzY2Y2M2MTYyMjNm
|
14
|
+
OTliNmRiNWMxZmViMjg0ZGE5MTJkYjM1ZDIxZmQxMDFjMmZmMjk2MDRmZTYz
|
15
|
+
OTQ1OTEwZWNjZjFhNDFkNDA5NTViYzRkNjMzMzQ1ODhjZWM0NGU=
|
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', '~> 0.1.
|
19
|
+
gem 'wiser_timezone', '~> 0.1.4'
|
20
20
|
|
21
21
|
Be sure to restart your application if it is already running.
|
22
22
|
|
@@ -59,7 +59,7 @@ Include the `wiser_timezone` stylesheet into your `app/assets/stylesheets/applic
|
|
59
59
|
|
60
60
|
*= require wiser_timezone
|
61
61
|
|
62
|
-
###
|
62
|
+
### Initialize
|
63
63
|
|
64
64
|
Render the `wiser_timezone_initialize` view below the `body` of your layout file:
|
65
65
|
|
@@ -67,22 +67,41 @@ Render the `wiser_timezone_initialize` view below the `body` of your layout file
|
|
67
67
|
<%= wiser_timezone_initialize %>
|
68
68
|
<!-- More Codes -->
|
69
69
|
</body>
|
70
|
+
|
71
|
+
You can use the `force` parameter to require the user to set the timezone before using the application.
|
72
|
+
|
73
|
+
<body>
|
74
|
+
<%= wiser_timezone_initialize(force: true) %>
|
75
|
+
<!-- More Codes -->
|
76
|
+
</body>
|
77
|
+
|
78
|
+
You can use the `auto_set_guest` parameter to automatically capture the timezone if the user is not logged in. In this way, the guest users will never be asked to set their timezone, the system timezone will automatically detected.
|
79
|
+
|
80
|
+
<body>
|
81
|
+
<%= wiser_timezone_initialize(force: true, auto_set_guest: true) %>
|
82
|
+
<!-- More Codes -->
|
83
|
+
</body>
|
70
84
|
|
71
85
|
|
72
86
|
## Usage
|
73
87
|
|
74
|
-
All dates must be printed using the custom helper `wiser_timezone()`
|
88
|
+
All dates must be printed using the custom helper `wiser_timezone()` or `wt()`.
|
75
89
|
|
76
|
-
### Basic
|
90
|
+
### Basic Usage
|
77
91
|
|
78
|
-
|
92
|
+
Here's how to apply the timezone in a Date object:
|
79
93
|
|
80
94
|
<%= wiser_timezone(@post.created_at) %>
|
81
95
|
// Return: 2014-03-15 02:37:07 +0800
|
82
96
|
|
83
|
-
Or
|
97
|
+
Or use the simplier `wt` method:
|
98
|
+
|
99
|
+
<%= wt(@post.created_at) %>
|
100
|
+
// Return: 2014-03-15 02:37:07 +0800
|
101
|
+
|
102
|
+
Then you can also format the value:
|
84
103
|
|
85
|
-
<%=
|
104
|
+
<%= wt(@post.created_at).strftime('%Y-%m-%d %H:%M:%S') %>
|
86
105
|
// Return: 2014-03-15 02:37:07
|
87
106
|
|
88
107
|
### Globalize
|
@@ -100,23 +119,46 @@ Enable the *WiserTimezone* in the entire application by adding the `ensure_timez
|
|
100
119
|
You can convert dates to timezone without having the time, in short, date only:
|
101
120
|
|
102
121
|
<%= wiser_timezone(@post.created_at, date_only: true) %>
|
103
|
-
//
|
122
|
+
// Output: 2014-03-15 00:00:00 +0800
|
104
123
|
|
105
124
|
|
125
|
+
### Reset Link
|
126
|
+
|
127
|
+
You can embed a link in your app to clear or reset the current settings:
|
128
|
+
|
129
|
+
<%= link_to "Reset Timezone", set_timezone_path(offset: 'clear') %>
|
130
|
+
|
106
131
|
### Extra
|
107
132
|
|
108
|
-
You can get the current timezone using the `current_timezone` method:
|
133
|
+
You can get the current timezone in basic format using the `current_timezone` method:
|
109
134
|
|
110
135
|
My timezone is:
|
111
136
|
<%= current_timezone %>
|
112
|
-
//
|
137
|
+
// Output: (GMT+08:00) Beijing
|
138
|
+
|
139
|
+
You can get the current timezone in slim format using the `current_timezone_slim` method:
|
140
|
+
|
141
|
+
My timezone is:
|
142
|
+
<%= current_timezone_slim %>
|
143
|
+
// Output: (GMT+8) Beijing
|
113
144
|
|
114
|
-
You can get the current timezone
|
145
|
+
You can get the current timezone location using the `current_timezone_location` method:
|
146
|
+
|
147
|
+
My timezone is:
|
148
|
+
<%= current_timezone_location %>
|
149
|
+
// Output: Beijing
|
150
|
+
|
151
|
+
You can get the current timezone offset in basic format using the `current_timezone_offset` method:
|
115
152
|
|
116
153
|
My timezone is:
|
117
154
|
<%= current_timezone_offset %>
|
118
|
-
//
|
155
|
+
// Output: GMT+8
|
119
156
|
|
157
|
+
You can get the current timezone offset in slim format using the `current_timezone_offset` method:
|
158
|
+
|
159
|
+
My timezone is:
|
160
|
+
<%= current_timezone_offset_slim %>
|
161
|
+
// Output: +8
|
120
162
|
|
121
163
|
## Contributing
|
122
164
|
|
@@ -1,29 +1,43 @@
|
|
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
|
+
$(window).resize()
|
9
4
|
});
|
10
5
|
|
11
|
-
|
6
|
+
$(window).resize(function(){
|
12
7
|
if($('#wiser_timezone_container').is(':visible')){
|
13
|
-
|
14
|
-
|
8
|
+
if(!$('#wiser_timezone_container').hasClass('force'))
|
9
|
+
$('html').css('margin-top', $('#wiser_timezone_container').height() + 'px')
|
10
|
+
if($('#wiser_timezone_container').hasClass('no_user'))
|
11
|
+
$('#wiser_timezone_container #wiser_timezone_link')[0].click()
|
12
|
+
}
|
13
|
+
})
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
}else{
|
15
|
+
$(document).on("click", "#wiser_timezone_close", function(){
|
16
|
+
$('#wiser_timezone_container').remove()
|
17
|
+
$('html').css('margin-top', '0px')
|
18
|
+
})
|
19
|
+
|
20
|
+
var wiser_timezone_reload = function(){
|
21
|
+
if($('#wiser_timezone_container').size() > 0){
|
22
|
+
if($('#wiser_timezone_container').data('offset-cookie') == 'skip'){
|
26
23
|
$('#wiser_timezone_container').remove()
|
24
|
+
}else{
|
25
|
+
browser_offset = (-(new Date()).getTimezoneOffset() / 60).toString();
|
26
|
+
setting_offset = $('#wiser_timezone_space').data('offset')
|
27
|
+
|
28
|
+
if(browser_offset != setting_offset){
|
29
|
+
$(window).resize()
|
30
|
+
url = $('#wiser_timezone_link').attr('href')
|
31
|
+
if(!$('#wiser_timezone_link').hasClass('wiser_timezone_link')){
|
32
|
+
$('#wiser_timezone_link').addClass('wiser_timezone_link')
|
33
|
+
$('#wiser_timezone_link').attr('href', url + '?offset=' + encodeURIComponent(browser_offset))
|
34
|
+
hours_offset = (new Date()).getTimezoneOffset() / -60
|
35
|
+
$('#wiser_timezone_space').html($('#wiser_timezone_space').html().replace('~TZ~','GMT+' + hours_offset))
|
36
|
+
}
|
37
|
+
$('#wiser_timezone_container').show()
|
38
|
+
}else{
|
39
|
+
$('#wiser_timezone_container').remove()
|
40
|
+
}
|
27
41
|
}
|
28
42
|
}
|
29
43
|
}
|
@@ -3,21 +3,60 @@
|
|
3
3
|
position: absolute;
|
4
4
|
top: 0;
|
5
5
|
left: 0;
|
6
|
-
z-index:
|
6
|
+
z-index: 99999;
|
7
7
|
/* Layout */
|
8
8
|
width: 100%;
|
9
9
|
}
|
10
|
+
#wiser_timezone_container.force {
|
11
|
+
/* Position */
|
12
|
+
position: fixed;
|
13
|
+
/* Layout */
|
14
|
+
height: 100%;
|
15
|
+
text-align: center;
|
16
|
+
}
|
17
|
+
#wiser_timezone_container #wiser_timezone_cover {
|
18
|
+
display: none;
|
19
|
+
}
|
20
|
+
#wiser_timezone_container.force #wiser_timezone_cover {
|
21
|
+
/* Position */
|
22
|
+
display: block;
|
23
|
+
position: fixed;
|
24
|
+
top: 0;
|
25
|
+
left: 0;
|
26
|
+
/* Layout */
|
27
|
+
width: 100%;
|
28
|
+
height: 100%;
|
29
|
+
opacity: 0.95;
|
30
|
+
/* Background */
|
31
|
+
background-color: #222;
|
32
|
+
}
|
10
33
|
#wiser_timezone_container #wiser_timezone_space {
|
11
34
|
/* Layout */
|
12
35
|
padding: 10px 15px;
|
13
36
|
line-height: 1.2em;
|
37
|
+
opacity: 0.95;
|
38
|
+
cursor: default;
|
14
39
|
/* Font */
|
15
|
-
font-family:
|
40
|
+
font-family: Lucida Sans, 'Liberation Sans', 'DejaVu Sans', sans-serif;
|
16
41
|
color: #555;
|
42
|
+
font-size: 13px;
|
17
43
|
/* Border */
|
18
44
|
border-bottom: 1px solid #ddd;
|
19
45
|
/* Background */
|
20
46
|
background: #f5f9ff;
|
47
|
+
box-shadow: 0 -1px 4px 0 rgba(0, 0, 0, 0.50);
|
48
|
+
}
|
49
|
+
#wiser_timezone_container.force #wiser_timezone_space {
|
50
|
+
/* Layout */
|
51
|
+
display: inline-block;
|
52
|
+
opacity: 0.85;
|
53
|
+
margin: 90px auto 0;
|
54
|
+
max-width: 330px;
|
55
|
+
padding: 30px 20px;
|
56
|
+
z-index: 2;
|
57
|
+
/* Font */
|
58
|
+
text-align: center;
|
59
|
+
font-size: 15px;
|
21
60
|
}
|
22
61
|
#wiser_timezone_container #wiser_timezone_space a {
|
23
62
|
/* Font */
|
@@ -2,17 +2,35 @@ module WiserTimezone
|
|
2
2
|
class WiserTimezoneController < ApplicationController
|
3
3
|
def set_timezone
|
4
4
|
if params[:offset].present?
|
5
|
-
if
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
if params[:offset] == "skip"
|
6
|
+
cookies[:wiser_timezone_offset] = params[:offset]
|
7
|
+
elsif params[:offset] == "clear"
|
8
|
+
cookies[:wiser_timezone_offset] = nil
|
9
|
+
if current_user.present?
|
10
|
+
begin
|
11
|
+
current_user.update_attribute(:timezone, nil)
|
12
|
+
rescue; end
|
13
|
+
else
|
14
|
+
cookies[:wiser_timezone_offset] = params[:offset]
|
10
15
|
end
|
11
16
|
else
|
12
|
-
|
17
|
+
if current_user.present?
|
18
|
+
cookies[:wiser_timezone_offset] = nil
|
19
|
+
begin
|
20
|
+
current_user.update_attribute(:timezone, params[:offset])
|
21
|
+
rescue
|
22
|
+
raise "You probably need to run the migration. Please review the documentation."
|
23
|
+
end
|
24
|
+
else
|
25
|
+
cookies[:wiser_timezone_offset] = params[:offset]
|
26
|
+
end
|
13
27
|
end
|
14
28
|
end
|
15
|
-
|
29
|
+
begin
|
30
|
+
redirect_to :back
|
31
|
+
rescue
|
32
|
+
redirect_to root_path
|
33
|
+
end
|
16
34
|
end
|
17
35
|
end
|
18
36
|
end
|
@@ -9,12 +9,26 @@ module WiserTimezone
|
|
9
9
|
return ActiveSupport::TimeZone[offset.to_i]
|
10
10
|
end
|
11
11
|
|
12
|
+
def current_timezone_slim
|
13
|
+
location = current_timezone.to_s.split(" ").last()
|
14
|
+
offset = current_timezone_offset
|
15
|
+
return "(#{offset}) #{location}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_timezone_location
|
19
|
+
return current_timezone.to_s.split(" ").last()
|
20
|
+
end
|
21
|
+
|
12
22
|
def current_timezone_offset
|
13
23
|
timezone_str = current_timezone.to_s
|
14
24
|
offset_str = timezone_str[timezone_str.index('(')+1..-1].split(':').first()
|
15
25
|
return "#{offset_str[0..3]}#{offset_str[4..-1].to_i}"
|
16
26
|
end
|
17
27
|
|
28
|
+
def current_timezone_offset_slim
|
29
|
+
current_timezone_offset[3..-1]
|
30
|
+
end
|
31
|
+
|
18
32
|
def wiser_timezone(date, date_only = false)
|
19
33
|
begin
|
20
34
|
date_time = date.to_datetime
|
@@ -28,15 +42,26 @@ module WiserTimezone
|
|
28
42
|
end
|
29
43
|
end
|
30
44
|
|
31
|
-
def
|
32
|
-
|
45
|
+
def wt(date, date_only = false)
|
46
|
+
wiser_timezone(date, date_only)
|
47
|
+
end
|
48
|
+
|
49
|
+
def wiser_timezone_initialize(options = {})
|
50
|
+
force = options[:force].present? && options[:force]
|
51
|
+
auto_set_guest = options[:auto_set_guest].present? && options[:auto_set_guest] && !current_user.present?
|
52
|
+
|
53
|
+
set_link = link_to('click here', set_timezone_path, :id => 'wiser_timezone_link')
|
54
|
+
close_link = link_to('skip', set_timezone_path(offset: 'skip'), :id => 'wiser_timezone_close', :remote => true)
|
55
|
+
|
33
56
|
if offset.present?
|
34
|
-
msg = "Your
|
57
|
+
msg = "Your system's timezone does not match your current setting #{current_timezone_slim}, <span class='no_wrap'>#{set_link} to update the timezone to ~TZ~.</span>#{'<br/>' if force}Otherwise, #{close_link} setting your timezone."
|
35
58
|
else
|
36
|
-
msg = "You do not have timezone in your
|
59
|
+
msg = "You do not have timezone in your settings, <span class='no_wrap'>#{set_link} to update the timezone to ~TZ~.</span>#{'<br/>' if force}Otherwise, #{close_link} setting your timezone."
|
37
60
|
end
|
61
|
+
classes = "#{'force' if force} #{'no_user' if auto_set_guest}"
|
38
62
|
space = "<div id='wiser_timezone_space' data-offset='#{offset}'>#{msg}</div>"
|
39
|
-
|
63
|
+
cover = "<div id='wiser_timezone_cover'></div>"
|
64
|
+
html = "<div id='wiser_timezone_container' class='#{classes}' style='display:none;' data-offset-cookie='#{cookies[:wiser_timezone_offset]}'>#{cover} #{space}</div>"
|
40
65
|
return html.html_safe
|
41
66
|
end
|
42
67
|
|
@@ -50,7 +75,11 @@ module WiserTimezone
|
|
50
75
|
@timezone_offset = nil
|
51
76
|
end
|
52
77
|
elsif cookies[:wiser_timezone_offset].present?
|
53
|
-
|
78
|
+
if cookies[:wiser_timezone_offset] == 'clear'
|
79
|
+
cookies[:wiser_timezone_offset] = nil
|
80
|
+
else
|
81
|
+
@timezone_offset ||= cookies[:wiser_timezone_offset]
|
82
|
+
end
|
54
83
|
end
|
55
84
|
return @timezone_offset
|
56
85
|
end
|
data/config/routes.rb
CHANGED
data/wiser_timezone.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = WiserTimezone::VERSION
|
9
9
|
spec.authors = ["Kenneth John Balgos"]
|
10
10
|
spec.email = ["kennethjohnbalgos@gmail.com"]
|
11
|
-
spec.description = ""
|
11
|
+
spec.description = "Allow your Ruby on Rails application to handle timezone dynamically."
|
12
12
|
spec.summary = "Friendly Timezone on Steroids"
|
13
13
|
spec.homepage = "https://github.com/kennethjohnbalgos/wiser_timezone"
|
14
14
|
spec.license = "MIT"
|
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.5
|
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-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,30 +38,51 @@ dependencies:
|
|
38
38
|
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description: Allow your Ruby on Rails application to handle timezone dynamically.
|
42
42
|
email:
|
43
43
|
- kennethjohnbalgos@gmail.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
49
|
-
|
50
|
-
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
-
|
55
|
-
|
56
|
-
-
|
57
|
-
|
58
|
-
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
-
|
63
|
-
|
64
|
-
|
48
|
+
- !binary |-
|
49
|
+
LmdpdGlnbm9yZQ==
|
50
|
+
- !binary |-
|
51
|
+
R2VtZmlsZQ==
|
52
|
+
- !binary |-
|
53
|
+
TElDRU5TRS50eHQ=
|
54
|
+
- !binary |-
|
55
|
+
UkVBRE1FLm1k
|
56
|
+
- !binary |-
|
57
|
+
UmFrZWZpbGU=
|
58
|
+
- !binary |-
|
59
|
+
YXBwL2Fzc2V0cy9qYXZhc2NyaXB0cy93aXNlcl90aW1lem9uZS5qcw==
|
60
|
+
- !binary |-
|
61
|
+
YXBwL2Fzc2V0cy9zdHlsZXNoZWV0cy93aXNlcl90aW1lem9uZS5jc3M=
|
62
|
+
- !binary |-
|
63
|
+
YXBwL2NvbnRyb2xsZXJzL3dpc2VyX3RpbWV6b25lL3dpc2VyX3RpbWV6b25l
|
64
|
+
X2NvbnRyb2xsZXIucmI=
|
65
|
+
- !binary |-
|
66
|
+
YXBwL2hlbHBlcnMvd2lzZXJfdGltZXpvbmUvd2lzZXJfdGltZXpvbmVfaGVs
|
67
|
+
cGVyLnJi
|
68
|
+
- !binary |-
|
69
|
+
Y29uZmlnL3JvdXRlcy5yYg==
|
70
|
+
- !binary |-
|
71
|
+
bGliL2dlbmVyYXRvcnMvd2lzZXJfdGltZXpvbmUucmI=
|
72
|
+
- !binary |-
|
73
|
+
bGliL2dlbmVyYXRvcnMvd2lzZXJfdGltZXpvbmUvbWlncmF0aW9uL21pZ3Jh
|
74
|
+
dGlvbl9nZW5lcmF0b3IucmI=
|
75
|
+
- !binary |-
|
76
|
+
bGliL2dlbmVyYXRvcnMvd2lzZXJfdGltZXpvbmUvbWlncmF0aW9uL3RlbXBs
|
77
|
+
YXRlcy9taWdyYXRpb24ucmI=
|
78
|
+
- !binary |-
|
79
|
+
bGliL3dpc2VyX3RpbWV6b25lLnJi
|
80
|
+
- !binary |-
|
81
|
+
bGliL3dpc2VyX3RpbWV6b25lL2VuZ2luZS5yYg==
|
82
|
+
- !binary |-
|
83
|
+
bGliL3dpc2VyX3RpbWV6b25lL3ZlcnNpb24ucmI=
|
84
|
+
- !binary |-
|
85
|
+
d2lzZXJfdGltZXpvbmUuZ2Vtc3BlYw==
|
65
86
|
homepage: https://github.com/kennethjohnbalgos/wiser_timezone
|
66
87
|
licenses:
|
67
88
|
- MIT
|