browser-timezone-rails 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c30f83e8af79d4726073f25438e2e68afc58d49f
|
4
|
+
data.tar.gz: 51349b7a95d4c5ce8e482d257731edb732cedabb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d865c60a5b8a6439daed659641948771510e3863ad9a714e234a33317dd05beeea63b56129ca949b109f4d03b407dd7c14953c0daae6471ddfaef6a7ee873683
|
7
|
+
data.tar.gz: f6376738e82c571f3666b3610d2aac081df78150093ae065111985cc907d6342d375c98d69015a30aecec6bef454ff55095438378a2fb5c83c6b639b4379cd6a
|
data/README.md
CHANGED
@@ -13,15 +13,23 @@ Add it to your Gemfile.
|
|
13
13
|
gem 'browser-timezone-rails'
|
14
14
|
```
|
15
15
|
|
16
|
-
|
16
|
+
Make sure you have each of the following entries in your application.js:
|
17
17
|
```
|
18
|
-
//= require
|
18
|
+
//= require jquery
|
19
|
+
//= require jquery.cookie
|
20
|
+
//= require jstz
|
21
|
+
//= require browser_timezone_rails/set_time_zone
|
19
22
|
```
|
23
|
+
That's it! No other configuration is needed as it's all done for you with this gem including setting up your application controller to start using your users' zones.
|
20
24
|
|
21
25
|
## How it works
|
22
26
|
|
23
27
|
The browsers timezone is set in a cookie using the awesome [jsTimezoneDetect](https://bitbucket.org/pellepim/jstimezonedetect) javascript library. That cookie is then read during each request to set the Rails timezone for that user.
|
24
28
|
|
29
|
+
You can also read more about this implementation here: [Blog](http://cowjumpedoverthecommodore64.blogspot.in/2013/03/setting-rails-timezone-to-users.html)
|
30
|
+
|
31
|
+
For those of you who need or want to do this on the backend with just Rails, Ryan Bates has a good RailsCast on how to that: [RailsCast #106](http://railscasts.com/episodes/106-time-zones-revised)
|
32
|
+
|
25
33
|
### About that cookie
|
26
34
|
The cookie is set each full page request and lives for 365 days
|
27
35
|
|
metadata
CHANGED
@@ -1,97 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browser-timezone-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kbaum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jquery-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jquery-cookie-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jstz-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rspec-rails
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- -
|
73
|
+
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
75
|
version: '0'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- -
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: capybara
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- -
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
89
|
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- -
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: launchy
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- -
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
103
|
version: '0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- -
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: sqlite3
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- -
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
117
|
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- -
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
description: The browser timezone is set on the Time#zone
|
@@ -104,10 +132,7 @@ files:
|
|
104
132
|
- MIT-LICENSE
|
105
133
|
- README.md
|
106
134
|
- Rakefile
|
107
|
-
- app/assets/javascripts/browser_timezone_rails/application.js
|
108
135
|
- app/assets/javascripts/browser_timezone_rails/set_time_zone.js.coffee
|
109
|
-
- app/assets/javascripts/jquery.cookie.js
|
110
|
-
- app/assets/javascripts/jstz.js
|
111
136
|
- app/controllers/browser_timezone_rails/application_controller.rb
|
112
137
|
- config/routes.rb
|
113
138
|
- lib/browser-timezone-rails.rb
|
@@ -122,17 +147,17 @@ require_paths:
|
|
122
147
|
- lib
|
123
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
149
|
requirements:
|
125
|
-
- -
|
150
|
+
- - ">="
|
126
151
|
- !ruby/object:Gem::Version
|
127
152
|
version: '0'
|
128
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
154
|
requirements:
|
130
|
-
- -
|
155
|
+
- - ">="
|
131
156
|
- !ruby/object:Gem::Version
|
132
157
|
version: '0'
|
133
158
|
requirements: []
|
134
159
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.4.3
|
136
161
|
signing_key:
|
137
162
|
specification_version: 4
|
138
163
|
summary: Sets the browser timezone within rails
|
@@ -1,17 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// the compiled file.
|
9
|
-
//
|
10
|
-
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
-
// GO AFTER THE REQUIRES BELOW.
|
12
|
-
//
|
13
|
-
//= require jquery
|
14
|
-
//= require jquery_ujs
|
15
|
-
//= require jquery.cookie
|
16
|
-
//= require jstz
|
17
|
-
//= require browser_timezone_rails/set_time_zone
|
@@ -1,72 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* jQuery Cookie Plugin v1.3
|
3
|
-
* https://github.com/carhartl/jquery-cookie
|
4
|
-
*
|
5
|
-
* Copyright 2011, Klaus Hartl
|
6
|
-
* Dual licensed under the MIT or GPL Version 2 licenses.
|
7
|
-
* http://www.opensource.org/licenses/mit-license.php
|
8
|
-
* http://www.opensource.org/licenses/GPL-2.0
|
9
|
-
*/
|
10
|
-
(function ($, document, undefined) {
|
11
|
-
|
12
|
-
var pluses = /\+/g;
|
13
|
-
|
14
|
-
function raw(s) {
|
15
|
-
return s;
|
16
|
-
}
|
17
|
-
|
18
|
-
function decoded(s) {
|
19
|
-
return decodeURIComponent(s.replace(pluses, ' '));
|
20
|
-
}
|
21
|
-
|
22
|
-
var config = $.cookie = function (key, value, options) {
|
23
|
-
|
24
|
-
// write
|
25
|
-
if (value !== undefined) {
|
26
|
-
options = $.extend({}, config.defaults, options);
|
27
|
-
|
28
|
-
if (value === null) {
|
29
|
-
options.expires = -1;
|
30
|
-
}
|
31
|
-
|
32
|
-
if (typeof options.expires === 'number') {
|
33
|
-
var days = options.expires, t = options.expires = new Date();
|
34
|
-
t.setDate(t.getDate() + days);
|
35
|
-
}
|
36
|
-
|
37
|
-
value = config.json ? JSON.stringify(value) : String(value);
|
38
|
-
|
39
|
-
return (document.cookie = [
|
40
|
-
encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
|
41
|
-
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
42
|
-
options.path ? '; path=' + options.path : '',
|
43
|
-
options.domain ? '; domain=' + options.domain : '',
|
44
|
-
options.secure ? '; secure' : ''
|
45
|
-
].join(''));
|
46
|
-
}
|
47
|
-
|
48
|
-
// read
|
49
|
-
var decode = config.raw ? raw : decoded;
|
50
|
-
var cookies = document.cookie.split('; ');
|
51
|
-
for (var i = 0, l = cookies.length; i < l; i++) {
|
52
|
-
var parts = cookies[i].split('=');
|
53
|
-
if (decode(parts.shift()) === key) {
|
54
|
-
var cookie = decode(parts.join('='));
|
55
|
-
return config.json ? JSON.parse(cookie) : cookie;
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
return null;
|
60
|
-
};
|
61
|
-
|
62
|
-
config.defaults = {};
|
63
|
-
|
64
|
-
$.removeCookie = function (key, options) {
|
65
|
-
if ($.cookie(key) !== null) {
|
66
|
-
$.cookie(key, null, options);
|
67
|
-
return true;
|
68
|
-
}
|
69
|
-
return false;
|
70
|
-
};
|
71
|
-
|
72
|
-
})(jQuery, document);
|
@@ -1,358 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This script gives you the zone info key representing your device's time zone setting.
|
3
|
-
*
|
4
|
-
* @name jsTimezoneDetect
|
5
|
-
* @version 1.0.5
|
6
|
-
* @author Jon Nylander
|
7
|
-
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
8
|
-
*
|
9
|
-
* For usage and examples, visit:
|
10
|
-
* http://pellepim.bitbucket.org/jstz/
|
11
|
-
*
|
12
|
-
* Copyright (c) Jon Nylander
|
13
|
-
*/
|
14
|
-
|
15
|
-
/*jslint undef: true */
|
16
|
-
/*global console, exports*/
|
17
|
-
|
18
|
-
(function(root) {
|
19
|
-
/**
|
20
|
-
* Namespace to hold all the code for timezone detection.
|
21
|
-
*/
|
22
|
-
var jstz = (function () {
|
23
|
-
'use strict';
|
24
|
-
var HEMISPHERE_SOUTH = 's',
|
25
|
-
|
26
|
-
/**
|
27
|
-
* Gets the offset in minutes from UTC for a certain date.
|
28
|
-
* @param {Date} date
|
29
|
-
* @returns {Number}
|
30
|
-
*/
|
31
|
-
get_date_offset = function (date) {
|
32
|
-
var offset = -date.getTimezoneOffset();
|
33
|
-
return (offset !== null ? offset : 0);
|
34
|
-
},
|
35
|
-
|
36
|
-
get_date = function (year, month, date) {
|
37
|
-
var d = new Date();
|
38
|
-
if (year !== undefined) {
|
39
|
-
d.setFullYear(year);
|
40
|
-
}
|
41
|
-
d.setMonth(month);
|
42
|
-
d.setDate(date);
|
43
|
-
return d;
|
44
|
-
},
|
45
|
-
|
46
|
-
get_january_offset = function (year) {
|
47
|
-
return get_date_offset(get_date(year, 0 ,2));
|
48
|
-
},
|
49
|
-
|
50
|
-
get_june_offset = function (year) {
|
51
|
-
return get_date_offset(get_date(year, 5, 2));
|
52
|
-
},
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Private method.
|
56
|
-
* Checks whether a given date is in daylight saving time.
|
57
|
-
* If the date supplied is after august, we assume that we're checking
|
58
|
-
* for southern hemisphere DST.
|
59
|
-
* @param {Date} date
|
60
|
-
* @returns {Boolean}
|
61
|
-
*/
|
62
|
-
date_is_dst = function (date) {
|
63
|
-
var is_southern = date.getMonth() > 7,
|
64
|
-
base_offset = is_southern ? get_june_offset(date.getFullYear()) :
|
65
|
-
get_january_offset(date.getFullYear()),
|
66
|
-
date_offset = get_date_offset(date),
|
67
|
-
is_west = base_offset < 0,
|
68
|
-
dst_offset = base_offset - date_offset;
|
69
|
-
|
70
|
-
if (!is_west && !is_southern) {
|
71
|
-
return dst_offset < 0;
|
72
|
-
}
|
73
|
-
|
74
|
-
return dst_offset !== 0;
|
75
|
-
},
|
76
|
-
|
77
|
-
/**
|
78
|
-
* This function does some basic calculations to create information about
|
79
|
-
* the user's timezone. It uses REFERENCE_YEAR as a solid year for which
|
80
|
-
* the script has been tested rather than depend on the year set by the
|
81
|
-
* client device.
|
82
|
-
*
|
83
|
-
* Returns a key that can be used to do lookups in jstz.olson.timezones.
|
84
|
-
* eg: "720,1,2".
|
85
|
-
*
|
86
|
-
* @returns {String}
|
87
|
-
*/
|
88
|
-
|
89
|
-
lookup_key = function () {
|
90
|
-
var january_offset = get_january_offset(),
|
91
|
-
june_offset = get_june_offset(),
|
92
|
-
diff = january_offset - june_offset;
|
93
|
-
|
94
|
-
if (diff < 0) {
|
95
|
-
return january_offset + ",1";
|
96
|
-
} else if (diff > 0) {
|
97
|
-
return june_offset + ",1," + HEMISPHERE_SOUTH;
|
98
|
-
}
|
99
|
-
|
100
|
-
return january_offset + ",0";
|
101
|
-
},
|
102
|
-
|
103
|
-
/**
|
104
|
-
* Uses get_timezone_info() to formulate a key to use in the olson.timezones dictionary.
|
105
|
-
*
|
106
|
-
* Returns a primitive object on the format:
|
107
|
-
* {'timezone': TimeZone, 'key' : 'the key used to find the TimeZone object'}
|
108
|
-
*
|
109
|
-
* @returns Object
|
110
|
-
*/
|
111
|
-
determine = function () {
|
112
|
-
var key = lookup_key();
|
113
|
-
return new jstz.TimeZone(jstz.olson.timezones[key]);
|
114
|
-
},
|
115
|
-
|
116
|
-
/**
|
117
|
-
* This object contains information on when daylight savings starts for
|
118
|
-
* different timezones.
|
119
|
-
*
|
120
|
-
* The list is short for a reason. Often we do not have to be very specific
|
121
|
-
* to single out the correct timezone. But when we do, this list comes in
|
122
|
-
* handy.
|
123
|
-
*
|
124
|
-
* Each value is a date denoting when daylight savings starts for that timezone.
|
125
|
-
*/
|
126
|
-
dst_start_for = function (tz_name) {
|
127
|
-
|
128
|
-
var ru_pre_dst_change = new Date(2010, 6, 15, 1, 0, 0, 0), // In 2010 Russia had DST, this allows us to detect Russia :)
|
129
|
-
dst_starts = {
|
130
|
-
'America/Denver': new Date(2011, 2, 13, 3, 0, 0, 0),
|
131
|
-
'America/Mazatlan': new Date(2011, 3, 3, 3, 0, 0, 0),
|
132
|
-
'America/Chicago': new Date(2011, 2, 13, 3, 0, 0, 0),
|
133
|
-
'America/Mexico_City': new Date(2011, 3, 3, 3, 0, 0, 0),
|
134
|
-
'America/Asuncion': new Date(2012, 9, 7, 3, 0, 0, 0),
|
135
|
-
'America/Santiago': new Date(2012, 9, 3, 3, 0, 0, 0),
|
136
|
-
'America/Campo_Grande': new Date(2012, 9, 21, 5, 0, 0, 0),
|
137
|
-
'America/Montevideo': new Date(2011, 9, 2, 3, 0, 0, 0),
|
138
|
-
'America/Sao_Paulo': new Date(2011, 9, 16, 5, 0, 0, 0),
|
139
|
-
'America/Los_Angeles': new Date(2011, 2, 13, 8, 0, 0, 0),
|
140
|
-
'America/Santa_Isabel': new Date(2011, 3, 5, 8, 0, 0, 0),
|
141
|
-
'America/Havana': new Date(2012, 2, 10, 2, 0, 0, 0),
|
142
|
-
'America/New_York': new Date(2012, 2, 10, 7, 0, 0, 0),
|
143
|
-
'Europe/Helsinki': new Date(2013, 2, 31, 5, 0, 0, 0),
|
144
|
-
'Pacific/Auckland': new Date(2011, 8, 26, 7, 0, 0, 0),
|
145
|
-
'America/Halifax': new Date(2011, 2, 13, 6, 0, 0, 0),
|
146
|
-
'America/Goose_Bay': new Date(2011, 2, 13, 2, 1, 0, 0),
|
147
|
-
'America/Miquelon': new Date(2011, 2, 13, 5, 0, 0, 0),
|
148
|
-
'America/Godthab': new Date(2011, 2, 27, 1, 0, 0, 0),
|
149
|
-
'Europe/Moscow': ru_pre_dst_change,
|
150
|
-
'Asia/Amman': new Date(2013, 2, 29, 1, 0, 0, 0),
|
151
|
-
'Asia/Beirut': new Date(2013, 2, 31, 2, 0, 0, 0),
|
152
|
-
'Asia/Damascus': new Date(2013, 3, 6, 2, 0, 0, 0),
|
153
|
-
'Asia/Jerusalem': new Date(2013, 2, 29, 5, 0, 0, 0),
|
154
|
-
'Asia/Yekaterinburg': ru_pre_dst_change,
|
155
|
-
'Asia/Omsk': ru_pre_dst_change,
|
156
|
-
'Asia/Krasnoyarsk': ru_pre_dst_change,
|
157
|
-
'Asia/Irkutsk': ru_pre_dst_change,
|
158
|
-
'Asia/Yakutsk': ru_pre_dst_change,
|
159
|
-
'Asia/Vladivostok': ru_pre_dst_change,
|
160
|
-
'Asia/Baku': new Date(2013, 2, 31, 4, 0, 0),
|
161
|
-
'Asia/Yerevan': new Date(2013, 2, 31, 3, 0, 0),
|
162
|
-
'Asia/Kamchatka': ru_pre_dst_change,
|
163
|
-
'Asia/Gaza': new Date(2010, 2, 27, 4, 0, 0),
|
164
|
-
'Africa/Cairo': new Date(2010, 4, 1, 3, 0, 0),
|
165
|
-
'Europe/Minsk': ru_pre_dst_change,
|
166
|
-
'Pacific/Apia': new Date(2010, 10, 1, 1, 0, 0, 0),
|
167
|
-
'Pacific/Fiji': new Date(2010, 11, 1, 0, 0, 0),
|
168
|
-
'Australia/Perth': new Date(2008, 10, 1, 1, 0, 0, 0)
|
169
|
-
};
|
170
|
-
|
171
|
-
return dst_starts[tz_name];
|
172
|
-
};
|
173
|
-
|
174
|
-
return {
|
175
|
-
determine: determine,
|
176
|
-
date_is_dst: date_is_dst,
|
177
|
-
dst_start_for: dst_start_for
|
178
|
-
};
|
179
|
-
}());
|
180
|
-
|
181
|
-
/**
|
182
|
-
* Simple object to perform ambiguity check and to return name of time zone.
|
183
|
-
*/
|
184
|
-
jstz.TimeZone = function (tz_name) {
|
185
|
-
'use strict';
|
186
|
-
/**
|
187
|
-
* The keys in this object are timezones that we know may be ambiguous after
|
188
|
-
* a preliminary scan through the olson_tz object.
|
189
|
-
*
|
190
|
-
* The array of timezones to compare must be in the order that daylight savings
|
191
|
-
* starts for the regions.
|
192
|
-
*/
|
193
|
-
var AMBIGUITIES = {
|
194
|
-
'America/Denver': ['America/Denver', 'America/Mazatlan'],
|
195
|
-
'America/Chicago': ['America/Chicago', 'America/Mexico_City'],
|
196
|
-
'America/Santiago': ['America/Santiago', 'America/Asuncion', 'America/Campo_Grande'],
|
197
|
-
'America/Montevideo': ['America/Montevideo', 'America/Sao_Paulo'],
|
198
|
-
'Asia/Beirut': ['Asia/Amman', 'Asia/Jerusalem', 'Asia/Beirut', 'Europe/Helsinki','Asia/Damascus'],
|
199
|
-
'Pacific/Auckland': ['Pacific/Auckland', 'Pacific/Fiji'],
|
200
|
-
'America/Los_Angeles': ['America/Los_Angeles', 'America/Santa_Isabel'],
|
201
|
-
'America/New_York': ['America/Havana', 'America/New_York'],
|
202
|
-
'America/Halifax': ['America/Goose_Bay', 'America/Halifax'],
|
203
|
-
'America/Godthab': ['America/Miquelon', 'America/Godthab'],
|
204
|
-
'Asia/Dubai': ['Europe/Moscow'],
|
205
|
-
'Asia/Dhaka': ['Asia/Yekaterinburg'],
|
206
|
-
'Asia/Jakarta': ['Asia/Omsk'],
|
207
|
-
'Asia/Shanghai': ['Asia/Krasnoyarsk', 'Australia/Perth'],
|
208
|
-
'Asia/Tokyo': ['Asia/Irkutsk'],
|
209
|
-
'Australia/Brisbane': ['Asia/Yakutsk'],
|
210
|
-
'Pacific/Noumea': ['Asia/Vladivostok'],
|
211
|
-
'Pacific/Tarawa': ['Asia/Kamchatka', 'Pacific/Fiji'],
|
212
|
-
'Pacific/Tongatapu': ['Pacific/Apia'],
|
213
|
-
'Asia/Baghdad': ['Europe/Minsk'],
|
214
|
-
'Asia/Baku': ['Asia/Yerevan','Asia/Baku'],
|
215
|
-
'Africa/Johannesburg': ['Asia/Gaza', 'Africa/Cairo']
|
216
|
-
},
|
217
|
-
|
218
|
-
timezone_name = tz_name,
|
219
|
-
|
220
|
-
/**
|
221
|
-
* Checks if a timezone has possible ambiguities. I.e timezones that are similar.
|
222
|
-
*
|
223
|
-
* For example, if the preliminary scan determines that we're in America/Denver.
|
224
|
-
* We double check here that we're really there and not in America/Mazatlan.
|
225
|
-
*
|
226
|
-
* This is done by checking known dates for when daylight savings start for different
|
227
|
-
* timezones during 2010 and 2011.
|
228
|
-
*/
|
229
|
-
ambiguity_check = function () {
|
230
|
-
var ambiguity_list = AMBIGUITIES[timezone_name],
|
231
|
-
length = ambiguity_list.length,
|
232
|
-
i = 0,
|
233
|
-
tz = ambiguity_list[0];
|
234
|
-
|
235
|
-
for (; i < length; i += 1) {
|
236
|
-
tz = ambiguity_list[i];
|
237
|
-
|
238
|
-
if (jstz.date_is_dst(jstz.dst_start_for(tz))) {
|
239
|
-
timezone_name = tz;
|
240
|
-
return;
|
241
|
-
}
|
242
|
-
}
|
243
|
-
},
|
244
|
-
|
245
|
-
/**
|
246
|
-
* Checks if it is possible that the timezone is ambiguous.
|
247
|
-
*/
|
248
|
-
is_ambiguous = function () {
|
249
|
-
return typeof (AMBIGUITIES[timezone_name]) !== 'undefined';
|
250
|
-
};
|
251
|
-
|
252
|
-
if (is_ambiguous()) {
|
253
|
-
ambiguity_check();
|
254
|
-
}
|
255
|
-
|
256
|
-
return {
|
257
|
-
name: function () {
|
258
|
-
return timezone_name;
|
259
|
-
}
|
260
|
-
};
|
261
|
-
};
|
262
|
-
|
263
|
-
jstz.olson = {};
|
264
|
-
|
265
|
-
/*
|
266
|
-
* The keys in this dictionary are comma separated as such:
|
267
|
-
*
|
268
|
-
* First the offset compared to UTC time in minutes.
|
269
|
-
*
|
270
|
-
* Then a flag which is 0 if the timezone does not take daylight savings into account and 1 if it
|
271
|
-
* does.
|
272
|
-
*
|
273
|
-
* Thirdly an optional 's' signifies that the timezone is in the southern hemisphere,
|
274
|
-
* only interesting for timezones with DST.
|
275
|
-
*
|
276
|
-
* The mapped arrays is used for constructing the jstz.TimeZone object from within
|
277
|
-
* jstz.determine_timezone();
|
278
|
-
*/
|
279
|
-
jstz.olson.timezones = {
|
280
|
-
'-720,0' : 'Pacific/Majuro',
|
281
|
-
'-660,0' : 'Pacific/Pago_Pago',
|
282
|
-
'-600,1' : 'America/Adak',
|
283
|
-
'-600,0' : 'Pacific/Honolulu',
|
284
|
-
'-570,0' : 'Pacific/Marquesas',
|
285
|
-
'-540,0' : 'Pacific/Gambier',
|
286
|
-
'-540,1' : 'America/Anchorage',
|
287
|
-
'-480,1' : 'America/Los_Angeles',
|
288
|
-
'-480,0' : 'Pacific/Pitcairn',
|
289
|
-
'-420,0' : 'America/Phoenix',
|
290
|
-
'-420,1' : 'America/Denver',
|
291
|
-
'-360,0' : 'America/Guatemala',
|
292
|
-
'-360,1' : 'America/Chicago',
|
293
|
-
'-360,1,s' : 'Pacific/Easter',
|
294
|
-
'-300,0' : 'America/Bogota',
|
295
|
-
'-300,1' : 'America/New_York',
|
296
|
-
'-270,0' : 'America/Caracas',
|
297
|
-
'-240,1' : 'America/Halifax',
|
298
|
-
'-240,0' : 'America/Santo_Domingo',
|
299
|
-
'-240,1,s' : 'America/Santiago',
|
300
|
-
'-210,1' : 'America/St_Johns',
|
301
|
-
'-180,1' : 'America/Godthab',
|
302
|
-
'-180,0' : 'America/Argentina/Buenos_Aires',
|
303
|
-
'-180,1,s' : 'America/Montevideo',
|
304
|
-
'-120,0' : 'America/Noronha',
|
305
|
-
'-120,1' : 'America/Noronha',
|
306
|
-
'-60,1' : 'Atlantic/Azores',
|
307
|
-
'-60,0' : 'Atlantic/Cape_Verde',
|
308
|
-
'0,0' : 'UTC',
|
309
|
-
'0,1' : 'Europe/London',
|
310
|
-
'60,1' : 'Europe/Berlin',
|
311
|
-
'60,0' : 'Africa/Lagos',
|
312
|
-
'60,1,s' : 'Africa/Windhoek',
|
313
|
-
'120,1' : 'Asia/Beirut',
|
314
|
-
'120,0' : 'Africa/Johannesburg',
|
315
|
-
'180,0' : 'Asia/Baghdad',
|
316
|
-
'180,1' : 'Europe/Moscow',
|
317
|
-
'210,1' : 'Asia/Tehran',
|
318
|
-
'240,0' : 'Asia/Dubai',
|
319
|
-
'240,1' : 'Asia/Baku',
|
320
|
-
'270,0' : 'Asia/Kabul',
|
321
|
-
'300,1' : 'Asia/Yekaterinburg',
|
322
|
-
'300,0' : 'Asia/Karachi',
|
323
|
-
'330,0' : 'Asia/Kolkata',
|
324
|
-
'345,0' : 'Asia/Kathmandu',
|
325
|
-
'360,0' : 'Asia/Dhaka',
|
326
|
-
'360,1' : 'Asia/Omsk',
|
327
|
-
'390,0' : 'Asia/Rangoon',
|
328
|
-
'420,1' : 'Asia/Krasnoyarsk',
|
329
|
-
'420,0' : 'Asia/Jakarta',
|
330
|
-
'480,0' : 'Asia/Shanghai',
|
331
|
-
'480,1' : 'Asia/Irkutsk',
|
332
|
-
'525,0' : 'Australia/Eucla',
|
333
|
-
'525,1,s' : 'Australia/Eucla',
|
334
|
-
'540,1' : 'Asia/Yakutsk',
|
335
|
-
'540,0' : 'Asia/Tokyo',
|
336
|
-
'570,0' : 'Australia/Darwin',
|
337
|
-
'570,1,s' : 'Australia/Adelaide',
|
338
|
-
'600,0' : 'Australia/Brisbane',
|
339
|
-
'600,1' : 'Asia/Vladivostok',
|
340
|
-
'600,1,s' : 'Australia/Sydney',
|
341
|
-
'630,1,s' : 'Australia/Lord_Howe',
|
342
|
-
'660,1' : 'Asia/Kamchatka',
|
343
|
-
'660,0' : 'Pacific/Noumea',
|
344
|
-
'690,0' : 'Pacific/Norfolk',
|
345
|
-
'720,1,s' : 'Pacific/Auckland',
|
346
|
-
'720,0' : 'Pacific/Tarawa',
|
347
|
-
'765,1,s' : 'Pacific/Chatham',
|
348
|
-
'780,0' : 'Pacific/Tongatapu',
|
349
|
-
'780,1,s' : 'Pacific/Apia',
|
350
|
-
'840,0' : 'Pacific/Kiritimati'
|
351
|
-
};
|
352
|
-
|
353
|
-
if (typeof exports !== 'undefined') {
|
354
|
-
exports.jstz = jstz;
|
355
|
-
} else {
|
356
|
-
root.jstz = jstz;
|
357
|
-
}
|
358
|
-
})(this);
|