BGT calendar object and NVGT conversion

Hello!
I'm currently converting a project of mine from BGT to NVGT.
I now have a question regarding the use of the calendar object.
Most of the functions seem to work just fine, I've substituted the reset function for a set function with a specific date. However, the add_hours, add_minutes and add_seconds functions do not seem to work.
Are any of you aware of a possible workaround regarding these issues?
Regards
Taurus Fan

1 Like

Adding Time

Hello.
There is no specific function to add hours, minutes, seconds. However, here is available method:

void main() {
	string format = "%W, %B %d, %Y at %h:%M:%S %A %Z"; //Temporary format string to display the differents.
	calendar c; //Focusing on current time.
	timestamp t;
	t += 1 * HOURS; //Add 1 hour
	alert("Current time", c.format(format));
	//Lets add the hour.
	c = t;
	alert("New date time", c.format(format));
}

That's it!

Available Constants

As you can add hours, you can also add other. Here is a list of available constants:

  • DAYS
  • HOURS
  • MINUTES
  • SECONDS
  • MILLISECONDS
  • MICROSECONDS

For example if you want to add days, you can do, t += 1 * DAYS;

Hope it helps!

1 Like

It's also worth noting that as this is a popular request, we will certainly add these remaining methods to this object at some near point in the future.

Thank you both for your answers, that really helps.

How could I create a function to obtain the distance in months between the current time and another calendar, like diff_months etc?

Hi,

Unfortunately it's not perfectly simple right now, we'll get the functions into NVGT's core itself at some point.

The timespan object only diffs up to days, weeks is easy because that's just days times 7, but for months you would need to calculate it using the helper function int datetime_days_of_month(int year, int month) which is in NVGT's core. NVGT also has bool datetime_is_leap_year(int year); which can help you complete your calculations.

I apologize for the difficulty here, I'll write such a function at some point and register it with the calendar object.

Make sure it also gets added to datetime object :slight_smile: