## Copyright (C) 1998-99 Klaus Alexander Seistrup @ Magnetic Ink, Copenhagen, DK. ## ## QTime -- Display time as English sentence. ## ## Author : 1998 Klaus Alexander Seistrup ## History : 1999/07/16 gotoken ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the Free ## Software Foundation; either version 2 of the License, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but with- ## out any warranty; without even the implied warranty of merchantability or ## fitness for a particular purpose. See the GNU General Public License for ## more details. ## ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. module QTime HR = %w( twelve one two three four five six seven eight nine ten eleven ) MN = [ nil, "five", "ten", "a quarter", "twenty", "twenty-five", "half" ] NY = [ "nearly", "almost", nil, "just after", "after" ] UP = [ "to", nil, "past" ] OC = { 0 => "o'clock" } def secs_since_midnight ( now = Time.now ) ( now - Time.local( now.year, now.month, now.day ) ).to_i end def qt(time = Time.now) adj_mins = (secs_since_midnight ( time ) + 30) / 60 + 27 hours = (adj_mins / 60) % 12 minutes = adj_mins % 60 almost = minutes % 5 divisions = (minutes / 5) - 5 to_past_idx = 1 + (divisions <=> 0) format "It's %s.", [ NY[almost], MN[divisions.abs], UP[to_past_idx], HR[hours], OC[divisions] ].compact.join(" ") end def qtime(time = Time.now) print (qt ( time ), "\n") end module_function :secs_since_midnight, :qt, :qtime end if __FILE__ == $0 puts QTime::qt () end