Python Forum
Calling the function to change the times
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling the function to change the times
#1
Hi all,
I'm calling the EPG_Times function to set up the datetime date for the self.epg_time_1, self.epg_time_2 and self.epg_time_3 to stored the time and date in the list in each time when I'm calling the EPG_Times function. I'm also used the self.program_day to store the value in the list, example: 0, 1, 2, 3..etc until to 6 for 7 days. When I'm calling the EPG_Times, it will show the time with the date like this:
    self.epg_time_1
    ['28/08/2017 11:30PM']
    self.epg_time_2
    ['29/08/2017 12:00AM']
    self.epg_time_3
    ['29/08/2017 12:30AM']
So when I'm calling the EPG_Times function again, it will show the output like this:
    self.epg_time_1
    ['29/08/2017 11:00PM']
    self.epg_time_2
    ['29/08/2017 11:30PM']
    self.epg_time_3
    ['29/08/2017 12:00AM']
I have changed from days = self.program_day + 1 to days = self.program_day - 1, but when the strings show 11:00PM, 11:30PM and 12:00AM from the variables epg_time_1, epg_time_2 and epg_time_3, it will show the contains like this:
    self.epg_time_1
    ['27/08/2017 11:00PM']
    self.epg_time_2
    ['27/08/2017 11:30PM']
    self.epg_time_3
    ['27/08/2017 12:00AM']
Here is what I'm expected to contain:
    self.epg_time_1
    ['28/08/2017 11:00PM']
    self.epg_time_2
    ['28/08/2017 11:30PM']
    self.epg_time_3
    ['29/08/2017 12:00AM']
Then calling again.......
    self.epg_time_1
    ['28/08/2017 10:30PM']
    self.epg_time_2
    ['28/08/2017 11:00PM']
    self.epg_time_3
    ['28/08/2017 11:30AM']
until to....
    self.epg_time_1
    ['27/08/2017 10:30PM']
    self.epg_time_2
    ['27/08/2017 11:00PM']
    self.epg_time_3
    ['27/08/2017 11:30AM']
and so on....


Here is the code:

    self.program_day = list()

    def EPG_Times(self):
         self.epg_time_1 = list()
         self.epg_time_2 = list()
         self.epg_time_3 = list()
         epg_time1 = str(self.getControl(344).getLabel())
         epg_time2 = str(self.getControl(345).getLabel())
         epg_time3 = str(self.getControl(346).getLabel())
         day_date = self.program_day
         day = ''
         month = ''
         year = ''
         print "you are calling EPG_Times..........................."
         print day_date
    
    
         if day_date >= 0 and day_date <= 6:
             print "EPG PASSED 1..................................."
             print epg_time2
             if epg_time3 == '12:00AM':
                 print "EPG PASSED 2..................................."
    
                 if day_date == 0:
                     print "EPG PASSED 3..................................."
                     if epg_time1 == '12:00AM':
                         print "EPG PASSED 4..................................."
                         epg_time_1 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
                         epg_time_2 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
                         epg_time_3 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
                     else:
                         print "EPG PASSED 5..................................."
                         epg_time_1 = datetime.datetime.now() + datetime.timedelta(days = self.program_day)
                         epg_time_2 = datetime.datetime.now() + datetime.timedelta(days = self.program_day)
                         epg_time_3 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
    
                 else:
                     print "EPG PASSED 6..................................."
                      
                     currentday = datetime.datetime.now() + datetime.timedelta(days = 0)
                     nextday = datetime.datetime.now() + datetime.timedelta(days = self.program_day)
    
                     if currentday != nextday:
                         print "you can now add the epg_time_2 and epg_time_3 next day date"
                         epg_time_1 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
                         epg_time_2 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
                         epg_time_3 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
                     elif currentday == nextday:
                         print "you can now add the epg_time_1, epg_time_2 and epg_time_3 next day date"
                         epg_time_1 = datetime.datetime.now() + datetime.timedelta(days = self.program_day)
                         epg_time_2 = datetime.datetime.now() + datetime.timedelta(days = self.program_day - 1)
                         epg_time_3 = datetime.datetime.now() + datetime.timedelta(days = self.program_day - 1)


                  epg1_day = epg_time_1.strftime("%d")
                  epg1_month = epg_time_1.strftime("%m")
                  epg1_year = epg_time_1.strftime("%Y")
                  epg2_day = epg_time_2.strftime("%d")
                  epg2_month = epg_time_2.strftime("%m")
                  epg2_year = epg_time_2.strftime("%Y")
                  epg3_day = epg_time_2.strftime("%d")
                  epg3_month = epg_time_2.strftime("%m")
                  epg3_year = epg_time_2.strftime("%Y")
                  half_hour = str(epg1_day + "/" + epg1_month + "/" + epg1_year + " " + epg_time1)
                  one_hour = str(epg2_day + "/" + epg2_month + "/" + epg2_year + " " + epg_time2)
                  one_hour_half = str(epg3_day + "/" + epg3_month + "/" + epg3_year + " " + epg_time3)
    
    
             #Store the times in the list....
             self.epg_time_1.append(half_hour)
             self.epg_time_2.append(one_hour)
             self.epg_time_3.append(one_hour_half)
I need to use the if statement to see if the time is valid so I can control on the date whether if I need to add it to the previous day date or add it to the next day date if the time show 12:00AM or whatever it is.

What I'm expected the code to do is to change to the previous day date when the epg_time_1 and epg_time_2 show the strings 11:00PM and 11:30PM. If the epg_time_3 show the string 12:00AM then I want to add it to the next day date. If the epg_time_1 and epg_time_2 show the strings 11:30PM and 12:00AM, I want to change to the previous date for epg_time_1 and add it to the next day date for the epg_time_2, because the time 12:00AM is the next day and the time 11:30PM is the previous day. 


Can you please show me an example how I could do that on my code in each time when I'm calling on the EPG_Times function?
Reply
#2
This post is really hard to follow. Can you reproduce your problem with 5-10 lines of runnable code and post that for us?
Reply
#3
(Aug-28-2017, 04:59 PM)micseydel Wrote: This post is really hard to follow. Can you reproduce your problem with 5-10 lines of runnable code and post that for us?

Ok, here it is:

if day_date >= 0 and day_date <= 6:
   if epg_time3 == '12:00AM':
     
      if day_date == 0:
        if epg_time1 == '12:00AM':
           .......
      else:
        currentday = datetime.datetime.now() + datetime.timedelta(days = 0)
        nextday = datetime.datetime.now() + datetime.timedelta(days = self.program_day)
     
        if currentday != nextday:
           epg_time_1 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
           epg_time_2 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
           epg_time_3 = datetime.datetime.now() + datetime.timedelta(days = self.program_day + 1)
        elif currentday == nextday:
           epg_time_1 = datetime.datetime.now() + datetime.timedelta(days = self.program_day)
           epg_time_2 = datetime.datetime.now() + datetime.timedelta(days = self.program_day - 1)
           epg_time_3 = datetime.datetime.now() + datetime.timedelta(days = self.program_day - 1)
Do you know how I can change to the previous day when the epg_time_1 and epg_time_2 show the strings 11:00PM and 11:30PM as put the epg_time_3 to the next day date when the time show 12:00AM??

And also if the epg_time_1 and epg_time_2 show the strings 11:30PM and 12:00AM, I want to change to the previous date for epg_time_1 and add it to the next day date for the epg_time_2. How I can do that with my code?
Reply
#4
you should take a look at: https://docs.python.org/3.6/library/date....timedelta
You'll find a lot of useful information on date manipulation
also: https://pymotw.com/3/datetime/
and one of my favorites: http://pleac.sourceforge.net/pleac_pytho...times.html
Reply
#5
(Aug-28-2017, 10:33 PM)Larz60+ Wrote: you should take a look at: https://docs.python.org/3.6/library/date....timedelta
You'll find a lot of useful information on date manipulation
also: https://pymotw.com/3/datetime/
and one of my favorites: http://pleac.sourceforge.net/pleac_pytho...times.html

I have already take a look, but you need to READ MY CODE and help me to fix the issues to allow me to control on the datetime to set the day date to the previous day before 12AM.
Reply
#6
which packages are you importing?
You need to supply enough of a code snippet to be run.
Reply
#7
(Aug-29-2017, 06:57 PM)Larz60+ Wrote: which packages are you importing?
You need to supply enough of a code snippet to be run.

what you mean which packages?

I use time and datetime.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  calling external function with arguments Wimpy_Wellington 7 1,446 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 823 Jun-07-2023, 08:55 PM
Last Post: deanhystad
Sad Iterate randint() multiple times when calling a function Jake123 2 2,057 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Calling a class from a function jc4d 5 1,824 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  write new function or change the old one to work "smartter? korenron 3 1,977 Aug-09-2021, 10:36 AM
Last Post: jamesaarr
  [Solved] TypeError when calling function Laplace12 2 2,892 Jun-16-2021, 02:46 PM
Last Post: Laplace12
  calling a function and argument in an input phillup7 3 2,618 Oct-25-2020, 02:12 PM
Last Post: jefsummers
  Use of input function to change screen background color in Turtles Oldman45 3 4,899 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 2,250 Apr-06-2020, 09:14 AM
Last Post: bowlofred
  Calling DLL function OptoBruh 0 1,595 Nov-15-2019, 11:51 PM
Last Post: OptoBruh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020