kibana-sinatra 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/kibana-sinatra.gemspec +24 -0
- data/lib/kibana/assets/app/app.js +140 -0
- data/lib/kibana/assets/app/components/extend-jquery.js +46 -0
- data/lib/kibana/assets/app/components/kbn.js +332 -0
- data/lib/kibana/assets/app/components/require.config.js +90 -0
- data/lib/kibana/assets/app/components/settings.js +27 -0
- data/lib/kibana/assets/app/components/underscore.extended.js +32 -0
- data/lib/kibana/assets/app/controllers/all.js +5 -0
- data/lib/kibana/assets/app/controllers/dash.js +91 -0
- data/lib/kibana/assets/app/controllers/dashLoader.js +123 -0
- data/lib/kibana/assets/app/controllers/row.js +76 -0
- data/lib/kibana/assets/app/dashboards/blank.json +42 -0
- data/lib/kibana/assets/app/dashboards/default.json +89 -0
- data/lib/kibana/assets/app/dashboards/guided.json +274 -0
- data/lib/kibana/assets/app/dashboards/logstash.js +181 -0
- data/lib/kibana/assets/app/dashboards/logstash.json +222 -0
- data/lib/kibana/assets/app/dashboards/noted.json +202 -0
- data/lib/kibana/assets/app/directives/addPanel.js +30 -0
- data/lib/kibana/assets/app/directives/all.js +10 -0
- data/lib/kibana/assets/app/directives/arrayJoin.js +34 -0
- data/lib/kibana/assets/app/directives/confirmClick.js +26 -0
- data/lib/kibana/assets/app/directives/dashUpload.js +37 -0
- data/lib/kibana/assets/app/directives/kibanaPanel.js +103 -0
- data/lib/kibana/assets/app/directives/ngBlur.js +20 -0
- data/lib/kibana/assets/app/directives/ngModelOnBlur.js +25 -0
- data/lib/kibana/assets/app/directives/tip.js +20 -0
- data/lib/kibana/assets/app/filters/all.js +110 -0
- data/lib/kibana/assets/app/panels/bettermap/editor.html +17 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/images/layers-2x.png +0 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/images/layers.png +0 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/images/marker-icon-2x.png +0 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/images/marker-icon.png +0 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/images/marker-shadow.png +0 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/leaflet-src.js +8724 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/leaflet.css +463 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/leaflet.ie.css +51 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/leaflet.js +8 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/plugins.css +75 -0
- data/lib/kibana/assets/app/panels/bettermap/leaflet/plugins.js +16 -0
- data/lib/kibana/assets/app/panels/bettermap/module.css +4 -0
- data/lib/kibana/assets/app/panels/bettermap/module.html +6 -0
- data/lib/kibana/assets/app/panels/bettermap/module.js +232 -0
- data/lib/kibana/assets/app/panels/column/editor.html +36 -0
- data/lib/kibana/assets/app/panels/column/module.html +16 -0
- data/lib/kibana/assets/app/panels/column/module.js +105 -0
- data/lib/kibana/assets/app/panels/column/panelgeneral.html +11 -0
- data/lib/kibana/assets/app/panels/dashcontrol/editor.html +44 -0
- data/lib/kibana/assets/app/panels/dashcontrol/load.html +40 -0
- data/lib/kibana/assets/app/panels/dashcontrol/module.html +6 -0
- data/lib/kibana/assets/app/panels/dashcontrol/module.js +198 -0
- data/lib/kibana/assets/app/panels/dashcontrol/save.html +30 -0
- data/lib/kibana/assets/app/panels/dashcontrol/share.html +11 -0
- data/lib/kibana/assets/app/panels/derivequeries/editor.html +23 -0
- data/lib/kibana/assets/app/panels/derivequeries/module.html +33 -0
- data/lib/kibana/assets/app/panels/derivequeries/module.js +160 -0
- data/lib/kibana/assets/app/panels/fields/editor.html +10 -0
- data/lib/kibana/assets/app/panels/fields/micropanel.html +25 -0
- data/lib/kibana/assets/app/panels/fields/module.html +3 -0
- data/lib/kibana/assets/app/panels/fields/module.js +37 -0
- data/lib/kibana/assets/app/panels/filtering/editor.html +7 -0
- data/lib/kibana/assets/app/panels/filtering/meta.html +15 -0
- data/lib/kibana/assets/app/panels/filtering/module.html +78 -0
- data/lib/kibana/assets/app/panels/filtering/module.js +66 -0
- data/lib/kibana/assets/app/panels/histogram/editor.html +74 -0
- data/lib/kibana/assets/app/panels/histogram/interval.js +57 -0
- data/lib/kibana/assets/app/panels/histogram/module.html +91 -0
- data/lib/kibana/assets/app/panels/histogram/module.js +511 -0
- data/lib/kibana/assets/app/panels/histogram/timeSeries.js +179 -0
- data/lib/kibana/assets/app/panels/hits/editor.html +29 -0
- data/lib/kibana/assets/app/panels/hits/module.html +44 -0
- data/lib/kibana/assets/app/panels/hits/module.js +270 -0
- data/lib/kibana/assets/app/panels/map/editor.html +15 -0
- data/lib/kibana/assets/app/panels/map/lib/jquery.jvectormap.min.js +8 -0
- data/lib/kibana/assets/app/panels/map/lib/map.europe.js +1 -0
- data/lib/kibana/assets/app/panels/map/lib/map.usa.js +1 -0
- data/lib/kibana/assets/app/panels/map/lib/map.world.js +1 -0
- data/lib/kibana/assets/app/panels/map/module.html +63 -0
- data/lib/kibana/assets/app/panels/map/module.js +185 -0
- data/lib/kibana/assets/app/panels/pie/editor.html +49 -0
- data/lib/kibana/assets/app/panels/pie/module.html +12 -0
- data/lib/kibana/assets/app/panels/pie/module.js +297 -0
- data/lib/kibana/assets/app/panels/query/editor.html +7 -0
- data/lib/kibana/assets/app/panels/query/meta.html +21 -0
- data/lib/kibana/assets/app/panels/query/module.html +25 -0
- data/lib/kibana/assets/app/panels/query/module.js +69 -0
- data/lib/kibana/assets/app/panels/query/query.css +39 -0
- data/lib/kibana/assets/app/panels/table/editor.html +48 -0
- data/lib/kibana/assets/app/panels/table/micropanel.html +44 -0
- data/lib/kibana/assets/app/panels/table/module.html +104 -0
- data/lib/kibana/assets/app/panels/table/module.js +389 -0
- data/lib/kibana/assets/app/panels/table/pagination.html +27 -0
- data/lib/kibana/assets/app/panels/terms/editor.html +51 -0
- data/lib/kibana/assets/app/panels/terms/module.html +55 -0
- data/lib/kibana/assets/app/panels/terms/module.js +307 -0
- data/lib/kibana/assets/app/panels/text/editor.html +16 -0
- data/lib/kibana/assets/app/panels/text/lib/showdown.js +1454 -0
- data/lib/kibana/assets/app/panels/text/module.html +10 -0
- data/lib/kibana/assets/app/panels/text/module.js +85 -0
- data/lib/kibana/assets/app/panels/timepicker/editor.html +34 -0
- data/lib/kibana/assets/app/panels/timepicker/module.html +73 -0
- data/lib/kibana/assets/app/panels/timepicker/module.js +268 -0
- data/lib/kibana/assets/app/panels/timepicker/refreshctrl.html +5 -0
- data/lib/kibana/assets/app/panels/trends/editor.html +20 -0
- data/lib/kibana/assets/app/panels/trends/module.html +11 -0
- data/lib/kibana/assets/app/panels/trends/module.js +232 -0
- data/lib/kibana/assets/app/partials/dashLoader.html +78 -0
- data/lib/kibana/assets/app/partials/dashLoaderShare.html +11 -0
- data/lib/kibana/assets/app/partials/dashboard.html +77 -0
- data/lib/kibana/assets/app/partials/dasheditor.html +151 -0
- data/lib/kibana/assets/app/partials/inspector.html +15 -0
- data/lib/kibana/assets/app/partials/load.html +4 -0
- data/lib/kibana/assets/app/partials/modal.html +12 -0
- data/lib/kibana/assets/app/partials/paneladd.html +6 -0
- data/lib/kibana/assets/app/partials/paneleditor.html +23 -0
- data/lib/kibana/assets/app/partials/panelgeneral.html +22 -0
- data/lib/kibana/assets/app/partials/querySelect.html +24 -0
- data/lib/kibana/assets/app/partials/roweditor.html +65 -0
- data/lib/kibana/assets/app/services/alertSrv.js +49 -0
- data/lib/kibana/assets/app/services/all.js +11 -0
- data/lib/kibana/assets/app/services/dashboard.js +417 -0
- data/lib/kibana/assets/app/services/fields.js +96 -0
- data/lib/kibana/assets/app/services/filterSrv.js +200 -0
- data/lib/kibana/assets/app/services/kbnIndex.js +101 -0
- data/lib/kibana/assets/app/services/panelMove.js +83 -0
- data/lib/kibana/assets/app/services/querySrv.js +147 -0
- data/lib/kibana/assets/app/services/timer.js +34 -0
- data/lib/kibana/assets/css/animate.min.css +3270 -0
- data/lib/kibana/assets/css/bootstrap-responsive.min.css +9 -0
- data/lib/kibana/assets/css/bootstrap.dark.min.css +9 -0
- data/lib/kibana/assets/css/bootstrap.light.min.css +9 -0
- data/lib/kibana/assets/css/font-awesome.min.css +403 -0
- data/lib/kibana/assets/css/main.css +193 -0
- data/lib/kibana/assets/css/normalize.min.css +1 -0
- data/lib/kibana/assets/css/timepicker.css +423 -0
- data/lib/kibana/assets/font/FontAwesome.otf +0 -0
- data/lib/kibana/assets/font/fontawesome-webfont.eot +0 -0
- data/lib/kibana/assets/font/fontawesome-webfont.svg +399 -0
- data/lib/kibana/assets/font/fontawesome-webfont.ttf +0 -0
- data/lib/kibana/assets/font/fontawesome-webfont.woff +0 -0
- data/lib/kibana/assets/img/glyphicons-halflings-white.png +0 -0
- data/lib/kibana/assets/img/glyphicons-halflings.png +0 -0
- data/lib/kibana/assets/img/kibana.png +0 -0
- data/lib/kibana/assets/img/load.gif +0 -0
- data/lib/kibana/assets/img/load_big.gif +0 -0
- data/lib/kibana/assets/index.html +49 -0
- data/lib/kibana/assets/vendor/angular/angular-dragdrop.js +304 -0
- data/lib/kibana/assets/vendor/angular/angular-sanitize.js +556 -0
- data/lib/kibana/assets/vendor/angular/angular-strap.js +875 -0
- data/lib/kibana/assets/vendor/angular/angular.js +15158 -0
- data/lib/kibana/assets/vendor/angular/datepicker.js +1046 -0
- data/lib/kibana/assets/vendor/angular/timepicker.js +888 -0
- data/lib/kibana/assets/vendor/bootstrap/bootstrap.js +2280 -0
- data/lib/kibana/assets/vendor/bootstrap/less/accordion.less +34 -0
- data/lib/kibana/assets/vendor/bootstrap/less/alerts.less +79 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bootstrap.dark.less +4 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bootstrap.less +63 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bootstrap.light.less +4 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bootswatch.dark.less +554 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bootswatch.light.less +9 -0
- data/lib/kibana/assets/vendor/bootstrap/less/breadcrumbs.less +24 -0
- data/lib/kibana/assets/vendor/bootstrap/less/button-groups.less +229 -0
- data/lib/kibana/assets/vendor/bootstrap/less/buttons.less +228 -0
- data/lib/kibana/assets/vendor/bootstrap/less/carousel.less +158 -0
- data/lib/kibana/assets/vendor/bootstrap/less/close.less +32 -0
- data/lib/kibana/assets/vendor/bootstrap/less/code.less +61 -0
- data/lib/kibana/assets/vendor/bootstrap/less/component-animations.less +22 -0
- data/lib/kibana/assets/vendor/bootstrap/less/dropdowns.less +248 -0
- data/lib/kibana/assets/vendor/bootstrap/less/forms.less +690 -0
- data/lib/kibana/assets/vendor/bootstrap/less/grid.less +21 -0
- data/lib/kibana/assets/vendor/bootstrap/less/hero-unit.less +25 -0
- data/lib/kibana/assets/vendor/bootstrap/less/labels-badges.less +84 -0
- data/lib/kibana/assets/vendor/bootstrap/less/layouts.less +16 -0
- data/lib/kibana/assets/vendor/bootstrap/less/media.less +55 -0
- data/lib/kibana/assets/vendor/bootstrap/less/mixins.less +702 -0
- data/lib/kibana/assets/vendor/bootstrap/less/modals.less +95 -0
- data/lib/kibana/assets/vendor/bootstrap/less/navbar.less +497 -0
- data/lib/kibana/assets/vendor/bootstrap/less/navs.less +409 -0
- data/lib/kibana/assets/vendor/bootstrap/less/overrides.less +237 -0
- data/lib/kibana/assets/vendor/bootstrap/less/pager.less +43 -0
- data/lib/kibana/assets/vendor/bootstrap/less/pagination.less +123 -0
- data/lib/kibana/assets/vendor/bootstrap/less/popovers.less +133 -0
- data/lib/kibana/assets/vendor/bootstrap/less/progress-bars.less +122 -0
- data/lib/kibana/assets/vendor/bootstrap/less/reset.less +216 -0
- data/lib/kibana/assets/vendor/bootstrap/less/responsive-1200px-min.less +28 -0
- data/lib/kibana/assets/vendor/bootstrap/less/responsive-767px-max.less +193 -0
- data/lib/kibana/assets/vendor/bootstrap/less/responsive-768px-979px.less +19 -0
- data/lib/kibana/assets/vendor/bootstrap/less/responsive-navbar.less +189 -0
- data/lib/kibana/assets/vendor/bootstrap/less/responsive-utilities.less +59 -0
- data/lib/kibana/assets/vendor/bootstrap/less/responsive.less +48 -0
- data/lib/kibana/assets/vendor/bootstrap/less/scaffolding.less +53 -0
- data/lib/kibana/assets/vendor/bootstrap/less/sprites.less +197 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tables.less +244 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/buttons.html +139 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/css-tests.css +150 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/css-tests.html +1399 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/forms-responsive.html +71 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/forms.html +179 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/navbar-fixed-top.html +104 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/navbar-static-top.html +107 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tests/navbar.html +107 -0
- data/lib/kibana/assets/vendor/bootstrap/less/thumbnails.less +53 -0
- data/lib/kibana/assets/vendor/bootstrap/less/tooltip.less +70 -0
- data/lib/kibana/assets/vendor/bootstrap/less/type.less +247 -0
- data/lib/kibana/assets/vendor/bootstrap/less/utilities.less +30 -0
- data/lib/kibana/assets/vendor/bootstrap/less/variables.dark.less +304 -0
- data/lib/kibana/assets/vendor/bootstrap/less/variables.less +301 -0
- data/lib/kibana/assets/vendor/bootstrap/less/variables.light.less +301 -0
- data/lib/kibana/assets/vendor/bootstrap/less/wells.less +29 -0
- data/lib/kibana/assets/vendor/elasticjs/elastic-angular-client.js +81 -0
- data/lib/kibana/assets/vendor/elasticjs/elastic.js +19993 -0
- data/lib/kibana/assets/vendor/filesaver.js +216 -0
- data/lib/kibana/assets/vendor/jquery/jquery-1.8.0.js +2 -0
- data/lib/kibana/assets/vendor/jquery/jquery-ui-1.10.3.js +5253 -0
- data/lib/kibana/assets/vendor/jquery/jquery.flot.js +3060 -0
- data/lib/kibana/assets/vendor/jquery/jquery.flot.pie.js +817 -0
- data/lib/kibana/assets/vendor/jquery/jquery.flot.selection.js +360 -0
- data/lib/kibana/assets/vendor/jquery/jquery.flot.stack.js +188 -0
- data/lib/kibana/assets/vendor/jquery/jquery.flot.stackpercent.js +126 -0
- data/lib/kibana/assets/vendor/jquery/jquery.flot.time.js +431 -0
- data/lib/kibana/assets/vendor/modernizr-2.6.1.js +4 -0
- data/lib/kibana/assets/vendor/moment.js +1662 -0
- data/lib/kibana/assets/vendor/require/css-build.js +78 -0
- data/lib/kibana/assets/vendor/require/css.js +23 -0
- data/lib/kibana/assets/vendor/require/require.js +2024 -0
- data/lib/kibana/assets/vendor/require/text.js +386 -0
- data/lib/kibana/assets/vendor/require/tmpl.js +17 -0
- data/lib/kibana/assets/vendor/timezone.js +993 -0
- data/lib/kibana/assets/vendor/underscore.js +1246 -0
- data/lib/kibana/sinatra.rb +3 -0
- data/lib/kibana/sinatra/version.rb +5 -0
- data/lib/kibana/sinatra/web.rb +28 -0
- data/lib/kibana/views/config.erb +54 -0
- metadata +325 -0
@@ -0,0 +1,386 @@
|
|
1
|
+
/**
|
2
|
+
* @license RequireJS text 2.0.10 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
3
|
+
* Available via the MIT or new BSD license.
|
4
|
+
* see: http://github.com/requirejs/text for details
|
5
|
+
*/
|
6
|
+
/*jslint regexp: true */
|
7
|
+
/*global require, XMLHttpRequest, ActiveXObject,
|
8
|
+
define, window, process, Packages,
|
9
|
+
java, location, Components, FileUtils */
|
10
|
+
|
11
|
+
define(['module'], function (module) {
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var text, fs, Cc, Ci, xpcIsWindows,
|
15
|
+
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
|
16
|
+
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
|
17
|
+
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
|
18
|
+
hasLocation = typeof location !== 'undefined' && location.href,
|
19
|
+
defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
|
20
|
+
defaultHostName = hasLocation && location.hostname,
|
21
|
+
defaultPort = hasLocation && (location.port || undefined),
|
22
|
+
buildMap = {},
|
23
|
+
masterConfig = (module.config && module.config()) || {};
|
24
|
+
|
25
|
+
text = {
|
26
|
+
version: '2.0.10',
|
27
|
+
|
28
|
+
strip: function (content) {
|
29
|
+
//Strips <?xml ...?> declarations so that external SVG and XML
|
30
|
+
//documents can be added to a document without worry. Also, if the string
|
31
|
+
//is an HTML document, only the part inside the body tag is returned.
|
32
|
+
if (content) {
|
33
|
+
content = content.replace(xmlRegExp, "");
|
34
|
+
var matches = content.match(bodyRegExp);
|
35
|
+
if (matches) {
|
36
|
+
content = matches[1];
|
37
|
+
}
|
38
|
+
} else {
|
39
|
+
content = "";
|
40
|
+
}
|
41
|
+
return content;
|
42
|
+
},
|
43
|
+
|
44
|
+
jsEscape: function (content) {
|
45
|
+
return content.replace(/(['\\])/g, '\\$1')
|
46
|
+
.replace(/[\f]/g, "\\f")
|
47
|
+
.replace(/[\b]/g, "\\b")
|
48
|
+
.replace(/[\n]/g, "\\n")
|
49
|
+
.replace(/[\t]/g, "\\t")
|
50
|
+
.replace(/[\r]/g, "\\r")
|
51
|
+
.replace(/[\u2028]/g, "\\u2028")
|
52
|
+
.replace(/[\u2029]/g, "\\u2029");
|
53
|
+
},
|
54
|
+
|
55
|
+
createXhr: masterConfig.createXhr || function () {
|
56
|
+
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
|
57
|
+
var xhr, i, progId;
|
58
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
59
|
+
return new XMLHttpRequest();
|
60
|
+
} else if (typeof ActiveXObject !== "undefined") {
|
61
|
+
for (i = 0; i < 3; i += 1) {
|
62
|
+
progId = progIds[i];
|
63
|
+
try {
|
64
|
+
xhr = new ActiveXObject(progId);
|
65
|
+
} catch (e) {}
|
66
|
+
|
67
|
+
if (xhr) {
|
68
|
+
progIds = [progId]; // so faster next time
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
return xhr;
|
75
|
+
},
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Parses a resource name into its component parts. Resource names
|
79
|
+
* look like: module/name.ext!strip, where the !strip part is
|
80
|
+
* optional.
|
81
|
+
* @param {String} name the resource name
|
82
|
+
* @returns {Object} with properties "moduleName", "ext" and "strip"
|
83
|
+
* where strip is a boolean.
|
84
|
+
*/
|
85
|
+
parseName: function (name) {
|
86
|
+
var modName, ext, temp,
|
87
|
+
strip = false,
|
88
|
+
index = name.indexOf("."),
|
89
|
+
isRelative = name.indexOf('./') === 0 ||
|
90
|
+
name.indexOf('../') === 0;
|
91
|
+
|
92
|
+
if (index !== -1 && (!isRelative || index > 1)) {
|
93
|
+
modName = name.substring(0, index);
|
94
|
+
ext = name.substring(index + 1, name.length);
|
95
|
+
} else {
|
96
|
+
modName = name;
|
97
|
+
}
|
98
|
+
|
99
|
+
temp = ext || modName;
|
100
|
+
index = temp.indexOf("!");
|
101
|
+
if (index !== -1) {
|
102
|
+
//Pull off the strip arg.
|
103
|
+
strip = temp.substring(index + 1) === "strip";
|
104
|
+
temp = temp.substring(0, index);
|
105
|
+
if (ext) {
|
106
|
+
ext = temp;
|
107
|
+
} else {
|
108
|
+
modName = temp;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
return {
|
113
|
+
moduleName: modName,
|
114
|
+
ext: ext,
|
115
|
+
strip: strip
|
116
|
+
};
|
117
|
+
},
|
118
|
+
|
119
|
+
xdRegExp: /^((\w+)\:)?\/\/([^\/\\]+)/,
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Is an URL on another domain. Only works for browser use, returns
|
123
|
+
* false in non-browser environments. Only used to know if an
|
124
|
+
* optimized .js version of a text resource should be loaded
|
125
|
+
* instead.
|
126
|
+
* @param {String} url
|
127
|
+
* @returns Boolean
|
128
|
+
*/
|
129
|
+
useXhr: function (url, protocol, hostname, port) {
|
130
|
+
var uProtocol, uHostName, uPort,
|
131
|
+
match = text.xdRegExp.exec(url);
|
132
|
+
if (!match) {
|
133
|
+
return true;
|
134
|
+
}
|
135
|
+
uProtocol = match[2];
|
136
|
+
uHostName = match[3];
|
137
|
+
|
138
|
+
uHostName = uHostName.split(':');
|
139
|
+
uPort = uHostName[1];
|
140
|
+
uHostName = uHostName[0];
|
141
|
+
|
142
|
+
return (!uProtocol || uProtocol === protocol) &&
|
143
|
+
(!uHostName || uHostName.toLowerCase() === hostname.toLowerCase()) &&
|
144
|
+
((!uPort && !uHostName) || uPort === port);
|
145
|
+
},
|
146
|
+
|
147
|
+
finishLoad: function (name, strip, content, onLoad) {
|
148
|
+
content = strip ? text.strip(content) : content;
|
149
|
+
if (masterConfig.isBuild) {
|
150
|
+
buildMap[name] = content;
|
151
|
+
}
|
152
|
+
onLoad(content);
|
153
|
+
},
|
154
|
+
|
155
|
+
load: function (name, req, onLoad, config) {
|
156
|
+
//Name has format: some.module.filext!strip
|
157
|
+
//The strip part is optional.
|
158
|
+
//if strip is present, then that means only get the string contents
|
159
|
+
//inside a body tag in an HTML string. For XML/SVG content it means
|
160
|
+
//removing the <?xml ...?> declarations so the content can be inserted
|
161
|
+
//into the current doc without problems.
|
162
|
+
|
163
|
+
// Do not bother with the work if a build and text will
|
164
|
+
// not be inlined.
|
165
|
+
if (config.isBuild && !config.inlineText) {
|
166
|
+
onLoad();
|
167
|
+
return;
|
168
|
+
}
|
169
|
+
|
170
|
+
masterConfig.isBuild = config.isBuild;
|
171
|
+
|
172
|
+
var parsed = text.parseName(name),
|
173
|
+
nonStripName = parsed.moduleName +
|
174
|
+
(parsed.ext ? '.' + parsed.ext : ''),
|
175
|
+
url = req.toUrl(nonStripName),
|
176
|
+
useXhr = (masterConfig.useXhr) ||
|
177
|
+
text.useXhr;
|
178
|
+
|
179
|
+
// Do not load if it is an empty: url
|
180
|
+
if (url.indexOf('empty:') === 0) {
|
181
|
+
onLoad();
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
|
185
|
+
//Load the text. Use XHR if possible and in a browser.
|
186
|
+
if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
|
187
|
+
text.get(url, function (content) {
|
188
|
+
text.finishLoad(name, parsed.strip, content, onLoad);
|
189
|
+
}, function (err) {
|
190
|
+
if (onLoad.error) {
|
191
|
+
onLoad.error(err);
|
192
|
+
}
|
193
|
+
});
|
194
|
+
} else {
|
195
|
+
//Need to fetch the resource across domains. Assume
|
196
|
+
//the resource has been optimized into a JS module. Fetch
|
197
|
+
//by the module name + extension, but do not include the
|
198
|
+
//!strip part to avoid file system issues.
|
199
|
+
req([nonStripName], function (content) {
|
200
|
+
text.finishLoad(parsed.moduleName + '.' + parsed.ext,
|
201
|
+
parsed.strip, content, onLoad);
|
202
|
+
});
|
203
|
+
}
|
204
|
+
},
|
205
|
+
|
206
|
+
write: function (pluginName, moduleName, write, config) {
|
207
|
+
if (buildMap.hasOwnProperty(moduleName)) {
|
208
|
+
var content = text.jsEscape(buildMap[moduleName]);
|
209
|
+
write.asModule(pluginName + "!" + moduleName,
|
210
|
+
"define(function () { return '" +
|
211
|
+
content +
|
212
|
+
"';});\n");
|
213
|
+
}
|
214
|
+
},
|
215
|
+
|
216
|
+
writeFile: function (pluginName, moduleName, req, write, config) {
|
217
|
+
var parsed = text.parseName(moduleName),
|
218
|
+
extPart = parsed.ext ? '.' + parsed.ext : '',
|
219
|
+
nonStripName = parsed.moduleName + extPart,
|
220
|
+
//Use a '.js' file name so that it indicates it is a
|
221
|
+
//script that can be loaded across domains.
|
222
|
+
fileName = req.toUrl(parsed.moduleName + extPart) + '.js';
|
223
|
+
|
224
|
+
//Leverage own load() method to load plugin value, but only
|
225
|
+
//write out values that do not have the strip argument,
|
226
|
+
//to avoid any potential issues with ! in file names.
|
227
|
+
text.load(nonStripName, req, function (value) {
|
228
|
+
//Use own write() method to construct full module value.
|
229
|
+
//But need to create shell that translates writeFile's
|
230
|
+
//write() to the right interface.
|
231
|
+
var textWrite = function (contents) {
|
232
|
+
return write(fileName, contents);
|
233
|
+
};
|
234
|
+
textWrite.asModule = function (moduleName, contents) {
|
235
|
+
return write.asModule(moduleName, fileName, contents);
|
236
|
+
};
|
237
|
+
|
238
|
+
text.write(pluginName, nonStripName, textWrite, config);
|
239
|
+
}, config);
|
240
|
+
}
|
241
|
+
};
|
242
|
+
|
243
|
+
if (masterConfig.env === 'node' || (!masterConfig.env &&
|
244
|
+
typeof process !== "undefined" &&
|
245
|
+
process.versions &&
|
246
|
+
!!process.versions.node &&
|
247
|
+
!process.versions['node-webkit'])) {
|
248
|
+
//Using special require.nodeRequire, something added by r.js.
|
249
|
+
fs = require.nodeRequire('fs');
|
250
|
+
|
251
|
+
text.get = function (url, callback, errback) {
|
252
|
+
try {
|
253
|
+
var file = fs.readFileSync(url, 'utf8');
|
254
|
+
//Remove BOM (Byte Mark Order) from utf8 files if it is there.
|
255
|
+
if (file.indexOf('\uFEFF') === 0) {
|
256
|
+
file = file.substring(1);
|
257
|
+
}
|
258
|
+
callback(file);
|
259
|
+
} catch (e) {
|
260
|
+
errback(e);
|
261
|
+
}
|
262
|
+
};
|
263
|
+
} else if (masterConfig.env === 'xhr' || (!masterConfig.env &&
|
264
|
+
text.createXhr())) {
|
265
|
+
text.get = function (url, callback, errback, headers) {
|
266
|
+
var xhr = text.createXhr(), header;
|
267
|
+
xhr.open('GET', url, true);
|
268
|
+
|
269
|
+
//Allow plugins direct access to xhr headers
|
270
|
+
if (headers) {
|
271
|
+
for (header in headers) {
|
272
|
+
if (headers.hasOwnProperty(header)) {
|
273
|
+
xhr.setRequestHeader(header.toLowerCase(), headers[header]);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
//Allow overrides specified in config
|
279
|
+
if (masterConfig.onXhr) {
|
280
|
+
masterConfig.onXhr(xhr, url);
|
281
|
+
}
|
282
|
+
|
283
|
+
xhr.onreadystatechange = function (evt) {
|
284
|
+
var status, err;
|
285
|
+
//Do not explicitly handle errors, those should be
|
286
|
+
//visible via console output in the browser.
|
287
|
+
if (xhr.readyState === 4) {
|
288
|
+
status = xhr.status;
|
289
|
+
if (status > 399 && status < 600) {
|
290
|
+
//An http 4xx or 5xx error. Signal an error.
|
291
|
+
err = new Error(url + ' HTTP status: ' + status);
|
292
|
+
err.xhr = xhr;
|
293
|
+
errback(err);
|
294
|
+
} else {
|
295
|
+
callback(xhr.responseText);
|
296
|
+
}
|
297
|
+
|
298
|
+
if (masterConfig.onXhrComplete) {
|
299
|
+
masterConfig.onXhrComplete(xhr, url);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
};
|
303
|
+
xhr.send(null);
|
304
|
+
};
|
305
|
+
} else if (masterConfig.env === 'rhino' || (!masterConfig.env &&
|
306
|
+
typeof Packages !== 'undefined' && typeof java !== 'undefined')) {
|
307
|
+
//Why Java, why is this so awkward?
|
308
|
+
text.get = function (url, callback) {
|
309
|
+
var stringBuffer, line,
|
310
|
+
encoding = "utf-8",
|
311
|
+
file = new java.io.File(url),
|
312
|
+
lineSeparator = java.lang.System.getProperty("line.separator"),
|
313
|
+
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
|
314
|
+
content = '';
|
315
|
+
try {
|
316
|
+
stringBuffer = new java.lang.StringBuffer();
|
317
|
+
line = input.readLine();
|
318
|
+
|
319
|
+
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
|
320
|
+
// http://www.unicode.org/faq/utf_bom.html
|
321
|
+
|
322
|
+
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
|
323
|
+
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
|
324
|
+
if (line && line.length() && line.charAt(0) === 0xfeff) {
|
325
|
+
// Eat the BOM, since we've already found the encoding on this file,
|
326
|
+
// and we plan to concatenating this buffer with others; the BOM should
|
327
|
+
// only appear at the top of a file.
|
328
|
+
line = line.substring(1);
|
329
|
+
}
|
330
|
+
|
331
|
+
if (line !== null) {
|
332
|
+
stringBuffer.append(line);
|
333
|
+
}
|
334
|
+
|
335
|
+
while ((line = input.readLine()) !== null) {
|
336
|
+
stringBuffer.append(lineSeparator);
|
337
|
+
stringBuffer.append(line);
|
338
|
+
}
|
339
|
+
//Make sure we return a JavaScript string and not a Java string.
|
340
|
+
content = String(stringBuffer.toString()); //String
|
341
|
+
} finally {
|
342
|
+
input.close();
|
343
|
+
}
|
344
|
+
callback(content);
|
345
|
+
};
|
346
|
+
} else if (masterConfig.env === 'xpconnect' || (!masterConfig.env &&
|
347
|
+
typeof Components !== 'undefined' && Components.classes &&
|
348
|
+
Components.interfaces)) {
|
349
|
+
//Avert your gaze!
|
350
|
+
Cc = Components.classes,
|
351
|
+
Ci = Components.interfaces;
|
352
|
+
Components.utils['import']('resource://gre/modules/FileUtils.jsm');
|
353
|
+
xpcIsWindows = ('@mozilla.org/windows-registry-key;1' in Cc);
|
354
|
+
|
355
|
+
text.get = function (url, callback) {
|
356
|
+
var inStream, convertStream, fileObj,
|
357
|
+
readData = {};
|
358
|
+
|
359
|
+
if (xpcIsWindows) {
|
360
|
+
url = url.replace(/\//g, '\\');
|
361
|
+
}
|
362
|
+
|
363
|
+
fileObj = new FileUtils.File(url);
|
364
|
+
|
365
|
+
//XPCOM, you so crazy
|
366
|
+
try {
|
367
|
+
inStream = Cc['@mozilla.org/network/file-input-stream;1']
|
368
|
+
.createInstance(Ci.nsIFileInputStream);
|
369
|
+
inStream.init(fileObj, 1, 0, false);
|
370
|
+
|
371
|
+
convertStream = Cc['@mozilla.org/intl/converter-input-stream;1']
|
372
|
+
.createInstance(Ci.nsIConverterInputStream);
|
373
|
+
convertStream.init(inStream, "utf-8", inStream.available(),
|
374
|
+
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
|
375
|
+
|
376
|
+
convertStream.readString(inStream.available(), readData);
|
377
|
+
convertStream.close();
|
378
|
+
inStream.close();
|
379
|
+
callback(readData.value);
|
380
|
+
} catch (e) {
|
381
|
+
throw new Error((fileObj && fileObj.path || '') + ': ' + e);
|
382
|
+
}
|
383
|
+
};
|
384
|
+
}
|
385
|
+
return text;
|
386
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/*jshint unused:false */
|
2
|
+
define(['module'], function (module) {
|
3
|
+
'use strict';
|
4
|
+
|
5
|
+
var masterConfig = (module.config && module.config()) || {};
|
6
|
+
|
7
|
+
return {
|
8
|
+
load: function (name, require, onLoad, config) {
|
9
|
+
var url = require.toUrl(name);
|
10
|
+
require(['text!'+name], function (text) {
|
11
|
+
masterConfig.registerTemplate && masterConfig.registerTemplate(url, text);
|
12
|
+
onLoad(text);
|
13
|
+
});
|
14
|
+
}
|
15
|
+
};
|
16
|
+
|
17
|
+
});
|
@@ -0,0 +1,993 @@
|
|
1
|
+
// -----
|
2
|
+
// The `timezoneJS.Date` object gives you full-blown timezone support, independent from the timezone set on the end-user's machine running the browser. It uses the Olson zoneinfo files for its timezone data.
|
3
|
+
//
|
4
|
+
// The constructor function and setter methods use proxy JavaScript Date objects behind the scenes, so you can use strings like '10/22/2006' with the constructor. You also get the same sensible wraparound behavior with numeric parameters (like setting a value of 14 for the month wraps around to the next March).
|
5
|
+
//
|
6
|
+
// The other significant difference from the built-in JavaScript Date is that `timezoneJS.Date` also has named properties that store the values of year, month, date, etc., so it can be directly serialized to JSON and used for data transfer.
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Copyright 2010 Matthew Eernisse (mde@fleegix.org)
|
10
|
+
* and Open Source Applications Foundation
|
11
|
+
*
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
13
|
+
* you may not use this file except in compliance with the License.
|
14
|
+
* You may obtain a copy of the License at
|
15
|
+
*
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
*
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
21
|
+
* See the License for the specific language governing permissions and
|
22
|
+
* limitations under the License.
|
23
|
+
*
|
24
|
+
* Credits: Ideas included from incomplete JS implementation of Olson
|
25
|
+
* parser, "XMLDAte" by Philippe Goetz (philippe.goetz@wanadoo.fr)
|
26
|
+
*
|
27
|
+
* Contributions:
|
28
|
+
* Jan Niehusmann
|
29
|
+
* Ricky Romero
|
30
|
+
* Preston Hunt (prestonhunt@gmail.com)
|
31
|
+
* Dov. B Katz (dov.katz@morganstanley.com)
|
32
|
+
* Peter Bergström (pbergstr@mac.com)
|
33
|
+
* Long Ho
|
34
|
+
*/
|
35
|
+
(function () {
|
36
|
+
// Standard initialization stuff to make sure the library is
|
37
|
+
// usable on both client and server (node) side.
|
38
|
+
"use strict";
|
39
|
+
var root = this;
|
40
|
+
|
41
|
+
var timezoneJS;
|
42
|
+
if (typeof exports !== 'undefined') {
|
43
|
+
timezoneJS = exports;
|
44
|
+
} else {
|
45
|
+
timezoneJS = root.timezoneJS = {};
|
46
|
+
}
|
47
|
+
|
48
|
+
timezoneJS.VERSION = '0.4.4';
|
49
|
+
|
50
|
+
// Grab the ajax library from global context.
|
51
|
+
// This can be jQuery, Zepto or fleegix.
|
52
|
+
// You can also specify your own transport mechanism by declaring
|
53
|
+
// `timezoneJS.timezone.transport` to a `function`. More details will follow
|
54
|
+
var $ = root.$ || root.jQuery || root.Zepto
|
55
|
+
, fleegix = root.fleegix
|
56
|
+
, _arrIndexOf
|
57
|
+
// Declare constant list of days and months. Unfortunately this doesn't leave room for i18n due to the Olson data being in English itself
|
58
|
+
, DAYS = timezoneJS.Days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
59
|
+
, MONTHS = timezoneJS.Months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
60
|
+
, SHORT_MONTHS = {}
|
61
|
+
, SHORT_DAYS = {}
|
62
|
+
, EXACT_DATE_TIME = {}
|
63
|
+
, TZ_REGEXP = new RegExp('^[a-zA-Z]+/');
|
64
|
+
|
65
|
+
//`{ "Jan": 0, "Feb": 1, "Mar": 2, "Apr": 3, "May": 4, "Jun": 5, "Jul": 6, "Aug": 7, "Sep": 8, "Oct": 9, "Nov": 10, "Dec": 11 }`
|
66
|
+
for (var i = 0; i < MONTHS.length; i++) {
|
67
|
+
SHORT_MONTHS[MONTHS[i].substr(0, 3)] = i;
|
68
|
+
}
|
69
|
+
|
70
|
+
//`{ "Sun": 0, "Mon": 1, "Tue": 2, "Wed": 3, "Thu": 4, "Fri": 5, "Sat": 6 }`
|
71
|
+
for (i = 0; i < DAYS.length; i++) {
|
72
|
+
SHORT_DAYS[DAYS[i].substr(0, 3)] = i;
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
//Handle array indexOf in IE
|
77
|
+
//From https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
|
78
|
+
//Extending Array prototype causes IE to iterate thru extra element
|
79
|
+
_arrIndexOf = Array.prototype.indexOf || function (el) {
|
80
|
+
if (this === null) {
|
81
|
+
throw new TypeError();
|
82
|
+
}
|
83
|
+
var t = Object(this);
|
84
|
+
var len = t.length >>> 0;
|
85
|
+
if (len === 0) {
|
86
|
+
return -1;
|
87
|
+
}
|
88
|
+
var n = 0;
|
89
|
+
if (arguments.length > 1) {
|
90
|
+
n = Number(arguments[1]);
|
91
|
+
if (n != n) { // shortcut for verifying if it's NaN
|
92
|
+
n = 0;
|
93
|
+
} else if (n !== 0 && n !== Infinity && n !== -Infinity) {
|
94
|
+
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
if (n >= len) {
|
98
|
+
return -1;
|
99
|
+
}
|
100
|
+
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
|
101
|
+
for (; k < len; k++) {
|
102
|
+
if (k in t && t[k] === el) {
|
103
|
+
return k;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return -1;
|
107
|
+
};
|
108
|
+
|
109
|
+
|
110
|
+
// Format a number to the length = digits. For ex:
|
111
|
+
//
|
112
|
+
// `_fixWidth(2, 2) = '02'`
|
113
|
+
//
|
114
|
+
// `_fixWidth(1998, 2) = '98'`
|
115
|
+
//
|
116
|
+
// This is used to pad numbers in converting date to string in ISO standard.
|
117
|
+
var _fixWidth = function (number, digits) {
|
118
|
+
if (typeof number !== "number") { throw "not a number: " + number; }
|
119
|
+
var s = number.toString();
|
120
|
+
if (number.length > digits) {
|
121
|
+
return number.substr(number.length - digits, number.length);
|
122
|
+
}
|
123
|
+
while (s.length < digits) {
|
124
|
+
s = '0' + s;
|
125
|
+
}
|
126
|
+
return s;
|
127
|
+
};
|
128
|
+
|
129
|
+
// Abstraction layer for different transport layers, including fleegix/jQuery/Zepto
|
130
|
+
//
|
131
|
+
// Object `opts` include
|
132
|
+
//
|
133
|
+
// - `url`: url to ajax query
|
134
|
+
//
|
135
|
+
// - `async`: true for asynchronous, false otherwise. If false, return value will be response from URL. This is true by default
|
136
|
+
//
|
137
|
+
// - `success`: success callback function
|
138
|
+
//
|
139
|
+
// - `error`: error callback function
|
140
|
+
// Returns response from URL if async is false, otherwise the AJAX request object itself
|
141
|
+
var _transport = function (opts) {
|
142
|
+
if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!$ || typeof $.ajax === 'undefined')) {
|
143
|
+
throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.');
|
144
|
+
}
|
145
|
+
if (!opts) return;
|
146
|
+
if (!opts.url) throw new Error ('URL must be specified');
|
147
|
+
if (!('async' in opts)) opts.async = true;
|
148
|
+
if (!opts.async) {
|
149
|
+
return fleegix && fleegix.xhr
|
150
|
+
? fleegix.xhr.doReq({ url: opts.url, async: false })
|
151
|
+
: $.ajax({ url : opts.url, async : false }).responseText;
|
152
|
+
}
|
153
|
+
return fleegix && fleegix.xhr
|
154
|
+
? fleegix.xhr.send({
|
155
|
+
url : opts.url,
|
156
|
+
method : 'get',
|
157
|
+
handleSuccess : opts.success,
|
158
|
+
handleErr : opts.error
|
159
|
+
})
|
160
|
+
: $.ajax({
|
161
|
+
url : opts.url,
|
162
|
+
dataType: 'text',
|
163
|
+
method : 'GET',
|
164
|
+
error : opts.error,
|
165
|
+
success : opts.success
|
166
|
+
});
|
167
|
+
};
|
168
|
+
|
169
|
+
// Constructor, which is similar to that of the native Date object itself
|
170
|
+
timezoneJS.Date = function () {
|
171
|
+
var args = Array.prototype.slice.apply(arguments)
|
172
|
+
, dt = null
|
173
|
+
, tz = null
|
174
|
+
, arr = [];
|
175
|
+
|
176
|
+
|
177
|
+
//We support several different constructors, including all the ones from `Date` object
|
178
|
+
// with a timezone string at the end.
|
179
|
+
//
|
180
|
+
//- `[tz]`: Returns object with time in `tz` specified.
|
181
|
+
//
|
182
|
+
// - `utcMillis`, `[tz]`: Return object with UTC time = `utcMillis`, in `tz`.
|
183
|
+
//
|
184
|
+
// - `Date`, `[tz]`: Returns object with UTC time = `Date.getTime()`, in `tz`.
|
185
|
+
//
|
186
|
+
// - `year, month, [date,] [hours,] [minutes,] [seconds,] [millis,] [tz]: Same as `Date` object
|
187
|
+
// with tz.
|
188
|
+
//
|
189
|
+
// - `Array`: Can be any combo of the above.
|
190
|
+
//
|
191
|
+
//If 1st argument is an array, we can use it as a list of arguments itself
|
192
|
+
if (Object.prototype.toString.call(args[0]) === '[object Array]') {
|
193
|
+
args = args[0];
|
194
|
+
}
|
195
|
+
if (typeof args[args.length - 1] === 'string' && TZ_REGEXP.test(args[args.length - 1])) {
|
196
|
+
tz = args.pop();
|
197
|
+
}
|
198
|
+
switch (args.length) {
|
199
|
+
case 0:
|
200
|
+
dt = new Date();
|
201
|
+
break;
|
202
|
+
case 1:
|
203
|
+
dt = new Date(args[0]);
|
204
|
+
break;
|
205
|
+
default:
|
206
|
+
for (var i = 0; i < 7; i++) {
|
207
|
+
arr[i] = args[i] || 0;
|
208
|
+
}
|
209
|
+
dt = new Date(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]);
|
210
|
+
break;
|
211
|
+
}
|
212
|
+
|
213
|
+
this._useCache = false;
|
214
|
+
this._tzInfo = {};
|
215
|
+
this._day = 0;
|
216
|
+
this.year = 0;
|
217
|
+
this.month = 0;
|
218
|
+
this.date = 0;
|
219
|
+
this.hours = 0;
|
220
|
+
this.minutes = 0;
|
221
|
+
this.seconds = 0;
|
222
|
+
this.milliseconds = 0;
|
223
|
+
this.timezone = tz || null;
|
224
|
+
//Tricky part:
|
225
|
+
// For the cases where there are 1/2 arguments: `timezoneJS.Date(millis, [tz])` and `timezoneJS.Date(Date, [tz])`. The
|
226
|
+
// Date `dt` created should be in UTC. Thus the way I detect such cases is to determine if `arr` is not populated & `tz`
|
227
|
+
// is specified. Because if `tz` is not specified, `dt` can be in local time.
|
228
|
+
if (arr.length) {
|
229
|
+
this.setFromDateObjProxy(dt);
|
230
|
+
} else {
|
231
|
+
this.setFromTimeProxy(dt.getTime(), tz);
|
232
|
+
}
|
233
|
+
};
|
234
|
+
|
235
|
+
// Implements most of the native Date object
|
236
|
+
timezoneJS.Date.prototype = {
|
237
|
+
getDate: function () { return this.date; },
|
238
|
+
getDay: function () { return this._day; },
|
239
|
+
getFullYear: function () { return this.year; },
|
240
|
+
getMonth: function () { return this.month; },
|
241
|
+
getYear: function () { return this.year - 1900; },
|
242
|
+
getHours: function () { return this.hours; },
|
243
|
+
getMilliseconds: function () { return this.milliseconds; },
|
244
|
+
getMinutes: function () { return this.minutes; },
|
245
|
+
getSeconds: function () { return this.seconds; },
|
246
|
+
getUTCDate: function () { return this.getUTCDateProxy().getUTCDate(); },
|
247
|
+
getUTCDay: function () { return this.getUTCDateProxy().getUTCDay(); },
|
248
|
+
getUTCFullYear: function () { return this.getUTCDateProxy().getUTCFullYear(); },
|
249
|
+
getUTCHours: function () { return this.getUTCDateProxy().getUTCHours(); },
|
250
|
+
getUTCMilliseconds: function () { return this.getUTCDateProxy().getUTCMilliseconds(); },
|
251
|
+
getUTCMinutes: function () { return this.getUTCDateProxy().getUTCMinutes(); },
|
252
|
+
getUTCMonth: function () { return this.getUTCDateProxy().getUTCMonth(); },
|
253
|
+
getUTCSeconds: function () { return this.getUTCDateProxy().getUTCSeconds(); },
|
254
|
+
// Time adjusted to user-specified timezone
|
255
|
+
getTime: function () {
|
256
|
+
return this._timeProxy + (this.getTimezoneOffset() * 60 * 1000);
|
257
|
+
},
|
258
|
+
getTimezone: function () { return this.timezone; },
|
259
|
+
getTimezoneOffset: function () { return this.getTimezoneInfo().tzOffset; },
|
260
|
+
getTimezoneAbbreviation: function () { return this.getTimezoneInfo().tzAbbr; },
|
261
|
+
getTimezoneInfo: function () {
|
262
|
+
if (this._useCache) return this._tzInfo;
|
263
|
+
var res;
|
264
|
+
// If timezone is specified, get the correct timezone info based on the Date given
|
265
|
+
if (this.timezone) {
|
266
|
+
res = this.timezone === 'Etc/UTC' || this.timezone === 'Etc/GMT'
|
267
|
+
? { tzOffset: 0, tzAbbr: 'UTC' }
|
268
|
+
: timezoneJS.timezone.getTzInfo(this._timeProxy, this.timezone);
|
269
|
+
}
|
270
|
+
// If no timezone was specified, use the local browser offset
|
271
|
+
else {
|
272
|
+
res = { tzOffset: this.getLocalOffset(), tzAbbr: null };
|
273
|
+
}
|
274
|
+
this._tzInfo = res;
|
275
|
+
this._useCache = true;
|
276
|
+
return res;
|
277
|
+
},
|
278
|
+
getUTCDateProxy: function () {
|
279
|
+
var dt = new Date(this._timeProxy);
|
280
|
+
dt.setUTCMinutes(dt.getUTCMinutes() + this.getTimezoneOffset());
|
281
|
+
return dt;
|
282
|
+
},
|
283
|
+
setDate: function (date) {
|
284
|
+
this.setAttribute('date', date);
|
285
|
+
return this.getTime();
|
286
|
+
},
|
287
|
+
setFullYear: function (year, month, date) {
|
288
|
+
if (date !== undefined) { this.setAttribute('date', 1); }
|
289
|
+
this.setAttribute('year', year);
|
290
|
+
if (month !== undefined) { this.setAttribute('month', month); }
|
291
|
+
if (date !== undefined) { this.setAttribute('date', date); }
|
292
|
+
return this.getTime();
|
293
|
+
},
|
294
|
+
setMonth: function (month, date) {
|
295
|
+
this.setAttribute('month', month);
|
296
|
+
if (date !== undefined) { this.setAttribute('date', date); }
|
297
|
+
return this.getTime();
|
298
|
+
},
|
299
|
+
setYear: function (year) {
|
300
|
+
year = Number(year);
|
301
|
+
if (0 <= year && year <= 99) { year += 1900; }
|
302
|
+
this.setUTCAttribute('year', year);
|
303
|
+
return this.getTime();
|
304
|
+
},
|
305
|
+
setHours: function (hours, minutes, seconds, milliseconds) {
|
306
|
+
this.setAttribute('hours', hours);
|
307
|
+
if (minutes !== undefined) { this.setAttribute('minutes', minutes); }
|
308
|
+
if (seconds !== undefined) { this.setAttribute('seconds', seconds); }
|
309
|
+
if (milliseconds !== undefined) { this.setAttribute('milliseconds', milliseconds); }
|
310
|
+
return this.getTime();
|
311
|
+
},
|
312
|
+
setMinutes: function (minutes, seconds, milliseconds) {
|
313
|
+
this.setAttribute('minutes', minutes);
|
314
|
+
if (seconds !== undefined) { this.setAttribute('seconds', seconds); }
|
315
|
+
if (milliseconds !== undefined) { this.setAttribute('milliseconds', milliseconds); }
|
316
|
+
return this.getTime();
|
317
|
+
},
|
318
|
+
setSeconds: function (seconds, milliseconds) {
|
319
|
+
this.setAttribute('seconds', seconds);
|
320
|
+
if (milliseconds !== undefined) { this.setAttribute('milliseconds', milliseconds); }
|
321
|
+
return this.getTime();
|
322
|
+
},
|
323
|
+
setMilliseconds: function (milliseconds) {
|
324
|
+
this.setAttribute('milliseconds', milliseconds);
|
325
|
+
return this.getTime();
|
326
|
+
},
|
327
|
+
setTime: function (n) {
|
328
|
+
if (isNaN(n)) { throw new Error('Units must be a number.'); }
|
329
|
+
this.setFromTimeProxy(n, this.timezone);
|
330
|
+
return this.getTime();
|
331
|
+
},
|
332
|
+
setUTCFullYear: function (year, month, date) {
|
333
|
+
if (date !== undefined) { this.setUTCAttribute('date', 1); }
|
334
|
+
this.setUTCAttribute('year', year);
|
335
|
+
if (month !== undefined) { this.setUTCAttribute('month', month); }
|
336
|
+
if (date !== undefined) { this.setUTCAttribute('date', date); }
|
337
|
+
return this.getTime();
|
338
|
+
},
|
339
|
+
setUTCMonth: function (month, date) {
|
340
|
+
this.setUTCAttribute('month', month);
|
341
|
+
if (date !== undefined) { this.setUTCAttribute('date', date); }
|
342
|
+
return this.getTime();
|
343
|
+
},
|
344
|
+
setUTCDate: function (date) {
|
345
|
+
this.setUTCAttribute('date', date);
|
346
|
+
return this.getTime();
|
347
|
+
},
|
348
|
+
setUTCHours: function (hours, minutes, seconds, milliseconds) {
|
349
|
+
this.setUTCAttribute('hours', hours);
|
350
|
+
if (minutes !== undefined) { this.setUTCAttribute('minutes', minutes); }
|
351
|
+
if (seconds !== undefined) { this.setUTCAttribute('seconds', seconds); }
|
352
|
+
if (milliseconds !== undefined) { this.setUTCAttribute('milliseconds', milliseconds); }
|
353
|
+
return this.getTime();
|
354
|
+
},
|
355
|
+
setUTCMinutes: function (minutes, seconds, milliseconds) {
|
356
|
+
this.setUTCAttribute('minutes', minutes);
|
357
|
+
if (seconds !== undefined) { this.setUTCAttribute('seconds', seconds); }
|
358
|
+
if (milliseconds !== undefined) { this.setUTCAttribute('milliseconds', milliseconds); }
|
359
|
+
return this.getTime();
|
360
|
+
},
|
361
|
+
setUTCSeconds: function (seconds, milliseconds) {
|
362
|
+
this.setUTCAttribute('seconds', seconds);
|
363
|
+
if (milliseconds !== undefined) { this.setUTCAttribute('milliseconds', milliseconds); }
|
364
|
+
return this.getTime();
|
365
|
+
},
|
366
|
+
setUTCMilliseconds: function (milliseconds) {
|
367
|
+
this.setUTCAttribute('milliseconds', milliseconds);
|
368
|
+
return this.getTime();
|
369
|
+
},
|
370
|
+
setFromDateObjProxy: function (dt) {
|
371
|
+
this.year = dt.getFullYear();
|
372
|
+
this.month = dt.getMonth();
|
373
|
+
this.date = dt.getDate();
|
374
|
+
this.hours = dt.getHours();
|
375
|
+
this.minutes = dt.getMinutes();
|
376
|
+
this.seconds = dt.getSeconds();
|
377
|
+
this.milliseconds = dt.getMilliseconds();
|
378
|
+
this._day = dt.getDay();
|
379
|
+
this._dateProxy = dt;
|
380
|
+
this._timeProxy = Date.UTC(this.year, this.month, this.date, this.hours, this.minutes, this.seconds, this.milliseconds);
|
381
|
+
this._useCache = false;
|
382
|
+
},
|
383
|
+
setFromTimeProxy: function (utcMillis, tz) {
|
384
|
+
var dt = new Date(utcMillis);
|
385
|
+
var tzOffset;
|
386
|
+
tzOffset = tz ? timezoneJS.timezone.getTzInfo(dt, tz).tzOffset : dt.getTimezoneOffset();
|
387
|
+
dt.setTime(utcMillis + (dt.getTimezoneOffset() - tzOffset) * 60000);
|
388
|
+
this.setFromDateObjProxy(dt);
|
389
|
+
},
|
390
|
+
setAttribute: function (unit, n) {
|
391
|
+
if (isNaN(n)) { throw new Error('Units must be a number.'); }
|
392
|
+
var dt = this._dateProxy;
|
393
|
+
var meth = unit === 'year' ? 'FullYear' : unit.substr(0, 1).toUpperCase() + unit.substr(1);
|
394
|
+
dt['set' + meth](n);
|
395
|
+
this.setFromDateObjProxy(dt);
|
396
|
+
},
|
397
|
+
setUTCAttribute: function (unit, n) {
|
398
|
+
if (isNaN(n)) { throw new Error('Units must be a number.'); }
|
399
|
+
var meth = unit === 'year' ? 'FullYear' : unit.substr(0, 1).toUpperCase() + unit.substr(1);
|
400
|
+
var dt = this.getUTCDateProxy();
|
401
|
+
dt['setUTC' + meth](n);
|
402
|
+
dt.setUTCMinutes(dt.getUTCMinutes() - this.getTimezoneOffset());
|
403
|
+
this.setFromTimeProxy(dt.getTime() + this.getTimezoneOffset() * 60000, this.timezone);
|
404
|
+
},
|
405
|
+
setTimezone: function (tz) {
|
406
|
+
var previousOffset = this.getTimezoneInfo().tzOffset;
|
407
|
+
this.timezone = tz;
|
408
|
+
this._useCache = false;
|
409
|
+
// Set UTC minutes offsets by the delta of the two timezones
|
410
|
+
this.setUTCMinutes(this.getUTCMinutes() - this.getTimezoneInfo().tzOffset + previousOffset);
|
411
|
+
},
|
412
|
+
removeTimezone: function () {
|
413
|
+
this.timezone = null;
|
414
|
+
this._useCache = false;
|
415
|
+
},
|
416
|
+
valueOf: function () { return this.getTime(); },
|
417
|
+
clone: function () {
|
418
|
+
return this.timezone ? new timezoneJS.Date(this.getTime(), this.timezone) : new timezoneJS.Date(this.getTime());
|
419
|
+
},
|
420
|
+
toGMTString: function () { return this.toString('EEE, dd MMM yyyy HH:mm:ss Z', 'Etc/GMT'); },
|
421
|
+
toLocaleString: function () {},
|
422
|
+
toLocaleDateString: function () {},
|
423
|
+
toLocaleTimeString: function () {},
|
424
|
+
toSource: function () {},
|
425
|
+
toISOString: function () { return this.toString('yyyy-MM-ddTHH:mm:ss.SSS', 'Etc/UTC') + 'Z'; },
|
426
|
+
toJSON: function () { return this.toISOString(); },
|
427
|
+
// Allows different format following ISO8601 format:
|
428
|
+
toString: function (format, tz) {
|
429
|
+
// Default format is the same as toISOString
|
430
|
+
if (!format) format = 'yyyy-MM-dd HH:mm:ss';
|
431
|
+
var result = format;
|
432
|
+
var tzInfo = tz ? timezoneJS.timezone.getTzInfo(this.getTime(), tz) : this.getTimezoneInfo();
|
433
|
+
var _this = this;
|
434
|
+
// If timezone is specified, get a clone of the current Date object and modify it
|
435
|
+
if (tz) {
|
436
|
+
_this = this.clone();
|
437
|
+
_this.setTimezone(tz);
|
438
|
+
}
|
439
|
+
var hours = _this.getHours();
|
440
|
+
return result
|
441
|
+
// fix the same characters in Month names
|
442
|
+
.replace(/a+/g, function () { return 'k'; })
|
443
|
+
// `y`: year
|
444
|
+
.replace(/y+/g, function (token) { return _fixWidth(_this.getFullYear(), token.length); })
|
445
|
+
// `d`: date
|
446
|
+
.replace(/d+/g, function (token) { return _fixWidth(_this.getDate(), token.length); })
|
447
|
+
// `m`: minute
|
448
|
+
.replace(/m+/g, function (token) { return _fixWidth(_this.getMinutes(), token.length); })
|
449
|
+
// `s`: second
|
450
|
+
.replace(/s+/g, function (token) { return _fixWidth(_this.getSeconds(), token.length); })
|
451
|
+
// `S`: millisecond
|
452
|
+
.replace(/S+/g, function (token) { return _fixWidth(_this.getMilliseconds(), token.length); })
|
453
|
+
// `M`: month. Note: `MM` will be the numeric representation (e.g February is 02) but `MMM` will be text representation (e.g February is Feb)
|
454
|
+
.replace(/M+/g, function (token) {
|
455
|
+
var _month = _this.getMonth(),
|
456
|
+
_len = token.length;
|
457
|
+
if (_len > 3) {
|
458
|
+
return timezoneJS.Months[_month];
|
459
|
+
} else if (_len > 2) {
|
460
|
+
return timezoneJS.Months[_month].substring(0, _len);
|
461
|
+
}
|
462
|
+
return _fixWidth(_month + 1, _len);
|
463
|
+
})
|
464
|
+
// `k`: AM/PM
|
465
|
+
.replace(/k+/g, function () {
|
466
|
+
if (hours >= 12) {
|
467
|
+
if (hours > 12) {
|
468
|
+
hours -= 12;
|
469
|
+
}
|
470
|
+
return 'PM';
|
471
|
+
}
|
472
|
+
return 'AM';
|
473
|
+
})
|
474
|
+
// `H`: hour
|
475
|
+
.replace(/H+/g, function (token) { return _fixWidth(hours, token.length); })
|
476
|
+
// `E`: day
|
477
|
+
.replace(/E+/g, function (token) { return DAYS[_this.getDay()].substring(0, token.length); })
|
478
|
+
// `Z`: timezone abbreviation
|
479
|
+
.replace(/Z+/gi, function () { return tzInfo.tzAbbr; });
|
480
|
+
},
|
481
|
+
toUTCString: function () { return this.toGMTString(); },
|
482
|
+
civilToJulianDayNumber: function (y, m, d) {
|
483
|
+
var a;
|
484
|
+
// Adjust for zero-based JS-style array
|
485
|
+
m++;
|
486
|
+
if (m > 12) {
|
487
|
+
a = parseInt(m/12, 10);
|
488
|
+
m = m % 12;
|
489
|
+
y += a;
|
490
|
+
}
|
491
|
+
if (m <= 2) {
|
492
|
+
y -= 1;
|
493
|
+
m += 12;
|
494
|
+
}
|
495
|
+
a = Math.floor(y / 100);
|
496
|
+
var b = 2 - a + Math.floor(a / 4)
|
497
|
+
, jDt = Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m + 1)) + d + b - 1524;
|
498
|
+
return jDt;
|
499
|
+
},
|
500
|
+
getLocalOffset: function () {
|
501
|
+
return this._dateProxy.getTimezoneOffset();
|
502
|
+
}
|
503
|
+
};
|
504
|
+
|
505
|
+
|
506
|
+
timezoneJS.timezone = new function () {
|
507
|
+
var _this = this
|
508
|
+
, regionMap = {'Etc':'etcetera','EST':'northamerica','MST':'northamerica','HST':'northamerica','EST5EDT':'northamerica','CST6CDT':'northamerica','MST7MDT':'northamerica','PST8PDT':'northamerica','America':'northamerica','Pacific':'australasia','Atlantic':'europe','Africa':'africa','Indian':'africa','Antarctica':'antarctica','Asia':'asia','Australia':'australasia','Europe':'europe','WET':'europe','CET':'europe','MET':'europe','EET':'europe'}
|
509
|
+
, regionExceptions = {'Pacific/Honolulu':'northamerica','Atlantic/Bermuda':'northamerica','Atlantic/Cape_Verde':'africa','Atlantic/St_Helena':'africa','Indian/Kerguelen':'antarctica','Indian/Chagos':'asia','Indian/Maldives':'asia','Indian/Christmas':'australasia','Indian/Cocos':'australasia','America/Danmarkshavn':'europe','America/Scoresbysund':'europe','America/Godthab':'europe','America/Thule':'europe','Asia/Yekaterinburg':'europe','Asia/Omsk':'europe','Asia/Novosibirsk':'europe','Asia/Krasnoyarsk':'europe','Asia/Irkutsk':'europe','Asia/Yakutsk':'europe','Asia/Vladivostok':'europe','Asia/Sakhalin':'europe','Asia/Magadan':'europe','Asia/Kamchatka':'europe','Asia/Anadyr':'europe','Africa/Ceuta':'europe','America/Argentina/Buenos_Aires':'southamerica','America/Argentina/Cordoba':'southamerica','America/Argentina/Tucuman':'southamerica','America/Argentina/La_Rioja':'southamerica','America/Argentina/San_Juan':'southamerica','America/Argentina/Jujuy':'southamerica','America/Argentina/Catamarca':'southamerica','America/Argentina/Mendoza':'southamerica','America/Argentina/Rio_Gallegos':'southamerica','America/Argentina/Ushuaia':'southamerica','America/Aruba':'southamerica','America/La_Paz':'southamerica','America/Noronha':'southamerica','America/Belem':'southamerica','America/Fortaleza':'southamerica','America/Recife':'southamerica','America/Araguaina':'southamerica','America/Maceio':'southamerica','America/Bahia':'southamerica','America/Sao_Paulo':'southamerica','America/Campo_Grande':'southamerica','America/Cuiaba':'southamerica','America/Porto_Velho':'southamerica','America/Boa_Vista':'southamerica','America/Manaus':'southamerica','America/Eirunepe':'southamerica','America/Rio_Branco':'southamerica','America/Santiago':'southamerica','Pacific/Easter':'southamerica','America/Bogota':'southamerica','America/Curacao':'southamerica','America/Guayaquil':'southamerica','Pacific/Galapagos':'southamerica','Atlantic/Stanley':'southamerica','America/Cayenne':'southamerica','America/Guyana':'southamerica','America/Asuncion':'southamerica','America/Lima':'southamerica','Atlantic/South_Georgia':'southamerica','America/Paramaribo':'southamerica','America/Port_of_Spain':'southamerica','America/Montevideo':'southamerica','America/Caracas':'southamerica'};
|
510
|
+
function invalidTZError(t) { throw new Error('Timezone "' + t + '" is either incorrect, or not loaded in the timezone registry.'); }
|
511
|
+
function builtInLoadZoneFile(fileName, opts) {
|
512
|
+
var url = _this.zoneFileBasePath + '/' + fileName;
|
513
|
+
return !opts || !opts.async
|
514
|
+
? _this.parseZones(_this.transport({ url : url, async : false }))
|
515
|
+
: _this.transport({
|
516
|
+
async: true,
|
517
|
+
url : url,
|
518
|
+
success : function (str) {
|
519
|
+
if (_this.parseZones(str) && typeof opts.callback === 'function') {
|
520
|
+
opts.callback();
|
521
|
+
}
|
522
|
+
return true;
|
523
|
+
},
|
524
|
+
error : function () {
|
525
|
+
throw new Error('Error retrieving "' + url + '" zoneinfo files');
|
526
|
+
}
|
527
|
+
});
|
528
|
+
}
|
529
|
+
function getRegionForTimezone(tz) {
|
530
|
+
var exc = regionExceptions[tz]
|
531
|
+
, reg
|
532
|
+
, ret;
|
533
|
+
if (exc) return exc;
|
534
|
+
reg = tz.split('/')[0];
|
535
|
+
ret = regionMap[reg];
|
536
|
+
// If there's nothing listed in the main regions for this TZ, check the 'backward' links
|
537
|
+
if (ret) return ret;
|
538
|
+
var link = _this.zones[tz];
|
539
|
+
if (typeof link === 'string') {
|
540
|
+
return getRegionForTimezone(link);
|
541
|
+
}
|
542
|
+
// Backward-compat file hasn't loaded yet, try looking in there
|
543
|
+
if (!_this.loadedZones.backward) {
|
544
|
+
// This is for obvious legacy zones (e.g., Iceland) that don't even have a prefix like "America/" that look like normal zones
|
545
|
+
_this.loadZoneFile('backward');
|
546
|
+
return getRegionForTimezone(tz);
|
547
|
+
}
|
548
|
+
invalidTZError(tz);
|
549
|
+
}
|
550
|
+
function parseTimeString(str) {
|
551
|
+
var pat = /(\d+)(?::0*(\d*))?(?::0*(\d*))?([wsugz])?$/;
|
552
|
+
var hms = str.match(pat);
|
553
|
+
hms[1] = parseInt(hms[1], 10);
|
554
|
+
hms[2] = hms[2] ? parseInt(hms[2], 10) : 0;
|
555
|
+
hms[3] = hms[3] ? parseInt(hms[3], 10) : 0;
|
556
|
+
|
557
|
+
return hms;
|
558
|
+
}
|
559
|
+
function processZone(z) {
|
560
|
+
if (!z[3]) { return; }
|
561
|
+
var yea = parseInt(z[3], 10);
|
562
|
+
var mon = 11;
|
563
|
+
var dat = 31;
|
564
|
+
if (z[4]) {
|
565
|
+
mon = SHORT_MONTHS[z[4].substr(0, 3)];
|
566
|
+
dat = parseInt(z[5], 10) || 1;
|
567
|
+
}
|
568
|
+
var string = z[6] ? z[6] : '00:00:00'
|
569
|
+
, t = parseTimeString(string);
|
570
|
+
return [yea, mon, dat, t[1], t[2], t[3]];
|
571
|
+
}
|
572
|
+
function getZone(dt, tz) {
|
573
|
+
var utcMillis = typeof dt === 'number' ? dt : new Date(dt).getTime();
|
574
|
+
var t = tz;
|
575
|
+
var zoneList = _this.zones[t];
|
576
|
+
// Follow links to get to an actual zone
|
577
|
+
while (typeof zoneList === "string") {
|
578
|
+
t = zoneList;
|
579
|
+
zoneList = _this.zones[t];
|
580
|
+
}
|
581
|
+
if (!zoneList) {
|
582
|
+
// Backward-compat file hasn't loaded yet, try looking in there
|
583
|
+
if (!_this.loadedZones.backward) {
|
584
|
+
//This is for backward entries like "America/Fort_Wayne" that
|
585
|
+
// getRegionForTimezone *thinks* it has a region file and zone
|
586
|
+
// for (e.g., America => 'northamerica'), but in reality it's a
|
587
|
+
// legacy zone we need the backward file for.
|
588
|
+
_this.loadZoneFile('backward');
|
589
|
+
return getZone(dt, tz);
|
590
|
+
}
|
591
|
+
invalidTZError(t);
|
592
|
+
}
|
593
|
+
if (zoneList.length === 0) {
|
594
|
+
throw new Error('No Zone found for "' + tz + '" on ' + dt);
|
595
|
+
}
|
596
|
+
//Do backwards lookup since most use cases deal with newer dates.
|
597
|
+
for (var i = zoneList.length - 1; i >= 0; i--) {
|
598
|
+
var z = zoneList[i];
|
599
|
+
if (z[3] && utcMillis > z[3]) break;
|
600
|
+
}
|
601
|
+
return zoneList[i+1];
|
602
|
+
}
|
603
|
+
function getBasicOffset(time) {
|
604
|
+
var off = parseTimeString(time)
|
605
|
+
, adj = time.charAt(0) === '-' ? -1 : 1;
|
606
|
+
off = adj * (((off[1] * 60 + off[2]) * 60 + off[3]) * 1000);
|
607
|
+
return off/60/1000;
|
608
|
+
}
|
609
|
+
|
610
|
+
//if isUTC is true, date is given in UTC, otherwise it's given
|
611
|
+
// in local time (ie. date.getUTC*() returns local time components)
|
612
|
+
function getRule(dt, zone, isUTC) {
|
613
|
+
var date = typeof dt === 'number' ? new Date(dt) : dt;
|
614
|
+
var ruleset = zone[1];
|
615
|
+
var basicOffset = zone[0];
|
616
|
+
|
617
|
+
// If the zone has a DST rule like '1:00', create a rule and return it
|
618
|
+
// instead of looking it up in the parsed rules
|
619
|
+
var staticDstMatch = ruleset.match(/^([0-9]):([0-9][0-9])$/);
|
620
|
+
if (staticDstMatch) {
|
621
|
+
return [-1000000,'max','-','Jan',1,parseTimeString('0:00'),parseInt(staticDstMatch[1]) * 60 + parseInt(staticDstMatch[2]), '-'];
|
622
|
+
}
|
623
|
+
|
624
|
+
//Convert a date to UTC. Depending on the 'type' parameter, the date
|
625
|
+
// parameter may be:
|
626
|
+
//
|
627
|
+
// - `u`, `g`, `z`: already UTC (no adjustment).
|
628
|
+
//
|
629
|
+
// - `s`: standard time (adjust for time zone offset but not for DST)
|
630
|
+
//
|
631
|
+
// - `w`: wall clock time (adjust for both time zone and DST offset).
|
632
|
+
//
|
633
|
+
// DST adjustment is done using the rule given as third argument.
|
634
|
+
var convertDateToUTC = function (date, type, rule) {
|
635
|
+
var offset = 0;
|
636
|
+
|
637
|
+
if (type === 'u' || type === 'g' || type === 'z') { // UTC
|
638
|
+
offset = 0;
|
639
|
+
} else if (type === 's') { // Standard Time
|
640
|
+
offset = basicOffset;
|
641
|
+
} else if (type === 'w' || !type) { // Wall Clock Time
|
642
|
+
offset = getAdjustedOffset(basicOffset, rule);
|
643
|
+
} else {
|
644
|
+
throw("unknown type " + type);
|
645
|
+
}
|
646
|
+
offset *= 60 * 1000; // to millis
|
647
|
+
|
648
|
+
return new Date(date.getTime() + offset);
|
649
|
+
};
|
650
|
+
|
651
|
+
//Step 1: Find applicable rules for this year.
|
652
|
+
//
|
653
|
+
//Step 2: Sort the rules by effective date.
|
654
|
+
//
|
655
|
+
//Step 3: Check requested date to see if a rule has yet taken effect this year. If not,
|
656
|
+
//
|
657
|
+
//Step 4: Get the rules for the previous year. If there isn't an applicable rule for last year, then
|
658
|
+
// there probably is no current time offset since they seem to explicitly turn off the offset
|
659
|
+
// when someone stops observing DST.
|
660
|
+
//
|
661
|
+
// FIXME if this is not the case and we'll walk all the way back (ugh).
|
662
|
+
//
|
663
|
+
//Step 5: Sort the rules by effective date.
|
664
|
+
//Step 6: Apply the most recent rule before the current time.
|
665
|
+
var convertRuleToExactDateAndTime = function (yearAndRule, prevRule) {
|
666
|
+
var year = yearAndRule[0]
|
667
|
+
, rule = yearAndRule[1];
|
668
|
+
// Assume that the rule applies to the year of the given date.
|
669
|
+
|
670
|
+
var hms = rule[5];
|
671
|
+
var effectiveDate;
|
672
|
+
|
673
|
+
if (!EXACT_DATE_TIME[year])
|
674
|
+
EXACT_DATE_TIME[year] = {};
|
675
|
+
|
676
|
+
// Result for given parameters is already stored
|
677
|
+
if (EXACT_DATE_TIME[year][rule])
|
678
|
+
effectiveDate = EXACT_DATE_TIME[year][rule];
|
679
|
+
else {
|
680
|
+
//If we have a specific date, use that!
|
681
|
+
if (!isNaN(rule[4])) {
|
682
|
+
effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]], rule[4], hms[1], hms[2], hms[3], 0));
|
683
|
+
}
|
684
|
+
//Let's hunt for the date.
|
685
|
+
else {
|
686
|
+
var targetDay
|
687
|
+
, operator;
|
688
|
+
//Example: `lastThu`
|
689
|
+
if (rule[4].substr(0, 4) === "last") {
|
690
|
+
// Start at the last day of the month and work backward.
|
691
|
+
effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]] + 1, 1, hms[1] - 24, hms[2], hms[3], 0));
|
692
|
+
targetDay = SHORT_DAYS[rule[4].substr(4, 3)];
|
693
|
+
operator = "<=";
|
694
|
+
}
|
695
|
+
//Example: `Sun>=15`
|
696
|
+
else {
|
697
|
+
//Start at the specified date.
|
698
|
+
effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]], rule[4].substr(5), hms[1], hms[2], hms[3], 0));
|
699
|
+
targetDay = SHORT_DAYS[rule[4].substr(0, 3)];
|
700
|
+
operator = rule[4].substr(3, 2);
|
701
|
+
}
|
702
|
+
var ourDay = effectiveDate.getUTCDay();
|
703
|
+
//Go forwards.
|
704
|
+
if (operator === ">=") {
|
705
|
+
effectiveDate.setUTCDate(effectiveDate.getUTCDate() + (targetDay - ourDay + ((targetDay < ourDay) ? 7 : 0)));
|
706
|
+
}
|
707
|
+
//Go backwards. Looking for the last of a certain day, or operator is "<=" (less likely).
|
708
|
+
else {
|
709
|
+
effectiveDate.setUTCDate(effectiveDate.getUTCDate() + (targetDay - ourDay - ((targetDay > ourDay) ? 7 : 0)));
|
710
|
+
}
|
711
|
+
}
|
712
|
+
EXACT_DATE_TIME[year][rule] = effectiveDate;
|
713
|
+
}
|
714
|
+
|
715
|
+
|
716
|
+
//If previous rule is given, correct for the fact that the starting time of the current
|
717
|
+
// rule may be specified in local time.
|
718
|
+
if (prevRule) {
|
719
|
+
effectiveDate = convertDateToUTC(effectiveDate, hms[4], prevRule);
|
720
|
+
}
|
721
|
+
return effectiveDate;
|
722
|
+
};
|
723
|
+
|
724
|
+
var findApplicableRules = function (year, ruleset) {
|
725
|
+
var applicableRules = [];
|
726
|
+
for (var i = 0; ruleset && i < ruleset.length; i++) {
|
727
|
+
//Exclude future rules.
|
728
|
+
if (ruleset[i][0] <= year &&
|
729
|
+
(
|
730
|
+
// Date is in a set range.
|
731
|
+
ruleset[i][1] >= year ||
|
732
|
+
// Date is in an "only" year.
|
733
|
+
(ruleset[i][0] === year && ruleset[i][1] === "only") ||
|
734
|
+
//We're in a range from the start year to infinity.
|
735
|
+
ruleset[i][1] === "max"
|
736
|
+
)
|
737
|
+
) {
|
738
|
+
//It's completely okay to have any number of matches here.
|
739
|
+
// Normally we should only see two, but that doesn't preclude other numbers of matches.
|
740
|
+
// These matches are applicable to this year.
|
741
|
+
applicableRules.push([year, ruleset[i]]);
|
742
|
+
}
|
743
|
+
}
|
744
|
+
return applicableRules;
|
745
|
+
};
|
746
|
+
|
747
|
+
var compareDates = function (a, b, prev) {
|
748
|
+
var year, rule;
|
749
|
+
if (a.constructor !== Date) {
|
750
|
+
year = a[0];
|
751
|
+
rule = a[1];
|
752
|
+
a = (!prev && EXACT_DATE_TIME[year] && EXACT_DATE_TIME[year][rule])
|
753
|
+
? EXACT_DATE_TIME[year][rule]
|
754
|
+
: convertRuleToExactDateAndTime(a, prev);
|
755
|
+
} else if (prev) {
|
756
|
+
a = convertDateToUTC(a, isUTC ? 'u' : 'w', prev);
|
757
|
+
}
|
758
|
+
if (b.constructor !== Date) {
|
759
|
+
year = b[0];
|
760
|
+
rule = b[1];
|
761
|
+
b = (!prev && EXACT_DATE_TIME[year] && EXACT_DATE_TIME[year][rule]) ? EXACT_DATE_TIME[year][rule]
|
762
|
+
: convertRuleToExactDateAndTime(b, prev);
|
763
|
+
} else if (prev) {
|
764
|
+
b = convertDateToUTC(b, isUTC ? 'u' : 'w', prev);
|
765
|
+
}
|
766
|
+
a = Number(a);
|
767
|
+
b = Number(b);
|
768
|
+
return a - b;
|
769
|
+
};
|
770
|
+
|
771
|
+
var year = date.getUTCFullYear();
|
772
|
+
var applicableRules;
|
773
|
+
|
774
|
+
applicableRules = findApplicableRules(year, _this.rules[ruleset]);
|
775
|
+
applicableRules.push(date);
|
776
|
+
//While sorting, the time zone in which the rule starting time is specified
|
777
|
+
// is ignored. This is ok as long as the timespan between two DST changes is
|
778
|
+
// larger than the DST offset, which is probably always true.
|
779
|
+
// As the given date may indeed be close to a DST change, it may get sorted
|
780
|
+
// to a wrong position (off by one), which is corrected below.
|
781
|
+
applicableRules.sort(compareDates);
|
782
|
+
|
783
|
+
//If there are not enough past DST rules...
|
784
|
+
if (_arrIndexOf.call(applicableRules, date) < 2) {
|
785
|
+
applicableRules = applicableRules.concat(findApplicableRules(year-1, _this.rules[ruleset]));
|
786
|
+
applicableRules.sort(compareDates);
|
787
|
+
}
|
788
|
+
var pinpoint = _arrIndexOf.call(applicableRules, date);
|
789
|
+
if (pinpoint > 1 && compareDates(date, applicableRules[pinpoint-1], applicableRules[pinpoint-2][1]) < 0) {
|
790
|
+
//The previous rule does not really apply, take the one before that.
|
791
|
+
return applicableRules[pinpoint - 2][1];
|
792
|
+
} else if (pinpoint > 0 && pinpoint < applicableRules.length - 1 && compareDates(date, applicableRules[pinpoint+1], applicableRules[pinpoint-1][1]) > 0) {
|
793
|
+
|
794
|
+
//The next rule does already apply, take that one.
|
795
|
+
return applicableRules[pinpoint + 1][1];
|
796
|
+
} else if (pinpoint === 0) {
|
797
|
+
//No applicable rule found in this and in previous year.
|
798
|
+
return null;
|
799
|
+
}
|
800
|
+
return applicableRules[pinpoint - 1][1];
|
801
|
+
}
|
802
|
+
function getAdjustedOffset(off, rule) {
|
803
|
+
return -Math.ceil(rule[6] - off);
|
804
|
+
}
|
805
|
+
function getAbbreviation(zone, rule) {
|
806
|
+
var res;
|
807
|
+
var base = zone[2];
|
808
|
+
if (base.indexOf('%s') > -1) {
|
809
|
+
var repl;
|
810
|
+
if (rule) {
|
811
|
+
repl = rule[7] === '-' ? '' : rule[7];
|
812
|
+
}
|
813
|
+
//FIXME: Right now just falling back to Standard --
|
814
|
+
// apparently ought to use the last valid rule,
|
815
|
+
// although in practice that always ought to be Standard
|
816
|
+
else {
|
817
|
+
repl = 'S';
|
818
|
+
}
|
819
|
+
res = base.replace('%s', repl);
|
820
|
+
}
|
821
|
+
else if (base.indexOf('/') > -1) {
|
822
|
+
//Chose one of two alternative strings.
|
823
|
+
res = base.split("/", 2)[rule[6] ? 1 : 0];
|
824
|
+
} else {
|
825
|
+
res = base;
|
826
|
+
}
|
827
|
+
return res;
|
828
|
+
}
|
829
|
+
|
830
|
+
this.zoneFileBasePath = null;
|
831
|
+
this.zoneFiles = ['africa', 'antarctica', 'asia', 'australasia', 'backward', 'etcetera', 'europe', 'northamerica', 'pacificnew', 'southamerica'];
|
832
|
+
this.loadingSchemes = {
|
833
|
+
PRELOAD_ALL: 'preloadAll',
|
834
|
+
LAZY_LOAD: 'lazyLoad',
|
835
|
+
MANUAL_LOAD: 'manualLoad'
|
836
|
+
};
|
837
|
+
this.loadingScheme = this.loadingSchemes.LAZY_LOAD;
|
838
|
+
this.loadedZones = {};
|
839
|
+
this.zones = {};
|
840
|
+
this.rules = {};
|
841
|
+
|
842
|
+
this.init = function (o) {
|
843
|
+
var opts = { async: true }
|
844
|
+
, def = this.loadingScheme === this.loadingSchemes.PRELOAD_ALL
|
845
|
+
? this.zoneFiles
|
846
|
+
: (this.defaultZoneFile || 'northamerica')
|
847
|
+
, done = 0
|
848
|
+
, callbackFn;
|
849
|
+
//Override default with any passed-in opts
|
850
|
+
for (var p in o) {
|
851
|
+
opts[p] = o[p];
|
852
|
+
}
|
853
|
+
if (typeof def === 'string') {
|
854
|
+
return this.loadZoneFile(def, opts);
|
855
|
+
}
|
856
|
+
//Wraps callback function in another one that makes
|
857
|
+
// sure all files have been loaded.
|
858
|
+
callbackFn = opts.callback;
|
859
|
+
opts.callback = function () {
|
860
|
+
done++;
|
861
|
+
(done === def.length) && typeof callbackFn === 'function' && callbackFn();
|
862
|
+
};
|
863
|
+
for (var i = 0; i < def.length; i++) {
|
864
|
+
this.loadZoneFile(def[i], opts);
|
865
|
+
}
|
866
|
+
};
|
867
|
+
|
868
|
+
//Get the zone files via XHR -- if the sync flag
|
869
|
+
// is set to true, it's being called by the lazy-loading
|
870
|
+
// mechanism, so the result needs to be returned inline.
|
871
|
+
this.loadZoneFile = function (fileName, opts) {
|
872
|
+
if (typeof this.zoneFileBasePath === 'undefined') {
|
873
|
+
throw new Error('Please define a base path to your zone file directory -- timezoneJS.timezone.zoneFileBasePath.');
|
874
|
+
}
|
875
|
+
//Ignore already loaded zones.
|
876
|
+
if (this.loadedZones[fileName]) {
|
877
|
+
return;
|
878
|
+
}
|
879
|
+
this.loadedZones[fileName] = true;
|
880
|
+
return builtInLoadZoneFile(fileName, opts);
|
881
|
+
};
|
882
|
+
this.loadZoneJSONData = function (url, sync) {
|
883
|
+
var processData = function (data) {
|
884
|
+
data = eval('('+ data +')');
|
885
|
+
for (var z in data.zones) {
|
886
|
+
_this.zones[z] = data.zones[z];
|
887
|
+
}
|
888
|
+
for (var r in data.rules) {
|
889
|
+
_this.rules[r] = data.rules[r];
|
890
|
+
}
|
891
|
+
};
|
892
|
+
return sync
|
893
|
+
? processData(_this.transport({ url : url, async : false }))
|
894
|
+
: _this.transport({ url : url, success : processData });
|
895
|
+
};
|
896
|
+
this.loadZoneDataFromObject = function (data) {
|
897
|
+
if (!data) { return; }
|
898
|
+
for (var z in data.zones) {
|
899
|
+
_this.zones[z] = data.zones[z];
|
900
|
+
}
|
901
|
+
for (var r in data.rules) {
|
902
|
+
_this.rules[r] = data.rules[r];
|
903
|
+
}
|
904
|
+
};
|
905
|
+
this.getAllZones = function () {
|
906
|
+
var arr = [];
|
907
|
+
for (var z in this.zones) { arr.push(z); }
|
908
|
+
return arr.sort();
|
909
|
+
};
|
910
|
+
this.parseZones = function (str) {
|
911
|
+
var lines = str.split('\n')
|
912
|
+
, arr = []
|
913
|
+
, chunk = ''
|
914
|
+
, l
|
915
|
+
, zone = null
|
916
|
+
, rule = null;
|
917
|
+
for (var i = 0; i < lines.length; i++) {
|
918
|
+
l = lines[i];
|
919
|
+
if (l.match(/^\s/)) {
|
920
|
+
l = "Zone " + zone + l;
|
921
|
+
}
|
922
|
+
l = l.split("#")[0];
|
923
|
+
if (l.length > 3) {
|
924
|
+
arr = l.split(/\s+/);
|
925
|
+
chunk = arr.shift();
|
926
|
+
//Ignore Leap.
|
927
|
+
switch (chunk) {
|
928
|
+
case 'Zone':
|
929
|
+
zone = arr.shift();
|
930
|
+
if (!_this.zones[zone]) {
|
931
|
+
_this.zones[zone] = [];
|
932
|
+
}
|
933
|
+
if (arr.length < 3) break;
|
934
|
+
//Process zone right here and replace 3rd element with the processed array.
|
935
|
+
arr.splice(3, arr.length, processZone(arr));
|
936
|
+
if (arr[3]) arr[3] = Date.UTC.apply(null, arr[3]);
|
937
|
+
arr[0] = -getBasicOffset(arr[0]);
|
938
|
+
_this.zones[zone].push(arr);
|
939
|
+
break;
|
940
|
+
case 'Rule':
|
941
|
+
rule = arr.shift();
|
942
|
+
if (!_this.rules[rule]) {
|
943
|
+
_this.rules[rule] = [];
|
944
|
+
}
|
945
|
+
//Parse int FROM year and TO year
|
946
|
+
arr[0] = parseInt(arr[0], 10);
|
947
|
+
arr[1] = parseInt(arr[1], 10) || arr[1];
|
948
|
+
//Parse time string AT
|
949
|
+
arr[5] = parseTimeString(arr[5]);
|
950
|
+
//Parse offset SAVE
|
951
|
+
arr[6] = getBasicOffset(arr[6]);
|
952
|
+
_this.rules[rule].push(arr);
|
953
|
+
break;
|
954
|
+
case 'Link':
|
955
|
+
//No zones for these should already exist.
|
956
|
+
if (_this.zones[arr[1]]) {
|
957
|
+
throw new Error('Error with Link ' + arr[1] + '. Cannot create link of a preexisted zone.');
|
958
|
+
}
|
959
|
+
//Create the link.
|
960
|
+
_this.zones[arr[1]] = arr[0];
|
961
|
+
break;
|
962
|
+
}
|
963
|
+
}
|
964
|
+
}
|
965
|
+
return true;
|
966
|
+
};
|
967
|
+
//Expose transport mechanism and allow overwrite.
|
968
|
+
this.transport = _transport;
|
969
|
+
this.getTzInfo = function (dt, tz, isUTC) {
|
970
|
+
//Lazy-load any zones not yet loaded.
|
971
|
+
if (this.loadingScheme === this.loadingSchemes.LAZY_LOAD) {
|
972
|
+
//Get the correct region for the zone.
|
973
|
+
var zoneFile = getRegionForTimezone(tz);
|
974
|
+
if (!zoneFile) {
|
975
|
+
throw new Error('Not a valid timezone ID.');
|
976
|
+
}
|
977
|
+
if (!this.loadedZones[zoneFile]) {
|
978
|
+
//Get the file and parse it -- use synchronous XHR.
|
979
|
+
this.loadZoneFile(zoneFile);
|
980
|
+
}
|
981
|
+
}
|
982
|
+
var z = getZone(dt, tz);
|
983
|
+
var off = z[0];
|
984
|
+
//See if the offset needs adjustment.
|
985
|
+
var rule = getRule(dt, z, isUTC);
|
986
|
+
if (rule) {
|
987
|
+
off = getAdjustedOffset(off, rule);
|
988
|
+
}
|
989
|
+
var abbr = getAbbreviation(z, rule);
|
990
|
+
return { tzOffset: off, tzAbbr: abbr };
|
991
|
+
};
|
992
|
+
};
|
993
|
+
}).call(this);
|