Skip to content

Commit

Permalink
fix get function and fix some issue on editors date
Browse files Browse the repository at this point in the history
  • Loading branch information
GBonnaire committed Nov 27, 2020
1 parent c7847ed commit 9fb3cf0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
20 changes: 9 additions & 11 deletions editors/dates/jexcel.editor.date.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Custom editor for date only (not datetime)
*
* @version 1.2.2
* @version 1.2.4
* @author Guillaume Bonnaire <contact@gbonnaire.fr>
* @website https://www.gbonnaire.fr
* @website https://repo.gbonnaire.fr
*
* @license This plugin is distribute under MIT License
*/
Expand Down Expand Up @@ -106,7 +106,7 @@ jexcel.editors.date = function() {
value = methods.ExcelDateToDate(value);
}

if(!isDateISOValid(value)) {
if(value && !isDateISOValid(value)) {
// Transform Date to Date ISO
var tmp_value = stringToDateISO(value, options.formatInput);
if(tmp_value !== false) {
Expand All @@ -123,11 +123,7 @@ jexcel.editors.date = function() {
if(parseFloat(value)+"" === value+"") {
value = methods.ExcelDateToDate(value);
}
if(options.returnISO) {
return value;
} else {
return formatedDateOnLocalFormat(value, options.locales, options.formatOutputOnCell);
}
return formatedDateOnLocalFormat(value, options.locales, options.formatOutputOnCell);
}

function addzero(value, base) {
Expand Down Expand Up @@ -163,6 +159,8 @@ jexcel.editors.date = function() {
}

function stringToDateISO(str, format) {


if(!format) {
format="yyyy-mm-dd";
} else {
Expand All @@ -174,9 +172,9 @@ jexcel.editors.date = function() {
var dayIndex=format.indexOf("dd");
var yearIndex=format.indexOf("yyyy");

var day=addzero(parseInt(str.substr(dayIndex,dayIndex*1+2)), 10);
var month=addzero(parseInt(str.substr(monthIndex,monthIndex*1+2)), 10);
var year=addzero(parseInt(str.substr(yearIndex,yearIndex*1+4)), 1000);
var day=addzero(parseInt(str.substring(dayIndex,dayIndex*1+2)), 10);
var month=addzero(parseInt(str.substring(monthIndex,monthIndex*1+2)), 10);
var year=addzero(parseInt(str.substring(yearIndex,yearIndex*1+4)), 1000);

var newDateISO_str = year+"-"+month+"-"+day;

Expand Down
28 changes: 12 additions & 16 deletions editors/dates/jexcel.editor.datetime.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Custom editor for datetime
*
* @version 1.2.2
* @version 1.2.4
* @author Guillaume Bonnaire <contact@gbonnaire.fr>
* @website https://www.gbonnaire.fr
* @website https://repo.gbonnaire.fr
*
* @license This plugin is distribute under MIT License
*/
Expand Down Expand Up @@ -105,15 +105,15 @@ jexcel.editors.datetime = function() {
value = methods.ExcelDateTimeToDateTime(value);
}

if(!isDateTimeISOValid(value)) {
if(value && !isDateTimeISOValid(value)) {
// Transform Date to Date ISO
var tmp_value = stringToDateTimeISO(value, options.formatInput);
if(tmp_value !== false) {
value = tmp_value;
} else {
value = false;
}
} else {
} else if(value) {
value = stringToDateTimeISO(value);
}

Expand All @@ -125,11 +125,7 @@ jexcel.editors.datetime = function() {
if(parseFloat(value)+"" === value+"") {
value = methods.ExcelDateTimeToDateTime(value);
}
if(options.returnISO) {
return value;
} else {
return formatedDateOnLocalFormat(value, options.locales, options.formatOutputOnCell);
}
return formatedDateOnLocalFormat(value, options.locales, options.formatOutputOnCell);
}

function addzero(value, base) {
Expand Down Expand Up @@ -179,22 +175,22 @@ jexcel.editors.datetime = function() {
var minuteIndex=format.indexOf("nn");
var secondIndex=format.indexOf("ss");

var day=addzero(parseInt(str.substr(dayIndex,dayIndex*1+2)), 10);
var month=addzero(parseInt(str.substr(monthIndex,monthIndex*1+2)), 10);
var year=addzero(parseInt(str.substr(yearIndex,yearIndex*1+4)), 1000);
var day=addzero(parseInt(str.substring(dayIndex,dayIndex*1+2)), 10);
var month=addzero(parseInt(str.substring(monthIndex,monthIndex*1+2)), 10);
var year=addzero(parseInt(str.substring(yearIndex,yearIndex*1+4)), 1000);

if(hourIndex!=-1 && str.length>(hourIndex*1+2)) {
var hour = addzero(parseInt(str.substr(hourIndex,hourIndex*1+2)), 10);
var hour = addzero(parseInt(str.substring(hourIndex,hourIndex*1+2)), 10);
} else {
var hour = "00";
}
if(minuteIndex!=-1 && str.length>(minuteIndex*1+2)) {
var minute = addzero(parseInt(str.substr(minuteIndex,minuteIndex*1+2)), 10);
var minute = addzero(parseInt(str.substring(minuteIndex,minuteIndex*1+2)), 10);
} else {
var minute = "00";
}
if(secondIndex!=-1 && str.length>(secondIndex*1+2)) {
var second = addzero(parseInt(str.substr(secondIndex,secondIndex*1+2)), 10);
var second = addzero(parseInt(str.substring(secondIndex,secondIndex*1+2)), 10);
} else {
var second = "00";
}
Expand All @@ -213,7 +209,7 @@ jexcel.editors.datetime = function() {
inDate = new Date(inDate);
}
var returnDateTime = 25569 + ((inDate.getTime() - (inDate.getTimezoneOffset() * 60 * 1000)) / (1000 * 60 * 60 * 24));
return returnDateTime.toString().substr(0,20);
return returnDateTime.toString().substring(0,20);
}

methods.ExcelDateTimeToDateTime = function (value) {
Expand Down

0 comments on commit 9fb3cf0

Please sign in to comment.