jsuites 4.11.3 → 4.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@
17
17
 
18
18
  var jSuites = function(options) {
19
19
  var obj = {}
20
- var version = '4.11.3';
20
+ var version = '4.11.4';
21
21
 
22
22
  var find = function(DOMElement, component) {
23
23
  if (DOMElement[component.type] && DOMElement[component.type] == component) {
@@ -1953,25 +1953,53 @@ jSuites.calendar.extractDateFromString = function(date, format) {
1953
1953
  return '';
1954
1954
  }
1955
1955
 
1956
+
1957
+ var excelInitialTime = Date.UTC(1900, 0, 0);
1958
+ var excelLeapYearBug = Date.UTC(1900, 1, 29);
1959
+ var millisecondsPerDay = 86400000;
1960
+
1956
1961
  /**
1957
1962
  * Date to number
1958
1963
  */
1959
- jSuites.calendar.dateToNum = function(a, b) {
1960
- a = new Date(a);
1961
- if (! b) {
1962
- b = '1899-12-30 ' + a.getHours() + ':' + a.getMinutes() + ':' + a.getSeconds();
1963
- }
1964
- b = new Date(b);
1965
- var v = a.getTime() - b.getTime();
1966
- return Math.round(v / 86400000);
1964
+ jSuites.calendar.dateToNum = function(jsDate) {
1965
+ if (typeof(jsDate) === 'string') {
1966
+ jsDate = new Date(jsDate + ' GMT+0');
1967
+ }
1968
+ var jsDateInMilliseconds = jsDate.getTime();
1969
+
1970
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1971
+ jsDateInMilliseconds += millisecondsPerDay;
1972
+ }
1973
+
1974
+ jsDateInMilliseconds -= excelInitialTime;
1975
+
1976
+ return jsDateInMilliseconds / millisecondsPerDay;
1967
1977
  }
1968
1978
 
1969
1979
  /**
1970
1980
  * Number to date
1971
1981
  */
1972
- jSuites.calendar.numToDate = function(value) {
1973
- var d = new Date(Math.round((value - 25569)*86400*1000));
1974
- return d.getFullYear() + "-" + jSuites.two(d.getMonth()+1) + "-" + jSuites.two(d.getDate()) + ' 00:00:00';
1982
+ // !IMPORTANT!
1983
+ // Excel incorrectly considers 1900 to be a leap year
1984
+ jSuites.calendar.numToDate = function(excelSerialNumber) {
1985
+ var jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
1986
+
1987
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1988
+ jsDateInMilliseconds -= millisecondsPerDay;
1989
+ }
1990
+
1991
+ const d = new Date(jsDateInMilliseconds);
1992
+
1993
+ var date = [
1994
+ d.getUTCFullYear(),
1995
+ d.getUTCMonth()+1,
1996
+ d.getUTCDate(),
1997
+ d.getUTCHours(),
1998
+ d.getUTCMinutes(),
1999
+ d.getUTCSeconds(),
2000
+ ];
2001
+
2002
+ return jSuites.calendar.now(date);
1975
2003
  }
1976
2004
 
1977
2005
  // Helper to convert date into string
@@ -7136,7 +7164,7 @@ jSuites.mask = (function() {
7136
7164
  }
7137
7165
  // Temporary value
7138
7166
  if (v[0]) {
7139
- var t = parseFloat(v[0]);
7167
+ var t = parseFloat(v[0] + '.1');
7140
7168
  if (o.style == 'percent') {
7141
7169
  t /= 100;
7142
7170
  }
@@ -7243,9 +7271,12 @@ jSuites.mask = (function() {
7243
7271
  if (this.tagName == 'DIV') {
7244
7272
  var s = window.getSelection();
7245
7273
  var r = document.createRange();
7246
- r.setStart(this.childNodes[0], index);
7247
- s.removeAllRanges();
7248
- s.addRange(r);
7274
+
7275
+ if (this.childNodes[0]) {
7276
+ r.setStart(this.childNodes[0], index);
7277
+ s.removeAllRanges();
7278
+ s.addRange(r);
7279
+ }
7249
7280
  } else {
7250
7281
  this.selectionStart = index;
7251
7282
  this.selectionEnd = index;
@@ -8159,10 +8190,8 @@ jSuites.mask = (function() {
8159
8190
 
8160
8191
  var o = obj(v, options, true);
8161
8192
  var value = getDate.call(o);
8162
- if ((o.date[0] && o.date[1] && o.date[2]) && ! (o.date[3] || o.date[4] || o.date[5])) {
8163
- var t = jSuites.calendar.now(o.date);
8164
- value = jSuites.calendar.dateToNum(t);
8165
- }
8193
+ var t = jSuites.calendar.now(o.date);
8194
+ value = jSuites.calendar.dateToNum(t);
8166
8195
  } else {
8167
8196
  var value = Extract.call(options, v);
8168
8197
  // Percentage
package/dist/jsuites.js CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  var jSuites = function(options) {
19
19
  var obj = {}
20
- var version = '4.11.3';
20
+ var version = '4.11.4';
21
21
 
22
22
  var find = function(DOMElement, component) {
23
23
  if (DOMElement[component.type] && DOMElement[component.type] == component) {
@@ -1964,25 +1964,53 @@ jSuites.calendar.extractDateFromString = function(date, format) {
1964
1964
  return '';
1965
1965
  }
1966
1966
 
1967
+
1968
+ var excelInitialTime = Date.UTC(1900, 0, 0);
1969
+ var excelLeapYearBug = Date.UTC(1900, 1, 29);
1970
+ var millisecondsPerDay = 86400000;
1971
+
1967
1972
  /**
1968
1973
  * Date to number
1969
1974
  */
1970
- jSuites.calendar.dateToNum = function(a, b) {
1971
- a = new Date(a);
1972
- if (! b) {
1973
- b = '1899-12-30 ' + a.getHours() + ':' + a.getMinutes() + ':' + a.getSeconds();
1974
- }
1975
- b = new Date(b);
1976
- var v = a.getTime() - b.getTime();
1977
- return Math.round(v / 86400000);
1975
+ jSuites.calendar.dateToNum = function(jsDate) {
1976
+ if (typeof(jsDate) === 'string') {
1977
+ jsDate = new Date(jsDate + ' GMT+0');
1978
+ }
1979
+ var jsDateInMilliseconds = jsDate.getTime();
1980
+
1981
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1982
+ jsDateInMilliseconds += millisecondsPerDay;
1983
+ }
1984
+
1985
+ jsDateInMilliseconds -= excelInitialTime;
1986
+
1987
+ return jsDateInMilliseconds / millisecondsPerDay;
1978
1988
  }
1979
1989
 
1980
1990
  /**
1981
1991
  * Number to date
1982
1992
  */
1983
- jSuites.calendar.numToDate = function(value) {
1984
- var d = new Date(Math.round((value - 25569)*86400*1000));
1985
- return d.getFullYear() + "-" + jSuites.two(d.getMonth()+1) + "-" + jSuites.two(d.getDate()) + ' 00:00:00';
1993
+ // !IMPORTANT!
1994
+ // Excel incorrectly considers 1900 to be a leap year
1995
+ jSuites.calendar.numToDate = function(excelSerialNumber) {
1996
+ var jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
1997
+
1998
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1999
+ jsDateInMilliseconds -= millisecondsPerDay;
2000
+ }
2001
+
2002
+ const d = new Date(jsDateInMilliseconds);
2003
+
2004
+ var date = [
2005
+ d.getUTCFullYear(),
2006
+ d.getUTCMonth()+1,
2007
+ d.getUTCDate(),
2008
+ d.getUTCHours(),
2009
+ d.getUTCMinutes(),
2010
+ d.getUTCSeconds(),
2011
+ ];
2012
+
2013
+ return jSuites.calendar.now(date);
1986
2014
  }
1987
2015
 
1988
2016
  // Helper to convert date into string
@@ -7561,7 +7589,7 @@ jSuites.mask = (function() {
7561
7589
  }
7562
7590
  // Temporary value
7563
7591
  if (v[0]) {
7564
- var t = parseFloat(v[0]);
7592
+ var t = parseFloat(v[0] + '.1');
7565
7593
  if (o.style == 'percent') {
7566
7594
  t /= 100;
7567
7595
  }
@@ -7668,9 +7696,12 @@ jSuites.mask = (function() {
7668
7696
  if (this.tagName == 'DIV') {
7669
7697
  var s = window.getSelection();
7670
7698
  var r = document.createRange();
7671
- r.setStart(this.childNodes[0], index);
7672
- s.removeAllRanges();
7673
- s.addRange(r);
7699
+
7700
+ if (this.childNodes[0]) {
7701
+ r.setStart(this.childNodes[0], index);
7702
+ s.removeAllRanges();
7703
+ s.addRange(r);
7704
+ }
7674
7705
  } else {
7675
7706
  this.selectionStart = index;
7676
7707
  this.selectionEnd = index;
@@ -8584,10 +8615,8 @@ jSuites.mask = (function() {
8584
8615
 
8585
8616
  var o = obj(v, options, true);
8586
8617
  var value = getDate.call(o);
8587
- if ((o.date[0] && o.date[1] && o.date[2]) && ! (o.date[3] || o.date[4] || o.date[5])) {
8588
- var t = jSuites.calendar.now(o.date);
8589
- value = jSuites.calendar.dateToNum(t);
8590
- }
8618
+ var t = jSuites.calendar.now(o.date);
8619
+ value = jSuites.calendar.dateToNum(t);
8591
8620
  } else {
8592
8621
  var value = Extract.call(options, v);
8593
8622
  // Percentage
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "javascript plugins"
20
20
  ],
21
21
  "main": "dist/jsuites.js",
22
- "version": "4.11.3",
22
+ "version": "4.11.4",
23
23
  "bugs": "https://github.com/jsuites/jsuites/issues",
24
24
  "homepage": "https://github.com/jsuites/jsuites",
25
25
  "docs": "https://jsuites.net",