formatted 'time' data in calculations

Aaron Hill ahill21programming at gmail.com
Wed Jan 7 14:41:58 EST 2009


I personally use epoch time since its absolute. I have a simple time clock
app that uses this method, from that it is easy to convert into human date:


[code]

def OnButtonIn(self,evt):

        'create time stamp with ID/action'

        'print to the rightFrame text'

        if self.punchedIn:

            print "Already punched in cannot punch again"

        else:

            seconds = time.time()

            current = time.localtime(seconds)

            day = time.localtime()

            # time string can have characters 0..9, -, period, or space

            timeday = time.strftime('%H:%M-%m.%d.%y', day)

            formatday = time.strftime('%c', day)

            self.ClockIntext = seconds

            #self.text =  "Clock in: " + self.text

            self.punchIn.SetValue(formatday)

            self.punchedIn = True

            self.punchedOut = False



    def OnButtonOut(self,evt):

        if self.punchedOut:

            print "Already punched out!"

        else:

            'create time stamp with ID/action'

            'print to the rightFrame text'

            'write to time sheet'

            seconds = time.time()

            current = time.localtime(seconds)

            day = time.localtime()

            # time string can have characters 0..9, -, period, or space

            timeday = time.strftime('%H:%M-%m.%d.%y', day)

            formatday = time.strftime('%c', day)

            self.ClockOuttext = seconds

            self.punchOut.SetValue(formatday)

            self.punchedIn = False

            self.punchedOut = True

            'create a file and write the table to it'

            file = open('timesheet.txt', 'a')

            file.write(str(self.ClockIntext))

            file.write('\t')

            file.write(str(self.ClockOuttext))

            file.write('\n')

            file.close()

        return None



    def OnButtonCalc(self,event):

        'open the time sheet and calculate the total time'

        file = open('timesheet.txt','r')

        lines = file.readlines()

        time1 = ''

        time2 = ''

        self.hours = 0.000

        for punch in lines:

            for x in punch:

                if(len(x) <= 0):

                    self.hours = self.hours

                else:

                    if x != '\t' and x!= '\n':

                        time1 = time1 + x

                    elif x == '\t':

                        time2 = time1

                        time1 = ''

                    elif x == '\n':

                        self.hours = self.hours +
abs(((float(time2)-float(time1))/60)/60)

                        time2 = ''

                        time1 = ''



        self.total.SetValue('%2f' % self.hours)
[/code]

Oops wrong person, sorry about that. This time it should go to the mailing
list



Aaron Hill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090107/5e697576/attachment-0001.html>


More information about the Python-list mailing list