Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-120121-

python code

Name: what could this be for? 2009-12-06 22:04

self.hours = 1 + (self.hours - 1) % 12

Name: Anonymous 2009-12-06 22:17

Converting 24 hour notation to 12 hour notation?

Name: Anonymous 2009-12-06 22:20

Yes, but why the -1 +1 business.

Name: Anonymous 2009-12-06 22:22

Because time was written in Lua.

Name: Anonymous 2009-12-06 22:25

>>3
24 % 12 = 0

(24 - 1) % 12 = 11 + 1 = 12 like it is supposed to.

Name: Anonymous 2009-12-06 22:26

>>5
(24 - 1) % 12 = 11
11 + 1 = 12
Just to clarify.

Name: thanks! I'm dumb... 2009-12-06 22:27

:3

Name: Anonymous 2009-12-06 22:27

clever

Name: Anonymous 2009-12-06 22:32

Obviously written by a moran.  It evaluates to:

self.hours = self.hours % 12

Which sets self.hours to a value from 0..11 depending on the remainder after dividing it by 12.  I can't see any surrounding code, but I guess it could be used when you have a number of hours representing 24-hour time and you just wanted to know which hour /12 that would be when using AM/PM instead of 24-hour time.

Name: Anonymous 2009-12-06 22:38

>>9
% has higher precedence that +, so you are wrong.  It doesn't simplify to that, and it sets hours to 1-12

Name: Anonymous 2009-12-06 22:39

>>9
moran

Name: Anonymous 2010-11-28 8:25

<

Name: Anonymous 2013-07-06 3:03

self.hours = self.hours % 12 or 12

Name: Anonymous 2013-07-06 4:20

>>9
>doesn't understand order of operations

Name: Anonymous 2013-07-06 9:09

>>158
He must be a lisp-idiot.

Don't change these.
Name: Email:
Entire Thread Thread List