odd date_compare_time interaction

O

Ondona

Guest
hey there, im trying to make a script that will check if a time of a given datetime will fall between two other datetimes

the easiest way i figured was using the date_compare_time function but ran into an issue and found out that for some reason it is returning different values depending on if date_set_timezone() is set as timezone_utc or timezone_local

GML:
date_set_timezone(timezone_local);
var _current = date_create_datetime(current_year, current_month, current_day, 9, 25, 0);
var _start = date_create_datetime(current_year, current_month, current_day, 9, 20, 0);
var _end = date_create_datetime(current_year, current_month, current_day, 11, 30, 0);
var _afterstart = date_compare_time(_current, _start);
var _check1 = date_time_string(_current);
var _check2 = date_time_string(_start);
var _check3 = date_time_string(_end);
var _afterend = date_compare_time(_current, _end);
var _pausehere = 1;
for some reason when i use "timezone_local" both _afterstart and _afterend return 1 instead of afterend returning -1 but using utc it returns correctly

anyone know why this is happening? running on windows 10 (if it matters)

is there any benefit/downside to using utc over local? does date_current_datetime() return different values?
 

Nidoking

Member
I suspect that your local time is UTC+10 or UTC+11, such that when those times are converted internally into UTC, they lie on opposite sides of midnight and thus in different days. Using UTC skips that conversion and keeps them all in the same day, without changing the validity of the calculation (depending on where you're getting the datetime values from in the first place).

As for whether date_current_datetime returns different values, I would recommend experimenting with that yourself. You've got those _check variables - show_debug_message or inspect them in the debugger to see what values they have. I think if you date_date_string, you'll see different days.
 
O

Ondona

Guest
Ur correct, I am in +10 and that was my thinking that those commands are internally changing back to the utc timing I did a test with what u said about the date strings and they actually still all show as the same date so it appears that only the date_compare_time function is the only one changing back to utc
for calculations

my only thought for a workaround is to either manually specify the timezone and save that information with the app or create two datetimes for current time one with utc and one with local and get the difference and store that. Then whenever i need to display the time for the user add the timezone difference but i feel like this will cause issues (or atleast a bit of hassle) when calculations of "new day" will happen and having that inline with the actual users change of day

either that or write my own compare datetime funcitons haha... probs the easiest way actually

EDIT: did an extra test with the date_compare_date function and it seems to be doing the same as date_compare_time

timezone_local.PNGtimezone_utc.PNG
 
Top