Follow

ya know this might not be the prettiest code i've ever written

but god damn every time i use this fuckin function it makes me dumbass happy because it just fuckin works after tons of patching little issues with it until it's seemingly perfect now

p.szy.io/fuvIwQ/python

takes a floating point number of hours and converts it to something nice like "3 hours 12 minutes" if short_format is True, and could be something like "3 hours 12 minutes 33 seconds" or something if short_format is False

Oh also this was originally written for thingworx where I don't have the luxury of such things as "external libraries"

@mdszy looks perfectly reasonable to me on first glance. i love using the python datetime stuff =)

@mdszy yeah, understandable. honestly, if this were a code review the first bits i would comment on are the final_string stuff, i think you could get some mileage out of the f-strings in python 3. (assuming you are using 3)

python.org/dev/peps/pep-0498/

@elmiko i would use f-strings, but the environment this is running on is using jython 2.7, and that isn't going to change any time soon unfortunately

@mdszy ouch...

in that case i might look more at using the string.format functionality, you can do a lot of composition with it and, imo, it's easier on the eyes.

Sign in to participate in the conversation
Mastodon for Tech Folks

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!