2019-09-19 15:56:58 +02:00
|
|
|
/* Fonctions Annexes */
|
|
|
|
|
2019-11-11 17:55:52 +01:00
|
|
|
/**
|
|
|
|
* @function isEmptyValue
|
|
|
|
* @description Vérifie si une valeur est vide.
|
|
|
|
* @param {string} value
|
|
|
|
* @returns {boolean}
|
|
|
|
* @example isEmptyValue(null) → true
|
|
|
|
*/
|
2019-09-19 15:56:58 +02:00
|
|
|
function isEmptyValue(value) {
|
2019-10-13 20:58:13 +02:00
|
|
|
return value === '' || value === null || value === undefined;
|
2019-11-11 17:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function formatNumberResult
|
|
|
|
* @description Formate un nombre avec des espaces.
|
|
|
|
* @param {number} num
|
|
|
|
* @returns {(number|string)} - Le nombre formaté soit en nombre ou soit en string si supérieur à 1000 car pour 1000 par exemple formatNumberResult renvoie '1 000'
|
|
|
|
* @example formatNumberResult(76120) → '76 120'
|
|
|
|
*/
|
2019-09-19 15:56:58 +02:00
|
|
|
function formatNumberResult(num) {
|
2019-10-18 20:35:03 +02:00
|
|
|
if(!isNaN(num) && num >= 1000) {
|
|
|
|
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ');
|
2019-09-19 15:56:58 +02:00
|
|
|
}
|
2019-10-18 20:35:03 +02:00
|
|
|
else {
|
|
|
|
return num;
|
2019-09-19 15:56:58 +02:00
|
|
|
}
|
2019-11-11 17:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function isFloat
|
2019-12-31 17:49:19 +01:00
|
|
|
* @description Vérifie si un nombre est un float (integer exclu).
|
2019-11-11 17:55:52 +01:00
|
|
|
* @param {number} value
|
|
|
|
* @returns {boolean}
|
|
|
|
* @example isFloat(76120.474) → true
|
|
|
|
*/
|
2019-10-18 20:35:03 +02:00
|
|
|
function isFloat(value) {
|
2019-10-23 09:33:36 +02:00
|
|
|
return !isNaN(value) && value.toString().includes('.');
|
2019-11-11 17:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function capitalize
|
|
|
|
* @description Majuscule à la 1ère lettre d'une string.
|
|
|
|
* @param {string} s
|
|
|
|
* @returns {string}
|
|
|
|
* @example capitalize('hello world!') → 'Hello world!'
|
|
|
|
*/
|
|
|
|
function capitalize(s) {
|
2019-09-19 15:56:58 +02:00
|
|
|
if (typeof s !== 'string') return ''
|
|
|
|
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
|
|
}
|
|
|
|
|
2019-11-11 17:55:52 +01:00
|
|
|
/**
|
|
|
|
* @function dateTimeUTC
|
|
|
|
* @description Donne la date et l'heure selon l'UTC (Universal Time Coordinated).
|
|
|
|
* @requires {@link fonctions_annexes.js: showDateTime}
|
|
|
|
* @requires {@link variables.js: timeNow, utcOffset, timeNow.setMinutes(timeNow.getMinutes() + utcOffset)}
|
|
|
|
* @param {string} utc Heure de décalage par rapport à l'UTC
|
|
|
|
* @returns {function} → showDateTime(enteredOffset) → Retourne l'exécution de la fonction showDateTime
|
|
|
|
* @example dateTimeUTC('0')
|
|
|
|
*/
|
2019-09-19 15:56:58 +02:00
|
|
|
function dateTimeUTC(utc) {
|
2019-10-28 09:40:21 +01:00
|
|
|
const enteredOffset = parseFloat(utc)*60;
|
2019-10-04 21:14:48 +02:00
|
|
|
timeNow.setMinutes(timeNow.getMinutes() + enteredOffset);
|
|
|
|
return showDateTime(enteredOffset);
|
2019-11-11 17:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function showDateTime
|
|
|
|
* @description Affiche la date et l'heure (format : dd/mm/yyyy - 00:00:00).
|
|
|
|
* @requires {@link fonctions_annexes.js: showDateTime}
|
|
|
|
* @param {string} utc Heure de décalage par rapport à l'UTC
|
|
|
|
* @returns {object} Retourne un objet contenant l'année, le mois, le jour, l'heure, les minutes, les secondes et la date formaté
|
|
|
|
* @example dateTimeUTC('0') → dateTimeUTC vous renvoie l'exécution de showDateTime
|
|
|
|
*/
|
2019-09-19 15:56:58 +02:00
|
|
|
function showDateTime(enteredOffset) {
|
2019-10-23 09:33:36 +02:00
|
|
|
const year = timeNow.getFullYear();
|
|
|
|
const month = ('0'+(timeNow.getMonth()+1)).slice(-2);
|
|
|
|
const day = ('0'+timeNow.getDate()).slice(-2);
|
|
|
|
const hour = ('0'+timeNow.getHours()).slice(-2);
|
|
|
|
const minute = ('0'+timeNow.getMinutes()).slice(-2);
|
|
|
|
const second = ('0'+timeNow.getSeconds()).slice(-2);
|
|
|
|
|
|
|
|
const showDateTimeValue = day + "/" + month + "/" + year + " - " + hour + ":" + minute + ":" + second;
|
|
|
|
const objectDateTime = {
|
|
|
|
year: year,
|
|
|
|
month: month,
|
|
|
|
day: day,
|
|
|
|
hour: hour,
|
|
|
|
minute: minute,
|
|
|
|
second: second,
|
|
|
|
showDateTimeValue: showDateTimeValue
|
|
|
|
};
|
2019-09-19 15:56:58 +02:00
|
|
|
timeNow.setMinutes(timeNow.getMinutes() - enteredOffset)
|
|
|
|
|
2019-10-23 09:33:36 +02:00
|
|
|
return objectDateTime;
|
2019-09-19 15:56:58 +02:00
|
|
|
}
|
|
|
|
|
2019-11-11 17:55:52 +01:00
|
|
|
/**
|
|
|
|
* @function realDateTime
|
|
|
|
* @description Affiche l'heure en temps réel.
|
|
|
|
* @param {string} id
|
|
|
|
* @returns {boolean} true → Toujours true
|
|
|
|
* @example window.onload = realDateTime('realDateTime') → va afficher l'heure en temps réel au chargement de la page dans la balise avec l'id realDateTime
|
|
|
|
*/
|
2019-10-23 09:33:36 +02:00
|
|
|
function realDateTime(id) {
|
|
|
|
const realDateTimeNow = new Date;
|
|
|
|
// const year = realDateTimeNow.getFullYear();
|
|
|
|
// const month = ('0'+(realDateTimeNow.getMonth()+1)).slice(-2);
|
|
|
|
// const day = ('0'+realDateTimeNow.getDate()).slice(-2);
|
|
|
|
const hour = ('0'+realDateTimeNow.getHours()).slice(-2);
|
|
|
|
const minute = ('0'+realDateTimeNow.getMinutes()).slice(-2);
|
|
|
|
const second = ('0'+realDateTimeNow.getSeconds()).slice(-2);
|
|
|
|
|
|
|
|
const resultat = hour + ":" + minute + ":" + second;
|
2019-09-19 15:56:58 +02:00
|
|
|
|
|
|
|
document.getElementById(id).innerHTML = resultat;
|
|
|
|
setTimeout('realDateTime("'+id+'");','1000');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-11 17:55:52 +01:00
|
|
|
/**
|
|
|
|
* @function isValidDate
|
|
|
|
* @description Vérifie si une date est valide (si la variable verifyDate a déjà exister avant la variable currentDate).
|
|
|
|
* @param {string} verifyDate (format : dd/mm/yyyy) sachant qu'il faut faire -1 au mois car de 0 à 11 donc par exemple 14/12/2019 sera le 14 novembre 2019
|
|
|
|
* @param {string} currentDate (format : dd/mm/yyyy) pas besoin de faire -1 au mois donc par exemple 14/12/2019 sera le 14 décembre 2019
|
|
|
|
* @returns {boolean}
|
|
|
|
* @example
|
|
|
|
* isValidDate('10/11/2019', '11/11/2019') → false → Comparaison entre le 10 décembre 2019 et le 11 novembre 2019
|
|
|
|
* isValidDate('10/10/2019', '11/11/2019') → true → Comparison entre le 10 novembre 2019 et le 11 novembre 2019
|
|
|
|
*/
|
2019-10-23 09:33:36 +02:00
|
|
|
function isValidDate(verifyDate, currentDate) {
|
2019-09-19 15:56:58 +02:00
|
|
|
// Date à vérifier
|
2019-10-23 09:33:36 +02:00
|
|
|
const toVerifyDate = verifyDate.split('/');
|
2019-10-18 09:55:35 +02:00
|
|
|
const splitedToVerifyDate = toVerifyDate[2] + '-' + (parseInt(toVerifyDate[1]) + 1) + '-' + toVerifyDate[0];
|
|
|
|
const msToVerifyDate = Date.parse(splitedToVerifyDate);
|
2019-09-19 15:56:58 +02:00
|
|
|
|
|
|
|
// Date courante
|
|
|
|
currentDate = currentDate.substr(0,10);
|
2019-10-18 09:55:35 +02:00
|
|
|
const currentDateSplited = currentDate.split('/');
|
|
|
|
const currentDateFormat = currentDateSplited[2] + '-' + currentDateSplited[1] + '-' + currentDateSplited[0];
|
|
|
|
const msCurrentDate = Date.parse(currentDateFormat);
|
2019-09-19 15:56:58 +02:00
|
|
|
|
|
|
|
if(msToVerifyDate <= msCurrentDate) {
|
|
|
|
return true;
|
|
|
|
} else if(msToVerifyDate > msCurrentDate) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return messageError;
|
|
|
|
}
|
2019-10-04 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
2019-11-11 17:55:52 +01:00
|
|
|
/**
|
|
|
|
* @function createSessionCookie
|
|
|
|
* @description Créer un cookie de session.
|
|
|
|
* @param {string} name Nom du cookie
|
|
|
|
* @param {string} value Valeur du cookie
|
|
|
|
*/
|
2019-10-04 13:47:32 +02:00
|
|
|
function createSessionCookie(name, value) {
|
|
|
|
document.cookie = escape(name) + "=" + escape(value) + " ; path=/";
|
2019-12-11 20:46:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function getCookieValue
|
|
|
|
* @description Récupère la valeur d'un cookie.
|
|
|
|
* @param {string} name Nom du cookie
|
|
|
|
* @param {string} value Valeur du cookie
|
|
|
|
*/
|
|
|
|
function getCookieValue(cname) {
|
|
|
|
const name = cname + "=";
|
|
|
|
const decodedCookie = decodeURIComponent(document.cookie);
|
|
|
|
const ca = decodedCookie.split(';');
|
|
|
|
for(let i = 0; i < ca.length; i++) {
|
|
|
|
let c = ca[i];
|
|
|
|
while (c.charAt(0) == ' ') {
|
|
|
|
c = c.substring(1);
|
|
|
|
}
|
|
|
|
if (c.indexOf(name) == 0) {
|
|
|
|
return c.substring(name.length, c.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|