2019-09-19 15:56:58 +02:00
|
|
|
/* Fonctions Annexes */
|
|
|
|
|
|
|
|
// Vérifie si une valeur est vide
|
|
|
|
function isEmptyValue(value) {
|
2019-10-13 20:58:13 +02:00
|
|
|
return value === '' || value === null || value === undefined;
|
2019-09-19 15:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Formate les nombres avec des espaces (ex : 76120 = 76 120)
|
|
|
|
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-10-18 20:35:03 +02:00
|
|
|
// Vérifie si une string est un float (integer exclu)
|
|
|
|
function isFloat(value) {
|
|
|
|
return !isNaN(value) && value.toString().indexOf('.') != -1;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:56:58 +02:00
|
|
|
// Convertit les puissances de 10 en nombre (ex: 1e+20 = 100 000 000 000 000 000 000), ne peut pas dépasser 1e+20 (21 ne fonctionne pas)
|
|
|
|
function convertPuissanceToNumber(num) {
|
2019-10-18 20:35:03 +02:00
|
|
|
if(!isNaN(num)) {
|
2019-10-18 09:55:35 +02:00
|
|
|
const number = formatNumberResult((num).toFixed(0));
|
2019-09-19 15:56:58 +02:00
|
|
|
return number;
|
|
|
|
}
|
2019-10-18 20:35:03 +02:00
|
|
|
else {
|
2019-09-19 15:56:58 +02:00
|
|
|
return messageError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Majuscule à la 1ère lettre d'une string
|
|
|
|
function capitalize (s) {
|
|
|
|
if (typeof s !== 'string') return ''
|
|
|
|
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Donne la date et l'heure selon l'UTC (Universal Time Coordinated)
|
|
|
|
function dateTimeUTC(utc) {
|
2019-10-04 21:14:48 +02:00
|
|
|
let result = "";
|
|
|
|
for (let index in utc) {
|
|
|
|
result = result + utc[index];
|
2019-09-19 15:56:58 +02:00
|
|
|
}
|
2019-10-18 09:55:35 +02:00
|
|
|
const enteredOffset = parseFloat(result)*60;
|
2019-10-04 21:14:48 +02:00
|
|
|
timeNow.setMinutes(timeNow.getMinutes() + enteredOffset);
|
|
|
|
return showDateTime(enteredOffset);
|
2019-09-19 15:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Affiche la date et l'heure (format : dd/mm/yyyy - 00:00:00)
|
|
|
|
function showDateTime(enteredOffset) {
|
|
|
|
year = timeNow.getFullYear();
|
|
|
|
month = ('0'+(timeNow.getMonth()+1)).slice(-2);
|
|
|
|
day = ('0'+timeNow.getDate()).slice(-2);
|
|
|
|
hour = ('0'+timeNow.getHours()).slice(-2);
|
|
|
|
minute = ('0'+timeNow.getMinutes()).slice(-2);
|
|
|
|
second = ('0'+timeNow.getSeconds()).slice(-2);
|
|
|
|
|
|
|
|
showDateTimeValue = day + "/" + month + "/" + year + " - " + hour + ":" + minute + ":" + second;
|
|
|
|
timeNow.setMinutes(timeNow.getMinutes() - enteredOffset)
|
|
|
|
|
|
|
|
return showDateTimeValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Affiche l'heure en temps réel
|
|
|
|
function realDateTime(id)
|
|
|
|
{
|
|
|
|
realDateTimeNow = new Date;
|
|
|
|
year = realDateTimeNow.getFullYear();
|
|
|
|
month = ('0'+(realDateTimeNow.getMonth()+1)).slice(-2);
|
|
|
|
day = ('0'+realDateTimeNow.getDate()).slice(-2);
|
|
|
|
hour = ('0'+realDateTimeNow.getHours()).slice(-2);
|
|
|
|
minute = ('0'+realDateTimeNow.getMinutes()).slice(-2);
|
|
|
|
second = ('0'+realDateTimeNow.getSeconds()).slice(-2);
|
|
|
|
|
|
|
|
resultat = hour + ":" + minute + ":" + second;
|
|
|
|
|
|
|
|
document.getElementById(id).innerHTML = resultat;
|
|
|
|
setTimeout('realDateTime("'+id+'");','1000');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-13 20:58:13 +02:00
|
|
|
// Récupére le décalage en secondes à partir de l'heure UTC grâce à l'API openweathermap.org
|
2019-09-19 15:56:58 +02:00
|
|
|
function timeZone(json) {
|
2019-10-13 20:58:13 +02:00
|
|
|
timeZoneValue = json.timezone / 60 / 60;
|
2019-10-18 09:55:35 +02:00
|
|
|
const timeZoneStr = timeZoneValue.toString();
|
2019-09-19 15:56:58 +02:00
|
|
|
return dateTimeUTC(timeZoneStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vérifie si une date est valide par rapport à la date d'aujourd'hui
|
|
|
|
function isValidDate(s) {
|
|
|
|
// Date à vérifier
|
2019-10-18 09:55:35 +02:00
|
|
|
const toVerifyDate = s.split('/');
|
|
|
|
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
|
2019-10-18 20:35:03 +02:00
|
|
|
let currentDate = dateTimeUTC('0');
|
2019-09-19 15:56:58 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Créer un cookie de session
|
|
|
|
function createSessionCookie(name, value) {
|
|
|
|
document.cookie = escape(name) + "=" + escape(value) + " ; path=/";
|
|
|
|
}
|