Skip to content
Snippets Groups Projects
say.c 181 KiB
Newer Older
  • Learn to ignore specific revisions
  • 		case 'H':
    		case 'k':
    			/* 24-Hour */
    			gr_say_number_female(tm.tm_hour, chan, ints, lang);
    			break;
    		case 'M':
    			/* Minute */
    			if (tm.tm_min) {
    				if (!res)
    					res = ast_streamfile(chan, "digits/kai", lang);
    				if (!res)
    					res = ast_waitstream(chan, ints);
    				if (!res)
    					res = ast_say_number_full_gr(chan, tm.tm_min, ints, lang, -1, -1);
    			} else {
    				if (!res)
    					res = ast_streamfile(chan, "digits/oclock", lang);
    				if (!res)
    					res = ast_waitstream(chan, ints);
    			}
    			break;
    		case 'P':
    		case 'p':
    			/* AM/PM */
    			if (tm.tm_hour > 11)
    				snprintf(nextmsg,sizeof(nextmsg), "digits/p-m");
    			else
    				snprintf(nextmsg,sizeof(nextmsg), "digits/a-m");
    			res = wait_file(chan,ints,nextmsg,lang);
    			break;
    		case 'Q':
    			/* Shorthand for "Today", "Yesterday", or ABdY */
    			{
    				struct timeval now;
    				struct tm tmnow;
    				time_t beg_today;
    				
    				gettimeofday(&now,NULL);
    				ast_localtime(&now.tv_sec,&tmnow,timezone);
    				/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
    				/* In any case, it saves not having to do ast_mktime() */
    				beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
    				if (beg_today < time) {
    					/* Today */
    					res = wait_file(chan,ints, "digits/today",lang);
    				} else if (beg_today - 86400 < time) {
    					/* Yesterday */
    					res = wait_file(chan,ints, "digits/yesterday",lang);
    				} else {
    					res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
    				}
    			}
    			break;
    		case 'q':
    			/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
    			{
    				struct timeval now;
    				struct tm tmnow;
    				time_t beg_today;
    				
    				gettimeofday(&now,NULL);
    				ast_localtime(&now.tv_sec,&tmnow,timezone);
    				/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
    				/* In any case, it saves not having to do ast_mktime() */
    				beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
    				if (beg_today < time) {
    					/* Today */
    				} else if ((beg_today - 86400) < time) {
    					/* Yesterday */
    					res = wait_file(chan,ints, "digits/yesterday",lang);
    				} else if (beg_today - 86400 * 6 < time) {
    					/* Within the last week */
    					res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
    				} else {
    					res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
    				}
    			}
    			break;
    		case 'R':
    			res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
    			break;
    		case 'S':
    			/* Seconds */
    			snprintf(nextmsg,sizeof(nextmsg), "digits/kai");
    			res = wait_file(chan,ints,nextmsg,lang);
    			if (!res)
    				res = ast_say_number_full_gr(chan, tm.tm_sec, ints, lang, -1, -1);
    			if (!res)
    				snprintf(nextmsg,sizeof(nextmsg), "digits/seconds");
    			res = wait_file(chan,ints,nextmsg,lang);
    			break;
    		case 'T':
    			res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
    			break;
    		case ' ':
    		case '	':
    			/* Just ignore spaces and tabs */
    			break;
    		default:
    			/* Unknown character */
    			ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
    		}
    		/* Jump out on DTMF */
    		if (res) {
    			break;
    		}
    	}
    	return res;
    }