HOME | DD

photofroggy — function time_length by-nc-sa

Published: 2007-09-12 20:22:36 +0000 UTC; Views: 1035; Favourites: 0; Downloads: 51
Redirect to original
Description This function is something I needed as I required a way to convert a time-span, in seconds, into a representative string. I also wanted something that produced a gramatically correct string. This was not going to be the easiest function to make, but I cracked at it and came out with this result, and works fine with positive values. The edit I have on my computer can handle negative values.

Sorting out the different numeric values to be used in the string was easy enough, but figuring out the code to sort the numbers into a grammatically accurate string was difficult. I wanted the function to be short and tidy, so I decided to use the ternary operator, and as a result created some amazingly long lines.

The section of code which works out the string is by far the longest part of the function, and the was the most difficult to create. It was tested and edited many times, to make sure that absolutely every possible variation worked! Thankfully, it works, and I made it into a generic function so that it can be used anywhere.

Thanks for reading.
Related content
Comments: 8

JohnJensen [2007-12-06 14:33:39 +0000 UTC]

You rule.

👍: 0 ⏩: 1

photofroggy In reply to JohnJensen [2007-12-06 19:28:31 +0000 UTC]

There are far better examples of code than the one shown here

👍: 0 ⏩: 1

JohnJensen In reply to photofroggy [2007-12-07 11:02:10 +0000 UTC]

I know XD

👍: 0 ⏩: 0

black-doll-army [2007-10-08 21:32:53 +0000 UTC]

uhm, adorable and lovely! (i don't get it, but anyway, i love small ants in your work)

👍: 0 ⏩: 1

photofroggy In reply to black-doll-army [2007-10-08 22:39:13 +0000 UTC]

ants? Where? lol

👍: 0 ⏩: 1

black-doll-army In reply to photofroggy [2007-10-09 04:44:23 +0000 UTC]

lol, everywhere-> , . etc

👍: 0 ⏩: 1

photofroggy In reply to black-doll-army [2007-10-09 06:59:39 +0000 UTC]

commas and full-stops?

👍: 0 ⏩: 1

black-doll-army In reply to photofroggy [2007-10-09 13:15:56 +0000 UTC]

yea you're the man!

👍: 0 ⏩: 0