doc • calendar

Dates and calendars

Gambas uses the Gregorian calendar

Wikipedia tells us:

"The Gregorian calendar is the calendar used in most of the world. It was introduced in October 1582 by Pope Gregory XIII as a minor modification of the Julian calendar, reducing the average year from 365.25 days to 365.2425 days, thus correcting for the drift against the solar year that the inaccuracy had caused during the intervening centuries..."

It's better to assume that every country and every people use their own calendar system, which do not match day to day. Because some follows the Sun, other the Moon, count months differently, years differently, begin the day the morning or the evening, have some holes in the calendar similar to the Julian/Gregorian transition, and so on... The human imagination has no limit.

The Gregorian calendar is now more or less understood by most the world, so it is a good candidate to be what Coordinated Universal Time (UTC) is for time.

Gambas almost uses the Gregorian calendar!

In Gambas, the date is internally stored as a number of day since January 1st 4801 BC.

But this date is actually a date of the Gregorian calendar extended to the past. Because the Gregorian calendar was adopted October 15th 1582, at least in the Catholic European world.

In other words:

  • October 15th 1582, and following days are exact.

  • The day before October 15th 1582 is not October 4th 1582 of the Julian calendar, but October 14th 1582. And so on.

This is by design: conversion between integers and dates, and date arithmetic have been favored for the sake of performance and simplicity.

Beware that in that extended Gregorian calendar, there is no year 0. The year following 1 BC is 1 AC.


You have to be careful when using the WeekDay function. As soon as your date is lower than October 15th 1582, the returned day is false.

You have to be careful too that the Gregorian calendar was adopted at different moments according to the country: for example, William Shakespeare and Miguel de Cervantes seemingly died on exactly the same date (April 23rd 1616), but Cervantes predeceased Shakespeare by ten days in real time (as Spain used the Gregorian calendar, but Britain used the Julian calendar).

The DateChooser control does not handle specific calendars. This could be an interesting development to do: adding support for different calendars, with transparent conversion between Gambas dates and local dates.

See also