Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] [Solved] Get Difference Between Time Period

 
  • 0 Vote(s) - 0 Average
Pawn [Solved] Get Difference Between Time Period
Radical
Offline

Burgershot Member
Posts: 148
Threads: 21
Joined: Dec 2020
Reputation: 16
#1
2021-05-18, 12:34 AM (This post was last modified: 2021-05-18, 08:54 AM by Radical.)
I have an function to get difference between time period.
But it has a little problem. If start_hour is the current hour and stop_hour is 24am, it does not accurately calculate the difference Between Time.

Code:
new start_hour, start_minute, start_second, hours, minutes, seconds;

gettime(start_hour, start_minute, start_second);
DifferenceBetweenTimePeriod(start_hour, 24, start_minute, 0, start_second, 0, hours, minutes, seconds);



function:
Code:
DifferenceBetweenTimePeriod(start_hour, stop_hour, start_minute, stop_minute, start_second, stop_second, &hours, &minutes, &seconds) {
    while (stop_second > start_second) {
        --start_minute;
        start_second += 60;
    }
    seconds = start_second - stop_second;
    while (stop_minute > start_minute) {
        --start_hour;
        start_minute += 60;
    }
    minutes = start_minute - stop_minute;
    hours = start_hour - stop_hour;
}

Is there a problem with the function?

Solved:

This is resolved if I put 24 in start_hour.
Code:
DifferenceBetweenTimePeriod(24, start_hour, start_minute, 0, start_second, 0, hours, minutes, seconds);
Markski
Offline

Burgershot Clerk

Posts: 127
Threads: 6
Joined: Apr 2019
Reputation: 5
Location: La Plata, Argentina
#2
2021-05-18, 01:45 AM
Hours in a day are counted from 0, there's no hour 24... that's 00. That function should never be receiving 24 as an hour in a normal scenario
Website
Radical
Offline

Burgershot Member
Posts: 148
Threads: 21
Joined: Dec 2020
Reputation: 16
#3
2021-05-18, 08:46 AM
(2021-05-18, 01:45 AM)Markski Wrote: Hours in a day are counted from 0, there's no hour 24... that's 00. That function should never be receiving 24 as an hour in a normal scenario

Yes you are right. But if for example start_hour is 3am and stop_hour is 0am, it returns:
02 Hours 00 Minutes 00 Seconds 

It should return 
21 Hours 00 Minutes 00 Seconds
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#4
2021-05-18, 12:03 PM
Use unix timestamps. If you ever have a question about time, they are the answer.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode