Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't get the time to increment in hours

Beginner and first time asker here! I’ve run into a problem with my first project.

I’m trying to write a class method that adds an hour on to the current time for every 180 within a big number.

I’m only testing a basic version at the moment, but I cant get it to work, the hour stays the same despite incrementing the hour variable.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(e.g. if the time now was 1:00pm and the user typed 540 cases, it would return:

“360 should be remaining at: 2:00pm”
“180 should be remaining at
3:00pm” “0 should be remaining at 4:00pm”

What it actually does is:

“360 should be remaining at: 2:00pm”
“180 should be remaining at 2:00pm”
“0 should be remaining at 2:00pm”

def hourly_time_formula(self):

        
        c = self.cases

        hour = 1 
        nextHour = datetime.now() + timedelta(hours = hour) 
        neat_time = nextHour.strftime("%H:%M:%S")
        

        if c > 180:
            while c >= 180:
                ihour += 1    
                c -= 180
                print(f"{c - 180} should be remaining at {neat_time}") 

Thanks in advance!

>Solution :

You’re not updating the neat_time variable. This is what you likely want:

def hourly_time_formula(self):
    c = self.cases

    hour = 0

    if c > 180:
        while c >= 180:
            hour += 1    
            c -= 180
            nextHour = datetime.now() + timedelta(hours = hour) 
            neat_time = nextHour.strftime("%H:%M:%S")

            print(f"{c - 180} should be remaining at {neat_time}") 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading