2023-11-29 20:05:48 +00:00
|
|
|
const { DateTime } = require('luxon')
|
|
|
|
|
|
|
|
function dateTime() {
|
|
|
|
const brazilTimeZone = 'America/Sao_Paulo'
|
|
|
|
const currentDateBrazil = DateTime.now().setZone(brazilTimeZone) // Get current date and time in Brazil timezone
|
|
|
|
|
|
|
|
const formattedDateTime = currentDateBrazil.toFormat("yyyy-MM-dd'T'HH:mm:ssZZ") // Format to ISO 8601
|
2024-09-24 12:10:18 +00:00
|
|
|
|
2023-11-29 20:05:48 +00:00
|
|
|
console.log('FORMATTED DATE TIME: ', formattedDateTime)
|
|
|
|
|
|
|
|
return formattedDateTime
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function secondsFormat(seconds, format = '') {
|
|
|
|
|
2024-09-24 12:10:18 +00:00
|
|
|
seconds = parseInt(seconds, 10)
|
2023-11-29 20:05:48 +00:00
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case 'hh:mm':
|
|
|
|
const hours = Math.floor(seconds / 3600)
|
|
|
|
const minutes = Math.floor((seconds % 3600) / 60)
|
|
|
|
const formattedHours = String(hours).padStart(2, '0')
|
|
|
|
const formattedMinutes = String(minutes).padStart(2, '0')
|
|
|
|
console.log(`formate hours: ${formattedHours}:${formattedMinutes}`)
|
|
|
|
return `${formattedHours}:${formattedMinutes}`
|
|
|
|
case 'milliseconds':
|
|
|
|
return seconds * 1000
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return seconds
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-09-24 12:10:18 +00:00
|
|
|
function getPastDateTimeFromSeconds(currentTime, secondsToSubtract) {
|
2023-11-29 20:05:48 +00:00
|
|
|
|
|
|
|
const currentDateTime = DateTime.fromISO(currentTime)
|
|
|
|
|
|
|
|
// Subtract seconds from the current date and time
|
|
|
|
const pastDateTime = currentDateTime.minus({ seconds: secondsToSubtract })
|
|
|
|
|
|
|
|
// Extract timezone offset from the current time
|
|
|
|
const timezoneOffset = currentDateTime.toFormat('ZZ')
|
|
|
|
|
|
|
|
// Format the past date and time in the desired format manually
|
|
|
|
const formattedPastDateTime = pastDateTime.toFormat(`yyyy-MM-dd'T'HH:mm:ss${timezoneOffset}`)
|
|
|
|
|
|
|
|
return formattedPastDateTime
|
|
|
|
}
|
|
|
|
|
2024-09-24 12:10:18 +00:00
|
|
|
function currentYearMonthDay() {
|
|
|
|
const originalDate = 'YYYY-MM-DD'
|
|
|
|
|
|
|
|
const parsedDate = new Date(originalDate)
|
|
|
|
|
|
|
|
const today = new Date()
|
|
|
|
|
|
|
|
parsedDate.setFullYear(today.getFullYear())
|
|
|
|
parsedDate.setMonth(today.getMonth())
|
|
|
|
parsedDate.setDate(today.getDate())
|
|
|
|
|
|
|
|
return parsedDate.toISOString().split('T')[0]
|
|
|
|
}
|
|
|
|
|
2023-11-29 20:05:48 +00:00
|
|
|
|
|
|
|
|
2024-09-24 12:10:18 +00:00
|
|
|
module.exports = { dateTime, secondsFormat, getPastDateTimeFromSeconds, currentYearMonthDay }
|