Changes

Jump to: navigation, search

Rchan sandbox

74 bytes added, 22:29, 2 November 2019
Part 3 - Another approach to perform operation on time objects
==Part 3 - Another approach to perform operation on time objects ==
In the previous parts, we recognise that the fact that a Time object is essentially a three-digit number in base 60. The '"second' " attribute is the "ones colume", the '"minute' " attribute is the "sixties column", and the hour attribute is the '"60 x 60' " column. This is why we have to carry over "second " to "minute " when the value of '"second' " exceeds 60, and we have to do the same for the "minute" attribute.
In this part, we are going to use a different approach to manage calculation on Time object. We know that there are 86400 (24 x 60 x 60) seconds in a day. It is relatively easy to convert a Time object in the form of hour:minute:second to be represent by a single into an integer value which represent the time in secondsfrom mid-night. It is equally straight forward to convert a integer number of seconds between 0 and 86399 into hour:minute:second format. Here are two functions: sec_to_time(seconds) and time_to_sec(time) that will which can do just that:<source lang="python">
...
...
1,760
edits

Navigation menu