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) | |||
734 | return 0; | 734 | return 0; |
735 | } | 735 | } |
736 | 736 | ||
737 | /* Say time duration/interval. Input is time in seconds, | ||
738 | say hours,minutes,seconds. */ | ||
739 | static int talk_time_unit(long secs, bool exact, bool enqueue) | ||
740 | { | ||
741 | int hours, mins; | ||
742 | if (!enqueue) | ||
743 | talk_shutup(); | ||
744 | if((hours = secs/3600)) { | ||
745 | secs %= 3600; | ||
746 | talk_value(hours, UNIT_HOUR, true); | ||
747 | } | ||
748 | if((mins = secs/60)) { | ||
749 | secs %= 60; | ||
750 | if(exact || !hours) | ||
751 | talk_value(mins, UNIT_MIN, true); | ||
752 | else talk_number(mins, true); /* don't say "minutes" */ | ||
753 | } | ||
754 | if((exact && secs) || (!hours && !mins)) | ||
755 | talk_value(secs, UNIT_SEC, true); | ||
756 | else if(!hours && secs) | ||
757 | talk_number(secs, true); | ||
758 | return 0; | ||
759 | } | ||
760 | |||
737 | /* singular/plural aware saying of a value */ | 761 | /* singular/plural aware saying of a value */ |
738 | int talk_value(long n, int unit, bool enqueue) | 762 | int talk_value(long n, int unit, bool enqueue) |
739 | { | 763 | { |
@@ -778,6 +802,10 @@ int talk_value(long n, int unit, bool enqueue) | |||
778 | return -1; | 802 | return -1; |
779 | #endif | 803 | #endif |
780 | 804 | ||
805 | /* special case for time duration */ | ||
806 | if (unit == UNIT_TIME || unit == UNIT_TIME_EXACT) | ||
807 | return talk_time_unit(n, unit == UNIT_TIME_EXACT, enqueue); | ||
808 | |||
781 | if (unit < 0 || unit >= UNIT_LAST) | 809 | if (unit < 0 || unit >= UNIT_LAST) |
782 | unit_id = -1; | 810 | unit_id = -1; |
783 | else | 811 | 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 { | |||
45 | UNIT_MB, /* Megabytes */ | 45 | UNIT_MB, /* Megabytes */ |
46 | UNIT_KBIT, /* kilobits per sec */ | 46 | UNIT_KBIT, /* kilobits per sec */ |
47 | UNIT_PM_TICK, /* peak meter units per tick */ | 47 | UNIT_PM_TICK, /* peak meter units per tick */ |
48 | UNIT_TIME_EXACT,/* time duration/interval in seconds, says hours,mins,secs*/ | ||
49 | UNIT_TIME, /* as above but less verbose */ | ||
48 | UNIT_LAST /* END MARKER */ | 50 | UNIT_LAST /* END MARKER */ |
49 | }; | 51 | }; |
50 | 52 | ||