GetDate() doesn't give millisecs()?

Monkey Forums/Monkey Beginners/GetDate() doesn't give millisecs()?

Xyle(Posted 2015) [#1]
I've been messing around with some random numbers and noticed my seed was the same sometimes. So I checked out the GetDate() function more and noticed that the 6th member of the array from GetDate(), which is supposed to be millisecs, always returns zero.

Local date:Int[] = GetDate()
Print "Actual Date: " +date[0]+ ", " +date[1]+ "," +date[2]+ ", " +date[3]+ ", " +date[4]+ ", " +date[5] + ", " +date[6]


I looked through the forums but couldn't find anything on it.

Thanks for any help!


ImmutableOctet(SKNG)(Posted 2015) [#2]
Couldn't you just use 'Millisecs', anyway?


impixi(Posted 2015) [#3]
I've noticed this too. There should be a note in the docs stating that GetDate() doesn't return the correct milliseconds value on some targets (GLFW and C++ tool, at least). The relevant code is in modules/brl/native/gametarget.cpp

...
void BBGame::GetDate( Array<int> date ){
	int n=date.Length();
	if( n>0 ){
		time_t t=time( 0 );
		
#if _MSC_VER
		struct tm tii;
		struct tm *ti=&tii;
		localtime_s( ti,&t );
#else
		struct tm *ti=localtime( &t );
#endif

		date[0]=ti->tm_year+1900;
		if( n>1 ){ 
			date[1]=ti->tm_mon+1;
			if( n>2 ){
				date[2]=ti->tm_mday;
				if( n>3 ){
					date[3]=ti->tm_hour;
					if( n>4 ){
						date[4]=ti->tm_min;
						if( n>5 ){
							date[5]=ti->tm_sec;
							if( n>6 ){
								date[6]=0;
							}
						}
					}
				}
			}
		}
	}
}
...


As you can see, the array element corresponding to the milliseconds data is always set to zero. You could modify it to use the clock() function, however, that's based on the system-dependent CLOCKS_PER_SEC macro and doesn't necessarily return milliseconds (though perhaps it would be better than zero?).

There is a c++ "std::chrono" library... Unfortunately that's a C++11 feature and Monkey hasn't gone in that direction yet...


StoneFaceEXE(Posted 2015) [#4]
I don't know, everything works fine for me (HTML5 target at least)


StoneFaceEXE(Posted 2015) [#5]
Couldn't you just use 'Millisecs', anyway?

Millisecs() returns the ammount of milliseconds that have passed since the moment your app started. Millisecs from GetDate() are actually Milliseconds of current time (so it returns from 0 to 999 like a full second)


Xyle(Posted 2015) [#6]
lol, thanks for the info!
Doing a more, better, face stuck on the monitor search...

http://www.monkey-x.com/Community/posts.php?topic=8349&post=84852&view=all#84852
"Posted 9 months ago #9
Ferdi
Just a warning in GLFW the millisecs part is not working in GetDate. It works in HTML5."

and a year ago...
http://www.monkey-x.com/Community/posts.php?topic=7762&post=75760&view=all#75760


impixi(Posted 2015) [#7]
LOL. I should have done a forum search myself; would have saved myself an hour or so of research...

In any case, it's an issue that manifests from time to time - it really should be fixed/documented.