diff options
-rw-r--r-- | apps/talk.c | 28 | ||||
-rw-r--r-- | apps/talk.h | 2 |
2 files changed, 30 insertions, 0 deletions
diff --git a/apps/talk.c b/apps/talk.c index 0c8fafbe59..a7baf4927a 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -734,6 +734,30 @@ int talk_number(long n, bool enqueue) return 0; } +/* Say time duration/interval. Input is time in seconds, + say hours,minutes,seconds. */ +static int talk_time_unit(long secs, bool exact, bool enqueue) +{ + int hours, mins; + if (!enqueue) + talk_shutup(); + if((hours = secs/3600)) { + secs %= 3600; + talk_value(hours, UNIT_HOUR, true); + } + if((mins = secs/60)) { + secs %= 60; + if(exact || !hours) + talk_value(mins, UNIT_MIN, true); + else talk_number(mins, true); /* don't say "minutes" */ + } + if((exact && secs) || (!hours && !mins)) + talk_value(secs, UNIT_SEC, true); + else if(!hours && secs) + talk_number(secs, true); + return 0; +} + /* singular/plural aware saying of a value */ int talk_value(long n, int unit, bool enqueue) { @@ -778,6 +802,10 @@ int talk_value(long n, int unit, bool enqueue) return -1; #endif + /* special case for time duration */ + if (unit == UNIT_TIME || unit == UNIT_TIME_EXACT) + return talk_time_unit(n, unit == UNIT_TIME_EXACT, enqueue); + if (unit < 0 || unit >= UNIT_LAST) unit_id = -1; else diff --git a/apps/talk.h b/apps/talk.h index 0dea8d6b18..bb05bd8321 100644 --- a/apps/talk.h +++ b/apps/talk.h @@ -45,6 +45,8 @@ enum { UNIT_MB, /* Megabytes */ UNIT_KBIT, /* kilobits per sec */ UNIT_PM_TICK, /* peak meter units per tick */ + UNIT_TIME_EXACT,/* time duration/interval in seconds, says hours,mins,secs*/ + UNIT_TIME, /* as above but less verbose */ UNIT_LAST /* END MARKER */ }; |