I’m trying to find a way to check whether or not an input time has been passed. I’ve been trying to use the time class to do this, but have been unsuccessful. What I’ve been trying to do is convert a dictionary to unix time, then see if that is smaller than the system’s unix time. Here’s what I have:
@onready var end: LineEdit = $GridContainer/End
func _process(_delta: float) -> void:
var END_ARRAY: Array = time_check(end.text.split(":",true,2))
func time_check(ARRAY) -> Array:
var DICTIONARY: Dictionary = Time.get_datetime_dict_from_system()
if ARRAY.size() != 3:
return["Not enough information!",DICTIONARY]
elif not ARRAY[0].is_valid_int() or ARRAY[0].to_int() > 24 or ARRAY[0].to_int() < 1:
return["Your hour is invalid!",DICTIONARY]
else:
DICTIONARY.set("hour",ARRAY[0].to_int())
if not ARRAY[1].is_valid_int() or ARRAY[1].to_int() > 59 or ARRAY[1].to_int() < 0:
return["Your minute is invalid!",DICTIONARY]
else:
DICTIONARY.set("minute",ARRAY[1].to_int())
if not ARRAY[2].is_valid_int() or ARRAY[2].to_int() > 59 or ARRAY[2].to_int() < 0:
return["Your second is invalid!",DICTIONARY]
else:
DICTIONARY.set("second",ARRAY[2].to_int())
# This is where my issue is, anyone know why?
if Time.get_unix_time_from_system() > Time.get_unix_time_from_datetime_dict(DICTIONARY):
return["That time has passed!",DICTIONARY]
else:
return[String(),DICTIONARY]
Your code seems really complicated. What if you just convert the end text directly into a unix timestamp with Time.get_unix_time_from_datetime_string()?
Found my solution. The issue was it couldn’t tell I was inputting a time in my timezone. I had to convert the dictionary to be utc. First, I had to make sure the dictionary was set to utc at the beginning. Then, I had to convert the inputed time to utc using the timezone bias, which I multiplied by 60 to convert it into seconds since it returns minutes and subtract 86400, because it gives me a day over for some reason.
@onready var end: LineEdit = $GridContainer/End
func _process(_delta: float) -> void:
var END_ARRAY: Array = time_check(end.text.split(":",true,2))
func time_check(ARRAY) -> Array:
var DICTIONARY: Dictionary = Time.get_datetime_dict_from_system(true)
if ARRAY.size() != 3:
return["Not enough information!",DICTIONARY]
elif not ARRAY[0].is_valid_int() or ARRAY[0].to_int() > 24 or ARRAY[0].to_int() < 1:
return["Your hour is invalid!",DICTIONARY]
else:
DICTIONARY.set("hour",ARRAY[0].to_int())
if not ARRAY[1].is_valid_int() or ARRAY[1].to_int() > 59 or ARRAY[1].to_int() < 0:
return["Your minute is invalid!",DICTIONARY]
else:
DICTIONARY.set("minute",ARRAY[1].to_int())
if not ARRAY[2].is_valid_int() or ARRAY[2].to_int() > 59 or ARRAY[2].to_int() < 0:
return["Your second is invalid!",DICTIONARY]
else:
DICTIONARY.set("second",ARRAY[2].to_int())
if Time.get_unix_time_from_system() > Time.get_unix_time_from_datetime_dict(DICTIONARY) - Time.get_time_zone_from_system().bias * 60 - 86400:
return["That time has passed!",DICTIONARY]
else:
return[String(),DICTIONARY]