Posted By

Pjotor on 12/01/09


Tagged

text clock verbose fuzzy


Versions (?)

Fuzzy Clock


 / Published in: JavaScript
 

A short compact fuzzy clock script. Fuzzes a supplied date object or returns current time fuzzy.

  1. function fuzz(d){ d=(d)?d:new Date();
  2. var t = [, "it's", "right after", "about", "o'clock", "quarter", "to", "past", "half", "sharp", "a"],
  3. h=["twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"],
  4. m=[0,d.getMinutes(),d.getHours()],s=[]; m[0]=m[1]%7.5; s[0]=t[1];
  5. s.push( (m[0]==0)? t[0]:(m[0]==parseInt(m[0]))?t[2]:t[3]);
  6. s.push( (m[1]>53)? [h[(m[2]+1)%12], t[4] ] :
  7. (m[1]>37)? [t[10],t[5],t[6], h[(m[2]+1)%12] ] :
  8. (m[1]>23)? [t[8], h[m[2]%12] ] :
  9. (m[1]>7 )? [t[10],t[5],t[7], h[m[2]%12] ] :
  10. (m[1]>0 )? [h[m[2]%12], t[4] ] :
  11. [h[m[2]%12],t[4], t[9] ]);
  12. return s.toString().replace(/,/gi," "); }

Report this snippet  

You need to login to post a comment.