2 * qtime - Display time as English sentence
4 * Copyright (C) 1999 Klaus Alexander Seistrup and Landon Curt Noll
6 * Written by: Klaus Alexander Seistrup <kseis@magnetic-ink.dk>
7 * With mods by: Landon Curt Noll <http://www.isthe.com/chongo/>
9 * Calc is open software; you can redistribute it and/or modify it under
10 * the terms of the version 2.1 of the GNU Lesser General Public License
11 * as published by the Free Software Foundation.
13 * Calc is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
16 * Public License for more details.
18 * A copy of version 2.1 of the GNU Lesser General Public License is
19 * distributed with calc under the filename COPYING-LGPL. You should have
20 * received a copy with calc; if not, write to Free Software Foundation, Inc.
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * @(#) $Revision: 30.1 $
24 * @(#) $Id: qtime.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
25 * @(#) $Source: /usr/local/src/bin/calc/cal/RCS/qtime.cal,v $
27 * Under source code control: 1999/10/13 04:10:33
28 * File existed as early as: 1999
30 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
31 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
36 * qtime(utc_hr_offset)
38 * utc_hr_offset Offset from UTC in hours.
41 * http://www.magnetic-ink.dk/download/qtime.html
43 * for examples of qtime() written on other languages.
48 * qtime - Display time as English sentence
50 define qtime(utc_hr_offset)
53 "twelve", "one", "two", "three", "four", "five",
54 "six", "seven", "eight", "nine", "ten", "eleven"
57 "", "five ", "ten ", "a quarter ", "twenty ", "twenty-five ", "half "
60 "nearly ", "almost ", "", "just after ", "after "
65 local adj_mins = (((time() + utc_hr_offset*3600) % 86400) + 30)//60+27;
66 local hours = (adj_mins // 60) % 12;
67 local minutes = adj_mins % 60;
68 local almost = minutes % 5;
69 local divisions = (minutes // 5) - 5;
70 local to_past_idx = divisions > 0 ? 1 : 0;
73 divisions = -divisions;
79 * Print the English sentence
81 * We avoid forward and back quotes just to show that the char()
82 * builtin function can be used in conjunction with a printf.
84 printf("It%cs %s%s%s%s",
85 char(0x27), ny[almost], mn[divisions],
86 up[to_past_idx], hr[hours]);
88 printf(" o%cclock", char(0x27));