Date in date_type.h
Moderator: OpenTTD Developers
Date in date_type.h
How exactly does int32 Date work? Is it a "simple" counter of days passed since 1 Jan 0000 ? (ATM this is my understanding)
Neither Doxygen nor the Wiki help here!
Neither Doxygen nor the Wiki help here!
Re: Date in date_type.h
A bit further down in the file is YearMonthDay, which says
I haven't looked what the functions do exactly, but maybe that's what you are looking for?
It usually helps to browse around, and check where (in this case) Date is used, to get a feel how to use it.
Of course, fixes for doxymentation are always welcome.
Code: Select all
/**
* Data structure to convert between Date and triplet (year, month, and day).
* @see ConvertDateToYMD(), ConvertYMDToDate()
*/
It usually helps to browse around, and check where (in this case) Date is used, to get a feel how to use it.
Of course, fixes for doxymentation are always welcome.
Re: Date in date_type.h
Actually that was the reason why I asked the question in the first place! That particular function has a funny way of dealing with leap years to my eyes. Playing around, I think that Date is a day counter from 0000-01-01, but then again the only advantage I can see with that is that you can use C++'s inbuilt plus/minus/times/divide rather than making new ones. (Wasted time from 0 to 1920, and we only use 1920 to 2050. 130 years, which is tiny compared to 1920 years!)Alberth wrote:... YearMonthDay ...
[My real goal is to rewrite the timekeeping code in order to implement economy changes (with the side effect that seasons, day-night cycles and so on are also solved at the same time).]
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Date in date_type.h
OpenTTD allows to start the game on 1st January 0 (or 1?) and counts years up to 5000000. Thus you can play a game for 5 million years. Quite a bit more than the assumd 130 years.LurkerL wrote:Wasted time from 0 to 1920, and we only use 1920 to 2050. 130 years, which is tiny compared to 1920 years!)
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Date in date_type.h
1.
Perhaps I should just show what I want.
Original (for those who don't have the source right this moment)
My try
(TimeDate::Date date(int year, int month, int day) deals with dates input in the "conventional" Gregorian way, e.g. date(1952, 02, 29) or date(1966, 01, 01) and so on.)
Where the "?" is I have no idea what to put in... (The latest I'm on is day-2*(!TimeDate::YearIsLeap(year)), which gives the correct date on leap years, but adds 2 days all other years).
2.

Perhaps I should just show what I want.
Original (for those who don't have the source right this moment)
Code: Select all
ConvertYMDToDate(Year year, Month month, Day day)
{
int days = _accum_days_for_month[month] + day - 1;
if (!IsLeapYear(year) && days >= ACCUM_MAR) days--;
return DAYS_TILL(year) + days;
}
Code: Select all
ConvertYMDToDate(Year year, Month month, Day day)
{
TimeDate::Date date(year, month+1, ?);
return DAYS_TILL(year) + date.DayOfYear();
}
Where the "?" is I have no idea what to put in... (The latest I'm on is day-2*(!TimeDate::YearIsLeap(year)), which gives the correct date on leap years, but adds 2 days all other years).
2.
Yes, my badplanetmaker wrote:... OpenTTD allows to start the game on 1st January 0 (or 1?) and counts years up to 5000000. Thus you can play a game for 5 million years. Quite a bit more than the assumd 130 years.

Re: Date in date_type.h
The source code is leading. Doxygen docs have been added much later without full knowledge of the details.LurkerL wrote:Actually that was the reason why I asked the question in the first place! That particular function has a funny way of dealing with leap years to my eyes. ...Alberth wrote:... YearMonthDay ...
If you find new information, and supply a doxygen patch, we are happy to add it.
Re: Date in date_type.h
I think I shouldn't have been so blunt in my first post---it wasn't my intention to say bad things about the docs or the code, or to say I wasn't playing with the code to figure it out myself.Alberth wrote:The source code is leading. Doxygen docs have been added much later without full knowledge of the details.LurkerL wrote:Actually that was the reason why I asked the question in the first place! That particular function has a funny way of dealing with leap years to my eyes. ...Alberth wrote:... YearMonthDay ...
If you find new information, and supply a doxygen patch, we are happy to add it.
Re: Date in date_type.h
it used to be that way that days were counted from 1920-01-01, with a 16 bit counter, which allowed dates up to 2090-12-31. this was not enough for some people, so 32 bit date was introduced, starting in 0000-01-01 and ending in 5000000-12-31. [this is a normalised gregorian calendar with year 0]LurkerL wrote:Wasted time from 0 to 1920, and we only use 1920 to 2050. 130 years, which is tiny compared to 1920 years!
leap years occur every 4 years, but every 100 years one is skipped, and every 400 years an additional one is added
Re: Date in date_type.h
Thanks for the help, it's been figured out now. "Leap year offset" in ConvertYMDToDate was giving me the trouble: the day ordinal ("Date type") is shifted by 1 day.
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest