2019-11-11 17:55:52 +01:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< title > JSDoc: Source: fonctions_annexes.js< / title >
< script src = "scripts/prettify/prettify.js" > < / script >
< script src = "scripts/prettify/lang-css.js" > < / script >
<!-- [if lt IE 9]>
< script src = "//html5shiv.googlecode.com/svn/trunk/html5.js" > < / script >
<![endif]-->
< link type = "text/css" rel = "stylesheet" href = "styles/prettify-tomorrow.css" >
< link type = "text/css" rel = "stylesheet" href = "styles/jsdoc-default.css" >
< / head >
< body >
< div id = "main" >
< h1 class = "page-title" > Source: fonctions_annexes.js< / h1 >
< section >
< article >
< pre class = "prettyprint source linenums" > < code > /* Fonctions Annexes */
/**
* @function isEmptyValue
* @description Vérifie si une valeur est vide.
* @param {string} value
* @returns {boolean}
* @example isEmptyValue(null) → true
*/
function isEmptyValue(value) {
return value === '' || value === null || value === undefined;
}
/**
* @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'
*/
function formatNumberResult(num) {
if(!isNaN(num) & & num >= 1000) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ');
}
else {
return num;
}
}
/**
* @function isFloat
* @description Vérifie si une string est un float (integer exclu).
* @param {number} value
* @returns {boolean}
* @example isFloat(76120.474) → true
*/
function isFloat(value) {
return !isNaN(value) & & value.toString().includes('.');
}
/**
* @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) {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
/**
* @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')
*/
function dateTimeUTC(utc) {
const enteredOffset = parseFloat(utc)*60;
timeNow.setMinutes(timeNow.getMinutes() + enteredOffset);
return showDateTime(enteredOffset);
}
/**
* @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
*/
function showDateTime(enteredOffset) {
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
};
timeNow.setMinutes(timeNow.getMinutes() - enteredOffset)
return objectDateTime;
}
/**
* @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
*/
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;
document.getElementById(id).innerHTML = resultat;
setTimeout('realDateTime("'+id+'");','1000');
return true;
}
/**
* @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
*/
function isValidDate(verifyDate, currentDate) {
// Date à vérifier
const toVerifyDate = verifyDate.split('/');
const splitedToVerifyDate = toVerifyDate[2] + '-' + (parseInt(toVerifyDate[1]) + 1) + '-' + toVerifyDate[0];
const msToVerifyDate = Date.parse(splitedToVerifyDate);
// Date courante
currentDate = currentDate.substr(0,10);
const currentDateSplited = currentDate.split('/');
const currentDateFormat = currentDateSplited[2] + '-' + currentDateSplited[1] + '-' + currentDateSplited[0];
const msCurrentDate = Date.parse(currentDateFormat);
if(msToVerifyDate < = msCurrentDate) {
return true;
} else if(msToVerifyDate > msCurrentDate) {
return false;
} else {
return messageError;
}
}
/**
* @function createSessionCookie
* @description Créer un cookie de session.
* @param {string} name Nom du cookie
* @param {string} value Valeur du cookie
*/
function createSessionCookie(name, value) {
document.cookie = escape(name) + "=" + escape(value) + " ; path=/";
} < / code > < / pre >
< / article >
< / section >
< / div >
< nav >
< h2 > < a href = "index.html" > Home< / a > < / h2 > < h3 > Global< / h3 > < ul > < li > < a href = "global.html#armstrongNumber" > armstrongNumber< / a > < / li > < li > < a href = "global.html#binaryToDecimal" > binaryToDecimal< / a > < / li > < li > < a href = "global.html#binaryToHexadecimal" > binaryToHexadecimal< / a > < / li > < li > < a href = "global.html#binaryToText" > binaryToText< / a > < / li > < li > < a href = "global.html#calculateAge" > calculateAge< / a > < / li > < li > < a href = "global.html#capitalize" > capitalize< / a > < / li > < li > < a href = "global.html#convertArabicToRoman" > convertArabicToRoman< / a > < / li > < li > < a href = "global.html#convertCurrency" > convertCurrency< / a > < / li > < li > < a href = "global.html#convertDistance" > convertDistance< / a > < / li > < li > < a href = "global.html#convertRomanToArabic" > convertRomanToArabic< / a > < / li > < li > < a href = "global.html#convertTemperature" > convertTemperature< / a > < / li > < li > < a href = "global.html#createSessionCookie" > createSessionCookie< / a > < / li > < li > < a href = "global.html#dateTimeUTC" > dateTimeUTC< / a > < / li > < li > < a href = "global.html#decimalToBinary" > decimalToBinary< / a > < / li > < li > < a href = "global.html#decimalToHexadecimal" > decimalToHexadecimal< / a > < / li > < li > < a href = "global.html#filterStudents" > filterStudents< / a > < / li > < li > < a href = "global.html#formatNumberResult" > formatNumberResult< / a > < / li > < li > < a href = "global.html#getRandomQuote" > getRandomQuote< / a > < / li > < li > < a href = "global.html#hexadecimalToBinary" > hexadecimalToBinary< / a > < / li > < li > < a href = "global.html#hexadecimalToDecimal" > hexadecimalToDecimal< / a > < / li > < li > < a href = "global.html#hexadecimalToText" > hexadecimalToText< / a > < / li > < li > < a href = "global.html#isEmptyValue" > isEmptyValue< / a > < / li > < li > < a href = "global.html#isFloat" > isFloat< / a > < / li > < li > < a href = "global.html#isValidDate" > isValidDate< / a > < / li > < li > < a href = "global.html#numberUnicodeToText" > numberUnicodeToText< / a > < / li > < li > < a href = "global.html#randomNumber" > randomNumber< / a > < / li > < li > < a href = "global.html#realDateTime" > realDateTime< / a > < / li > < li > < a href = "global.html#showDateTime" > showDateTime< / a > < / li > < li > < a href = "global.html#stringPermutations" > stringPermutations< / a > < / li > < li > < a href = "global.html#textToBinary" > textToBinary< / a > < / li > < li > < a href = "global.html#textToHexadecimal" > textToHexadecimal< / a > < / li > < li > < a href = "global.html#textToNumberUnicode" > textToNumberUnicode< / a > < / li > < li > < a href = "global.html#weatherRequest" > weatherRequest< / a > < / li > < / ul >
< / nav >
< br class = "clear" >
< footer >
2019-11-16 10:17:28 +01:00
Documentation generated by < a href = "https://github.com/jsdoc/jsdoc" > JSDoc 3.6.3< / a > on Sat Nov 16 2019 10:11:50 GMT+0100 (GMT+01:00)
2019-11-11 17:55:52 +01:00
< / footer >
< script > prettyPrint ( ) ; < / script >
< script src = "scripts/linenumber.js" > < / script >
< / body >
< / html >