Fixes, adjustement :)

This commit is contained in:
Divlo 2019-10-23 09:33:36 +02:00
parent 6e2d3fe580
commit a176e81c6a
5 changed files with 57 additions and 77 deletions

View File

@ -44,6 +44,5 @@ Le projet est disponible sur [function.divlo.fr](https://function.divlo.fr/).
| **dateTimeUTC(utc)** | Donne la date et l'heure selon l'UTC (Universal Time Coordinated). | - utc : heure de décalage avec l'utc |
| **showDateTime(enteredOffset)** | Affiche la date et l'heure (format : dd/mm/yyyy - 00:00:00). | - enteredOffset : date à formaté |
| **realDateTime(id)** | Affiche l'heure en temps réel. | - id : l'id de votre span/div où vous voulez afficher l'heure en temps réel |
| **timeZone(json)** | Récupére le décalage en secondes à partir de l'heure UTC grâce à l'API openweathermap.org. | - json : le json de l'API |
| **isValidDate(s)** | Vérifie si une date est valide par rapport à la date d'aujourd'hui. | - s : la date à verifier (format : dd/mm/yyyy) |
| **createSessionCookie(name, value)** | Créer un cookie de session | - name : nom du cookie - value : valeur du cookie |

View File

@ -17,18 +17,12 @@ function formatNumberResult(num) {
// Vérifie si une string est un float (integer exclu)
function isFloat(value) {
return !isNaN(value) && value.toString().indexOf('.') != -1;
return !isNaN(value) && value.toString().includes('.');
}
// 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) {
if(!isNaN(num)) {
const number = formatNumberResult((num).toFixed(0));
return number;
}
else {
return messageError;
}
return formatNumberResult((num).toFixed(0));
}
// Majuscule à la 1ère lettre d'une string
@ -50,53 +44,53 @@ function dateTimeUTC(utc) {
// 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);
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);
showDateTimeValue = day + "/" + month + "/" + year + " - " + hour + ":" + minute + ":" + second;
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 showDateTimeValue;
return objectDateTime;
}
// 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);
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);
resultat = hour + ":" + minute + ":" + second;
const resultat = hour + ":" + minute + ":" + second;
document.getElementById(id).innerHTML = resultat;
setTimeout('realDateTime("'+id+'");','1000');
return true;
}
// Récupére le décalage en secondes à partir de l'heure UTC grâce à l'API openweathermap.org
function timeZone(json) {
timeZoneValue = json.timezone / 60 / 60;
const timeZoneStr = timeZoneValue.toString();
return dateTimeUTC(timeZoneStr);
}
// Vérifie si une date est valide par rapport à la date d'aujourd'hui
function isValidDate(s) {
function isValidDate(verifyDate, currentDate) {
// Date à vérifier
const toVerifyDate = s.split('/');
const toVerifyDate = verifyDate.split('/');
const splitedToVerifyDate = toVerifyDate[2] + '-' + (parseInt(toVerifyDate[1]) + 1) + '-' + toVerifyDate[0];
const msToVerifyDate = Date.parse(splitedToVerifyDate);
// Date courante
let currentDate = dateTimeUTC('0');
currentDate = currentDate.substr(0,10);
const currentDateSplited = currentDate.split('/');
const currentDateFormat = currentDateSplited[2] + '-' + currentDateSplited[1] + '-' + currentDateSplited[0];

View File

@ -9,7 +9,7 @@ function weatherRequest() {
try {
const json = jQuery.parseJSON(data);
const city = json.name;
const showDateTimeValue = timeZone(json);
const showDateTimeValue = dateTimeUTC((json.timezone / 60 / 60).toString()).showDateTimeValue;
$('.results').html(`🌎 Position : <a href='https://www.google.com/maps/search/?api=1&query=${json.coord.lat},${json.coord.lon}' class="yellow-color" target="_blank">${city}, ${json.sys.country}</a><br>⏰ Date et heure : ${showDateTimeValue}<br>☁️ Météo : ${capitalize(json.weather[0].description)}<br> 🌡️ Température : ${json.main.temp} °C<br> 💧 Humidité : ${json.main.humidity}% <br> <img src="https://openweathermap.org/img/wn/${json.weather[0].icon}@2x.png"/>`);
}
@ -38,10 +38,10 @@ function calculateAge(birthDateEntered) {
const birthDateDay = parseInt(birthDateEntered.substring(0, 2));
const birthDateMonth = parseInt((birthDateEntered.substring(3, 5)) - 1);
const birthDateYear = parseInt(birthDateEntered.substring(6, 10));
dateTimeUTC('0');
day = parseInt(day);
month = parseInt(month - 1);
year = parseInt(year);
const currentDateObject = dateTimeUTC('0');
const day = parseInt(currentDateObject.day);
const month = parseInt(currentDateObject.month - 1);
const year = parseInt(currentDateObject.year);
let dateNow = moment([year, month, day]);
let birthDate = moment([birthDateYear, birthDateMonth, birthDateDay]);
@ -53,13 +53,13 @@ function calculateAge(birthDateEntered) {
birthDate.add(ageMonths, 'months');
let ageDays = dateNow.diff(birthDate, 'days');
const isValidDateFunction = isValidDate(birthDateDay + '/' + birthDateMonth + '/' + birthDateYear);
const isValidDateFunction = isValidDate(birthDateDay + '/' + birthDateMonth + '/' + birthDateYear, currentDateObject.showDateTimeValue);
// Vérifie si la valeur entrée correspond à une date de naissance valide
if(isValidDateFunction === true && !isNaN(ageDays)) {
ageYears = formatNumberResult(ageYears);
// Si c'est ton anniversaire aujourd'hui
if(birthDateDay === parseInt(day) && (parseInt(birthDateMonth) + 1) === parseInt(month)) {
if(birthDateDay === day && parseInt(birthDateMonth) === month) {
return 'Vous avez ' + ageYears + ' ans. Joyeux Anniversaire! 🥳';
}
else {

View File

@ -2,31 +2,25 @@ $(function () {
/* ÉXECUTION DES FONCTONS */
$( "#submitWeatherRequest" ).click(function()
{
$( "#submitWeatherRequest" ).click(() => {
const city = $('#cityName').val();
const cityName = city.split(' ').join('+');
if(isEmptyValue(cityName))
{
if(isEmptyValue(cityName)) {
$('.results').html(emptyMessageError);
}
else
{
else {
createSessionCookie("city", cityName);
weatherRequest();
}
});
$("#submitRandomNumber").click(function()
{
$("#submitRandomNumber").click(() => {
const minEntered = $('#minValue').val();
const maxEntered = $('#maxValue').val();
if(isEmptyValue(minEntered) || isEmptyValue(maxEntered))
{
if(isEmptyValue(minEntered) || isEmptyValue(maxEntered)) {
$('.results').html(emptyMessageError);
}
else
{
else {
const result = randomNumber(minEntered, maxEntered);
if(result === messageError) {
$('.results').html(messageError);
@ -36,13 +30,13 @@ $(function () {
}
});
$("#birthDateValue").bind("keyup change", function()
$("#birthDateValue").bind("keyup change", () =>
{
const birthDateEntered = $('#birthDateValue').val();
$('.results').html(calculateAge(birthDateEntered));
});
$("#submitConvertTemperature").click(function()
$("#submitConvertTemperature").click(() =>
{
const temperatureValue = $('#temperatureValue').val();
const degree = parseFloat(temperatureValue.slice(0, temperatureValue.length - 2));
@ -55,7 +49,7 @@ $(function () {
}
});
$("#submitConvertDistance").click(function()
$("#submitConvertDistance").click(() =>
{
let firstValue = $('#firstValue').val();
const unitFirstValue = $("#firstValueUnit option:selected").text();
@ -69,7 +63,7 @@ $(function () {
}
});
$("#submitFilterStudents").click(function()
$("#submitFilterStudents").click(() =>
{
const nameEntered = $('#nameEntered').val();
let filteredLetter = $("#filteredLetter").val();
@ -87,13 +81,12 @@ $(function () {
});
let randomQuoteClicked;
$("#submitRandomQuote").click(function()
{
$("#submitRandomQuote").click(() => {
randomQuoteClicked = true;
$('.resultsRandomQuote').html(getRandomQuote());
});
// Affichage d'une citation au chargement de la page
if (randomQuoteClicked != true && window.location.href.indexOf("randomQuote") > -1) {
if (randomQuoteClicked != true && window.location.href.includes("randomQuote")) {
$('.resultsRandomQuote').html(getRandomQuote());
}
@ -107,8 +100,7 @@ $(function () {
$( ".quote-list" ).append(resultat);
}
$("#submitConvertCurrency").click(function()
{
$("#submitConvertCurrency").click(() => {
let value = $('#value').val();
const currencyOfTheValue = $("#currencyOfTheValue option:selected").val();
const currencyAfter = $("#currencyAfter option:selected").val();
@ -122,15 +114,13 @@ $(function () {
}
});
$("#submitConvertEncoding").click(function()
{
$("#submitConvertEncoding").click(() => {
const value = $('#value').val();
const option = $("#option option:selected").val();
if(isEmptyValue(value)) {
$('.results').html(messageError);
}
else
{
else {
if (option === 'DecimalToBinary' || option === 'BinaryToDecimal' || option === 'DecimalToHexadecimal' || option === 'HexadecimalToDecimal' || option === 'BinaryToHexadecimal' || option === 'HexadecimalToBinary') {
const result = convertDecimalBinaryHexadecimal(value, option);
$('.results').html(result);
@ -160,8 +150,7 @@ $(function () {
}
});
$("#submitConvertRomanArabicNumbers").click(function()
{
$("#submitConvertRomanArabicNumbers").click(() => {
let numbersValue = $('#numbersArabic').val();
numbersValue = numbersValue.replace(/\s/g,'');
const convertNumberType = $("#convertNumberType option:selected").text();
@ -195,8 +184,7 @@ $(function () {
}
});
$("#numberToTest").bind("keyup change", function()
{
$("#numberToTest").bind("keyup change", () => {
let numbersValue = $('#numberToTest').val();
numbersValue = parseInt(numbersValue.replace(/\s/g,''));
if (!isNaN(numbersValue) && numbersValue >= 0) {
@ -207,8 +195,7 @@ $(function () {
}
});
$("#submitHeapAlgorithm").click(function()
{
$("#submitHeapAlgorithm").click(() => {
const value = $('#value').val();
if(isEmptyValue(value)) {
$('.results').html(emptyMessageError);

View File

@ -6,7 +6,7 @@ let chemin = window.location.pathname;
const emptyMessageError = "Vous ne pouvez pas rentré de valeur vide.";
const messageError = "Vous n'avez pas rentré de valeur valide.";
/* Varibales pour les fonctions */
/* Variables pour les fonctions */
let timeNow = new Date();
let utcOffset = timeNow.getTimezoneOffset();
timeNow.setMinutes(timeNow.getMinutes() + utcOffset);