mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
serialization forr evaluations
This commit is contained in:
@@ -30,6 +30,13 @@ const dateToISO = (date) => {
|
||||
* **Experimental**
|
||||
*/
|
||||
const ISOToDate = (str) => {
|
||||
if (null === str) {
|
||||
return null;
|
||||
}
|
||||
if ("" === str.trim()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let
|
||||
[year, month, day] = str.split('-');
|
||||
|
||||
@@ -86,11 +93,12 @@ const datetimeToISO = (date) => {
|
||||
};
|
||||
|
||||
const intervalDaysToISO = (days) => {
|
||||
console.log(days);
|
||||
if (null === days) {
|
||||
return null;
|
||||
return 'PD0';
|
||||
}
|
||||
|
||||
return `PD${days}`;
|
||||
return `P${days}D`;
|
||||
}
|
||||
|
||||
const intervalISOToDays = (str) => {
|
||||
@@ -98,10 +106,14 @@ const intervalISOToDays = (str) => {
|
||||
return null
|
||||
}
|
||||
|
||||
if ("" === str.trim()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let days = 0;
|
||||
let isDate = true;
|
||||
let vstring = "";
|
||||
for (let i = 0; i < str.length; i = i + 1) {
|
||||
// we do not take time into account
|
||||
if (!isDate) {
|
||||
continue;
|
||||
}
|
||||
@@ -109,21 +121,35 @@ const intervalISOToDays = (str) => {
|
||||
case 'P':
|
||||
isDate = true;
|
||||
break;
|
||||
case 'Y':
|
||||
i = i+1;
|
||||
days = days + Number.parseInt(str.charAt(i)) * 365;
|
||||
break;
|
||||
case 'M':
|
||||
i = i+1;
|
||||
days = days + Number.parseInt(str.charAt(i)) * 30;
|
||||
break;
|
||||
case 'D':
|
||||
i = i+1;
|
||||
days = days + Number.parseInt(str.charAt(i));
|
||||
break;
|
||||
case 'T':
|
||||
isDate = false;
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
vstring = vstring + str.charAt(i);
|
||||
break;
|
||||
case 'Y':
|
||||
days = days + Number.parseInt(vstring) * 365;
|
||||
vstring = "";
|
||||
break;
|
||||
case 'M':
|
||||
days = days + Number.parseInt(vstring) * 30;
|
||||
vstring = "";
|
||||
break;
|
||||
case 'D':
|
||||
days = days + Number.parseInt(vstring);
|
||||
vstring = "";
|
||||
break;
|
||||
default:
|
||||
throw Error("this character should not appears: " + str.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user