Python – Writing a ‘Fuzzy Clock’

If you want a clock that’s a little more human, there’s no better way than a ‘Fuzzy’ clock, essentially this converts the time in to a more brain friendly format such as “Twenty past Twelve” rather than 12:22.

Writing a simple fuzzy clock
Source Code:

[gist][/gist]

Output:

$ python fuzzytime.py
It’s 25 to 2

Writing a more readable fuzzy clock:

Now, this returns in a form of “It’s 20 past 1” rather than “It’s twenty past one”, if you’re going to want this then it’s only a little more tricky. For this I used a lookup table which would essentially replace the numbers for the written numbers.

Source Code:

[gist][/gist]

Output:

$ python fuzzytime.py
It’s two o’clock

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>