samtupy / nvgt

The Nonvisual Gaming Toolkit
https://nvgt.gg
Other
43 stars 27 forks source link

Datetime Function Existence #35

Closed harrymkt closed 1 month ago

harrymkt commented 1 month ago

Hello. First of all, it would be best if this repository has discussion page turned on so questions can be asked in discussion page instead, more like a forum without using issues page, since the questions aren't always issues.

Anyway, is there any function for datetime?

For example, we currently have datetime object. We would need some methods like, double datetime::diff_years(datetime@ other); like the BGT's calendar diff functions. Or please provide if there are such functions already been added.

I am making a similar function to date object in PHP with supporting format in BGT, so I want just now to it be converted to NVGT. Here it is:

string get_time_in_format(string format="<dd>/<mm>/<y>, <hh>:<nn>:<ss> <TT>",double a=DATE_YEAR,double b=DATE_MONTH,double c=DATE_DAY,double d=TIME_HOUR,double e=TIME_MINUTE,double f=TIME_SECOND)
{
string result=format;
calendar cl;
cl.set(a,b,c,d,e,f);
string date, month, year, hour12, hour12x0, hour24, minute, second, daytime_lc, daytime;
date=c;
if(c<10)
{
date="0"+date;
}
month=""+b;
if(b<10)
{
month="0"+month;
}
year=""+a;
year=string_trim_left(year, 2);
hour24=""+d;
if(d<10)
{
hour24="0"+hour24;
}
if(d>12)
{
hour12=""+(d-12);
hour12x0=""+(d-12);
daytime="PM";
daytime_lc="pm";
}
if(d==0)
{
hour12="12";
hour12x0="12";
daytime="AM";
daytime_lc="am";
}
if(d<=12)
{
if(d>0)
{
hour12=""+d;
hour12x0=""+d;
daytime="AM";
daytime_lc="am";
}
}
if(d<10)
{
if(d>0)
{
hour12="0"+hour12;
}
}
if(d<22)
{
if(d>12)
{
hour12="0"+hour12;
}
}
minute=e;
if(e<10)
{
minute="0"+minute;
}
second=f;
if(f<10)
{
second="0"+second;
}
if(result!="")
{
result=string_replace(result, "<d>", ""+c+"", true);
result=string_replace(result, "<D>", ""+c+"", true);
result=string_replace(result, "<dd>", date, true);
result=string_replace(result, "<DD>", date, true);
result=string_replace(result, "<w>", ""+cl.weekday, true);
result=string_replace(result, "<W>", cl.weekday_name, true);
result=string_replace(result, "<m>", ""+b, true);
result=string_replace(result, "<M>", cl.month_name, true);
result=string_replace(result, "<mm>", month, true);
result=string_replace(result, "<y>", ""+a, true);
result=string_replace(result, "<Y>", year, true);
result=string_replace(result, "<h>", hour12x0, true);
result=string_replace(result, "<hh>", hour12, true);
result=string_replace(result, "<H>", ""+d, true);
result=string_replace(result, "<HH>", hour24, true);
result=string_replace(result, "<n>", ""+e, true);
result=string_replace(result, "<N>", ""+e, true);
result=string_replace(result, "<nn>", minute, true);
result=string_replace(result, "<NN>", minute, true);
result=string_replace(result, "<s>", ""+f, true);
result=string_replace(result, "<S>", ""+f, true);
result=string_replace(result, "<ss>", second, true);
result=string_replace(result, "<SS>", second, true);
result=string_replace(result, "<tt>", daytime_lc, true);
result=string_replace(result, "<TT>", daytime, true);
}
return result;
}
TheQuinbox commented 1 month ago

Hi, I don't think we have something exactly like diff_years, but datetime implements the opSub operator overload, so you can subtract two datetime objects and compare the fields. If I recall correctly though, we plan to replace the datetime object with Poco's Datetime class as opposed to an Angelscript addon, so it's possible this could be added in the future.

harrymkt commented 1 month ago

So, could you show an example diffing with it?