Closed Mesrine67 closed 1 month ago
lib.cron uses system time...
example of the code that I want to propose, this is what I am talking about
local timeZones = {
fr = "Europe/Paris",
us = "America/New_York",
jp = "Asia/Tokyo"
}
local defaultTimeZone = 'fr'
local function getTimeZone()
local localTime = GetConvar('localTime', defaultTimeZone)
return timeZones[localTime] or timeZones[defaultTimeZone]
end
local function formatDateTime(dateTime)
local year, month, day, hour, min, sec = dateTime:match("(%d+)%-(%d+)%-(%d+)T(%d+):(%d+):(%d+)")
if year and month and day and hour and min and sec then
return string.format("%02d-%02d-%04d %02d:%02d:%02d", day, month, year, hour, min, sec)
else
return dateTime
end
end
local function fetchCurrentDateTime(callback)
local timeZone = getTimeZone()
PerformHttpRequest("http://worldtimeapi.org/api/timezone/" .. timeZone, function(statusCode, response, headers)
if statusCode == 200 then
local data = json.decode(response)
if data and data.datetime then
local dateTime = formatDateTime(data.datetime)
callback(dateTime)
else
callback(nil)
end
else
callback(nil)
end
end, "GET", "", {})
end
RegisterCommand('time', function(source, args, rawCommand)
fetchCurrentDateTime(function(dateTime)
if dateTime then
local notification = {
id = 'current_time',
title = 'Current Date and Time',
description = string.format('**Date and Time:** %s', dateTime),
duration = 5000,
position = 'top-right',
type = 'inform',
style = {
backgroundColor = '#141517',
color = '#C1C2C5',
['.description'] = {
color = '#00FF00'
}
},
icon = 'clock',
iconColor = '#00FF00',
iconAnimation = 'pulse'
}
TriggerClientEvent('ox_lib:notify', source, notification)
lib.print.info(("Current DateTime for player %s: %s"):format(source, dateTime))
else
local notification = {
id = 'time_fetch_failed',
title = 'Error',
description = '**Failed to fetch current date and time.**',
duration = 5000,
position = 'top-right',
type = 'error',
style = {
backgroundColor = '#FF0000',
color = '#FFFFFF',
['.description'] = {
color = '#FFFFFF'
}
},
icon = 'times-circle',
iconColor = '#FF0000',
iconAnimation = 'shake'
}
TriggerClientEvent('ox_lib:notify', source, notification)
lib.print.error(("Failed to fetch current date and time for player %s"):format(source))
end
end)
end, true)
Wtf cron is using system time, Txadmin also for reboots etc
You need to change your system time. That's all
Would it be possible to synchronize the time of
lib.cron
withsetr ox:locale
orsetr ox:localeTime
?