GMS 2 [SOLVED] date_leap_year requirements

Gamebot

Member
date_leap_year ( 2020 ) is returning false. So is every other leap year I try.

Is there a specific format I'm missing?
The only other guess is that this is supposed to be in one of the c++ redistribute files?
I don't want to report as a bug unless I know I'm doing it right.
 
Last edited:
Is there a specific format I'm missing?
You have to give it a date, not a year.
From the manual (https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/maths/date and time/date_leap_year.html):
This function will return true if the year component of the given datetime value is a leap year or false otherwise.
So if you just want to check the current year, then do exactly as the example on that page does by using date_current_datetime() as the parameter:
Code:
if date_leap_year(date_current_datetime())
 

TailBit

Member
It's because you are not using the datetime format, try create it using:
GML:
date_create_datetime(year, month, day, hour, minute, second);
you could even fill it with the buildin variables, current_year, current_month and such
 

Gamebot

Member
I did read the manual a few times. It looked like to me it just needed a year. I see the difference now.


It's because you are not using the datetime format, try create it using:
GML:
date_create_datetime(year, month, day, hour, minute, second);
you could even fill it with the buildin variables, current_year, current_month and such
I need different dates from different years so the correct .csv file can be loaded therefore, current_ anything is out of the question..
I did miss the date_create_datetime. I'll monkey around with it a bit later.

Thanks.
 

Gamebot

Member
Thanks everyone.

That was easy. Just used the:
date_create_datetime


scr_date_to_ordinal

GML:
var dy, mnth, yr, leap, file, out;

// d = day, m = month, y = year, l = ( if year == leapyear (boolean) )
mnth = argument0;
dy = argument1;
yr = argument2;

[COLOR=rgb(247, 218, 100)][SIZE=5]var date = date_create_datetime(yr, mnth, day, 12, 12, 12);[/SIZE][/COLOR]
leap  = date_leap_year(date);

// .csv creates and loads as a ds_grid. Remember to destroy.
switch (leap) {
case false: file = load_csv("Julian Ordinal Common.csv"); break;
case true:  file = load_csv("Julian Ordinal Leap.csv"); break;
}

out = ds_grid_get(file, mnth - 1, dy);

ds_grid_destroy(file);
return out;
The .csv files also goes the other way by finding a date from an ordinal.
 
Last edited:
Top