2020-08-03 12:04:07 +02:00
|
|
|
/**
|
2020-03-24 16:11:55 +01:00
|
|
|
* @description Donne la date et l'heure selon l'UTC (Universal Time Coordinated).
|
2020-08-03 12:04:07 +02:00
|
|
|
* @param {String} utc Heure de décalage par rapport à l'UTC
|
2020-03-24 16:11:55 +01:00
|
|
|
* @returns {Function} → showDateTime(enteredOffset) → Retourne l'exécution de la fonction showDateTime
|
2020-08-03 12:04:07 +02:00
|
|
|
* @examples dateTimeUTC('0')
|
|
|
|
*/
|
|
|
|
function dateTimeUTC (utc) {
|
|
|
|
const timeNow = new Date()
|
|
|
|
const utcOffset = timeNow.getTimezoneOffset()
|
|
|
|
timeNow.setMinutes(timeNow.getMinutes() + utcOffset)
|
|
|
|
const enteredOffset = parseFloat(utc) * 60
|
|
|
|
timeNow.setMinutes(timeNow.getMinutes() + enteredOffset)
|
|
|
|
return showDateTime(timeNow)
|
|
|
|
}
|
2020-03-24 16:11:55 +01:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
/**
|
2020-03-24 16:11:55 +01:00
|
|
|
* @description Affiche la date et l'heure (format : dd/mm/yyyy - 00:00:00).
|
|
|
|
* @requires {@link fonctions_annexes.js: showDateTime}
|
2020-08-03 12:04:07 +02:00
|
|
|
* @param {String} utc Heure de décalage par rapport à l'UTC
|
2020-03-24 16:11:55 +01:00
|
|
|
* @returns {Object} Retourne un objet contenant l'année, le mois, le jour, l'heure, les minutes, les secondes et la date formaté
|
|
|
|
* @examples dateTimeUTC('0') → dateTimeUTC vous renvoie l'exécution de showDateTime
|
2020-08-03 12:04:07 +02:00
|
|
|
*/
|
|
|
|
function showDateTime (timeNow) {
|
|
|
|
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)
|
2020-08-03 14:14:45 +02:00
|
|
|
const showDateTimeValue =
|
|
|
|
day + '/' + month + '/' + year + ' - ' + hour + ':' + minute + ':' + second
|
2020-08-03 12:04:07 +02:00
|
|
|
const objectDateTime = {
|
|
|
|
year: year,
|
|
|
|
month: month,
|
|
|
|
day: day,
|
|
|
|
hour: hour,
|
|
|
|
minute: minute,
|
|
|
|
second: second,
|
|
|
|
showDateTimeValue: showDateTimeValue
|
|
|
|
}
|
|
|
|
return objectDateTime
|
2020-03-24 16:11:55 +01:00
|
|
|
}
|
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
module.exports = dateTimeUTC
|