Skip to content

Commit

Permalink
Timezone support improvements #3
Browse files Browse the repository at this point in the history
- fixed bug with exporting hours rom negative UTC offset
- added some basic tests
  • Loading branch information
valkirilov committed Oct 9, 2017
1 parent 3f57751 commit 5b87780
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 350 deletions.
4 changes: 2 additions & 2 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ <h4>Export formats</h4>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="libs/bootstrap/js/bootstrap.min.js"></script>

<!-- <script type="text/javascript" src="scripts/mtr-datepicker-timezones.js"></script> -->
<script type="text/javascript" src="scripts/mtr-datepicker-timezones.js"></script>
<script type="text/javascript" src="scripts/mtr-datepicker.js"></script>
<script type="text/javascript" src="demo/demo.js"></script>

<script type="text/javascript">
var initDate = new Date(2010, 10, 21);
var demoDatepicker = MtrDatepickerDemo.init({
target: 'datepicker-demo-custom',
//timestamp: initDate.getTime(),
timestamp: initDate.getTime(),
}, {
exportFormats: 'datepicker-demo-custom-export-formats',
customizeFuture: 'datepicker-demo-input-customize-future',
Expand Down
543 changes: 268 additions & 275 deletions dist/mtr-datepicker.min.js

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions docs/MtrDatepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ <h4 class="name" id="~xDown"><span class="type-signature">(inner) </span>xDown<s

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1812">line 1812</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1806">line 1806</a>
</li></ul></dd>


Expand Down Expand Up @@ -442,7 +442,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1633">line 1633</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1627">line 1627</a>
</li></ul></dd>


Expand Down Expand Up @@ -573,7 +573,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1601">line 1601</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1595">line 1595</a>
</li></ul></dd>


Expand Down Expand Up @@ -723,7 +723,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line909">line 909</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line903">line 903</a>
</li></ul></dd>


Expand Down Expand Up @@ -825,7 +825,7 @@ <h4 class="name" id="~createMarkup"><span class="type-signature">(inner) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line443">line 443</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line437">line 437</a>
</li></ul></dd>


Expand Down Expand Up @@ -956,7 +956,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line838">line 838</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line832">line 832</a>
</li></ul></dd>


Expand Down Expand Up @@ -1105,7 +1105,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1676">line 1676</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1670">line 1670</a>
</li></ul></dd>


Expand Down Expand Up @@ -1205,7 +1205,7 @@ <h4 class="name" id="~createRangeForDate"><span class="type-signature">(inner) <

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1692">line 1692</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1686">line 1686</a>
</li></ul></dd>


Expand Down Expand Up @@ -1340,7 +1340,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line536">line 536</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line530">line 530</a>
</li></ul></dd>


Expand Down Expand Up @@ -1489,7 +1489,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1952">line 1952</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1933">line 1933</a>
</li></ul></dd>


Expand Down Expand Up @@ -1523,6 +1523,7 @@ <h5>Returns:</h5>
h, hh
m, mm
a, AA
Z, ZZ
</div>


Expand Down Expand Up @@ -1644,7 +1645,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1824">line 1824</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1818">line 1818</a>
</li></ul></dd>


Expand Down Expand Up @@ -1927,7 +1928,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1667">line 1667</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1661">line 1661</a>
</li></ul></dd>


Expand Down Expand Up @@ -2099,7 +2100,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1650">line 1650</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1644">line 1644</a>
</li></ul></dd>


Expand Down Expand Up @@ -2230,7 +2231,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1795">line 1795</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1789">line 1789</a>
</li></ul></dd>


Expand Down Expand Up @@ -2510,7 +2511,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1520">line 1520</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1514">line 1514</a>
</li></ul></dd>


Expand Down Expand Up @@ -2596,7 +2597,7 @@ <h4 class="name" id="~smooth_scroll_to"><span class="type-signature">(inner) </s

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1722">line 1722</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1716">line 1716</a>
</li></ul></dd>


Expand Down Expand Up @@ -2752,7 +2753,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1037">line 1037</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1031">line 1031</a>
</li></ul></dd>


Expand Down Expand Up @@ -2906,7 +2907,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1489">line 1489</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1483">line 1483</a>
</li></ul></dd>


Expand Down Expand Up @@ -3086,7 +3087,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1077">line 1077</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line1071">line 1071</a>
</li></ul></dd>


Expand Down Expand Up @@ -3152,7 +3153,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="MtrDatepi
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Thu Oct 05 2017 14:49:35 GMT+0300 (EEST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Mon Oct 09 2017 18:43:34 GMT+0300 (EEST)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ <h4 class="name" id="init"><span class="type-signature"></span>init<span class="

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line2053">line 2053</a>
<a href="mtr-datepicker.js.html">mtr-datepicker.js</a>, <a href="mtr-datepicker.js.html#line2038">line 2038</a>
</li></ul></dd>


Expand Down Expand Up @@ -242,7 +242,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="MtrDatepi
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Thu Oct 05 2017 14:49:35 GMT+0300 (EEST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Mon Oct 09 2017 18:43:34 GMT+0300 (EEST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="MtrDatepi
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Thu Oct 05 2017 14:49:35 GMT+0300 (EEST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Mon Oct 09 2017 18:43:34 GMT+0300 (EEST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/mtr-datepicker-timezones.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="MtrDatepi
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Thu Oct 05 2017 14:49:35 GMT+0300 (EEST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Mon Oct 09 2017 18:43:34 GMT+0300 (EEST)
</footer>

<script> prettyPrint(); </script>
Expand Down
31 changes: 8 additions & 23 deletions docs/mtr-datepicker.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,6 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>
values.date = new Date(timezoneOffsetTimestamp);
values.timestamp = values.date.getTime();

if (input.utcTimezone !== undefined) {
loadJSON('./dist/timezones.json', function(response) {
config.timezones = JSON.parse(response);
});
}

// Override minutes
config.minutes.min = (input.minutes !== undefined &amp;&amp; input.minutes.min !== undefined) ? parseInt(input.minutes.min) : config.minutes.min;
config.minutes.max = (input.minutes !== undefined &amp;&amp; input.minutes.max !== undefined) ? parseInt(input.minutes.max) : config.minutes.max;
Expand Down Expand Up @@ -1880,19 +1874,6 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>
yDown = null;
}

function loadJSON(filename, callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', filename, true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 &amp;&amp; xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}

/*****************************************************************************
* PUBLIC API
*
Expand Down Expand Up @@ -1935,8 +1916,7 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>

// "Wed Sep 23 2015 11:43:47 GMT+0300 (EEST)"
var toString = function() {

if (config.timezones) {
if (plugins.timezones) {
return toDateString() + ' ' + toTimeString();
}

Expand All @@ -1950,7 +1930,7 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>
timeString = values.date.toTimeString().split(' ');

toReturn += timeString[0];
toReturn += ' GMT' + (config.utcTimezone.offset > 0 ? '+' : '') + (Math.abs(config.utcTimezone.offset) &lt; 10 ? '0' : '') + config.utcTimezone.offset + '00';
toReturn += ' GMT' + (config.utcTimezone.offset > 0 ? '+' : '-') + (Math.abs(config.utcTimezone.offset) &lt; 10 ? '0' : '') + Math.abs(config.utcTimezone.offset) + '00';
toReturn += ' (' + config.utcTimezone.abbr + ')';

return toReturn;
Expand All @@ -1976,6 +1956,7 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>
* h, hh
* m, mm
* a, AA
* Z, ZZ
*/
var format = function(input) {
var currentHours = getHours();
Expand All @@ -1985,6 +1966,7 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>
var currentDate = getDate();
var currentMonth = getMonth() + 1;
var currentYear = getYear();
var currentTimezone = config.utcTimezone.offset;

// Dates
input = specialReplace(input, 'DD', prependZero(currentDate));
Expand Down Expand Up @@ -2014,6 +1996,9 @@ <h1 class="page-title">Source: mtr-datepicker.js</h1>
input = specialReplace(input, 'MM', prependZero(currentMonth));
input = specialReplace(input, 'M', currentMonth);

input = specialReplace(input, 'ZZ', (currentTimezone > 0 ? '+' : '-') + prependZero(Math.abs(currentTimezone)) + ':00');
input = specialReplace(input, 'Z', (currentTimezone > 0 ? '+' : '-') + Math.abs(currentTimezone) + ':00');

input = input.split('#%#').join('');

function specialReplace(input, selector, value) {
Expand Down Expand Up @@ -2140,7 +2125,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="MtrDatepi
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Thu Oct 05 2017 14:49:35 GMT+0300 (EEST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc https://registry.npmjs.org/jsdoc/-/jsdoc-3.4.3.tgz</a> on Mon Oct 09 2017 18:43:34 GMT+0300 (EEST)
</footer>

<script> prettyPrint(); </script>
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<link rel="stylesheet" type="text/css" href="demo/cosmo.bootstrap.min.css">

<!-- Custom styles for this template -->
<link rel="stylesheet" type="text/css" href="dist/mtr-datepicker.min.css?rel=1507204172421" />
<link rel="stylesheet" type="text/css" href="dist/mtr-datepicker.default-theme.min.css?rel=1507204172423" />
<link rel="stylesheet" type="text/css" href="dist/mtr-datepicker.min.css?rel=1507563811797" />
<link rel="stylesheet" type="text/css" href="dist/mtr-datepicker.default-theme.min.css?rel=1507563811798" />
<link rel="stylesheet" type="text/css" href="demo/jumbotron-narrow.css" />

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=yyxxeK88Mx">
Expand Down Expand Up @@ -162,7 +162,7 @@ <h1 id="demo" class="text-center">Demo</h1>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="libs/bootstrap/js/bootstrap.min.js"></script>

<script type="text/javascript" src="dist/mtr-datepicker.min.js?rel=1507204172423"></script>
<script type="text/javascript" src="dist/mtr-datepicker.min.js?rel=1507563811799"></script>

<script type="text/javascript">
var demoDatepicker = new MtrDatepicker({
Expand Down

0 comments on commit 5b87780

Please sign in to comment.