SA-MP Forums Archive
Get Time - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get Time (/showthread.php?tid=664484)



Get Time - Longover - 02.03.2019

Problem: i want the hour:minute for my location,not for my host.
In my location si now: 11:03
And on my host location is: 04:03



Code for /time command:

Код:
new hour,minute,second;
	gettime(hour,minute,second);
	format(string, sizeof(string), "Acum e ora %d:%s%d si %d secunde.", hour, (minute < 10) ? ("0") : (""), minute, second);



Re: Get Time - Longover - 02.03.2019

Quote:
Originally Posted by Longover
Посмотреть сообщение
Problem: i want the hour:minute for my location,not for my host.
In my location si now: 11:03
And on my host location is: 04:03



Code for /time command:

Код:
new hour,minute,second;
	gettime(hour,minute,second);
	format(string, sizeof(string), "Acum e ora %d:%s%d si %d secunde.", hour, (minute < 10) ? ("0") : (""), minute, second);
BUMP


Re: Get Time - Longover - 02.03.2019

BUMP


Re: Get Time - Jeffry - 02.03.2019

Use this Include: https://sampforum.blast.hk/showthread.php?tid=347605
For the Timestamp use the return value of gettime().

And DO NOT Bump within a few minutes!


Re: Get Time - Longover - 02.03.2019

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Use this Include: https://sampforum.blast.hk/showthread.php?tid=347605
For the Timestamp use the return value of gettime().

And DO NOT Bump within a few minutes!
It Doesen't work.


Re: Get Time - Jeffry - 02.03.2019

Please post your code and explain what's not working.


Re: Get Time - Longover - 02.03.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
You need to enter your timezone somewhere, say in a command, then add that offset to the hour returned by gettime.
CMD:time(playerid, params[])
{
if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "Trebuie sa te loghezi inainte de a face asta.");
if(PlayerInfo[playerid][pSleeping] == 1) return 1;
new sendername[25],string[256];
new hour,minute,second;
gettime(hour,minute,second);
format(string, sizeof(string), "Acum e ora %d:%s%d si %d secunde.", hour, (minute < 10) ? ("0") : (""), minute, second);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Ai jucat %d secunde din aceasta ora.", PlayerInfo[playerid][pPayDay]);
SendClientMessage(playerid, COLOR_WHITE, string);
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s isi da maneca la o parte si se uita la ceas.", sendername);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPL E,COLOR_PURPLE);
if(!IsPlayerInAnyVehicle(playerid)) ApplyAnimation(playerid,"COP_AMBIENT","Coplook_wat ch",4.1,0,0,0,0,0);
return 1;
}


Re: Get Time - Jeffry - 02.03.2019

You are not even using get TimestampToDate function here. Use it, otherwise it can't work, obviously.


Re: Get Time - Longover - 02.03.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
Nothing in that code adjusts your timezone.
hmm,if i put:

hours + (a number to ajust the time)

and

minutes + (a number to ajust the time)


Re: Get Time - Jeffry - 02.03.2019

The code is supposed to be like this:

Код:
new y, m, d, hour, minute, second;
TimestampToDate(gettime(), y, m, d, hour, minute, second, -6);



Re: Get Time - Jeffry - 02.03.2019

Y_Less, I have been using this function for many many years and apart from the little fix posted by me on the last page of the thread, there were no issues, ever. It will handle the case of Longover very well, there is no need for a plugin here.


Re: Get Time - Jeffry - 03.03.2019

Yes, there has been a leap second. This can also be considered, by leaving out a second if the Timestamp is greater than the time when it was added. The function can easily be adjusted for this, if needed in his case at all.

This function can handle all kinds of time offsets, simply add a command for a player to adjust his own time zone and reduce or increase the gettime() return value with the offset, before calling TimestampToDate, that's the way I used it, it worked perfectly for all areas of the world. This way daylight savings were taken into consideration too.

The video is pointless to me, because from my practical experience, I can tell, that there is no need for a plugin. It's been running for years and never had an issue apart from the reported one.
I try to prevent suggesting Plugins if not needed, because Plugins are pretty much a black box and you can never modify them easily. Once the creator stops supporting it or even deletes the Plugin, you can easily run into bigger problems, due to the Plugin not being updated anymore.

I, personally, wouldn't go with a plugin here. If you'd do, that's fine with me. I still wouldn't, since the simple function can handle all of the requirements too.


Re: Get Time - Jeffry - 03.03.2019

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
So you think repeatedly modifying code until it fixes all bugs and corner-cases is better than just using existing code that works?
What kind of bugs are in there? Could you please state a specific example, apart from what has already been stated and can easily be fixed since the solution is already present?


Quote:
Originally Posted by Y_Less
Посмотреть сообщение
That’s not a good solution. If you have to have additional code before calling a function to ensure that the function works correctly, the function is no longer self-contained. This is called a “leaky abstraction”, and is where your code is directly tied to the internals of a function. If you call the function five times, you have to ensure all the other code is right five times. If there’s a bug you have to fix it five times, and hope you didn’t forget a sixth.
Obviously this would be done in a separate function, which is then calling the TimestampToDate.
For example:
Код:
stock TimestampToDateForPlayer(playerid, Timestamp, &year, &month, &day, &hour, &minute, &second)
{
	return TimestampToDate(Timestamp + tOffset[playerid][0]*3600 + tOffset[playerid][1]*60 + tOffset[playerid][2], year, month, day, hour, minute, second, 0);
}
No need to fix anything in multiple instances.
Additionally, this has nothing to do with leaky abstraction, it's simply making use of a personalizable function.
Furthermore, you'd need this in combination with the Chrono Plugin too.


Quote:
Originally Posted by Y_Less
Посмотреть сообщение
What’s that got to do with the video? Just because you’ve never hit the bugs that are provably there doesn’t mean they don’t exist and won’t be hit by other people.
As stated in the first paragraph, could you please provide a practical example, where the function runs into a bug, excluding the issues already stated where the solution is already present?
If not, I do not see a reason why calling this function bugged.


Quote:
Originally Posted by Y_Less
Посмотреть сообщение
All plugins are required to release their source. They are no more a black-box than includes, and faster. You might not like plugins, and that’s up to you, but don’t inflict your ignorance on others but preventing them being suggested better code.
That's true, but nevertheless, modifying a plugin is way more complex than modifying a PAWN code, that's why I said "pretty much". You can have a look into the code, but modifying it for your needs is nothing everybody can or will do.

Actually, I do not even see the point of a discussion here. If I haven't had issues over half a decade with the function, I'm right to say the function works well for most requirements and most likely it fulfills Longover's requirements too. If not, he can use the plugin. It has nothing to do with ignorance, it's a simple suggestion based on my opinion and my experiences.


Re: Get Time - masuzaron - 03.03.2019

gettime returns time of the machine (server) on which your server is hosted, so you can't change it.
The only thing you can do is to contact your hosting provider and ask them to change timezone for your server.