2 * Asterisk -- A telephony toolkit for Linux.
4 * SayUnixTime application
6 * Copyright (c) 2003 Tilghman Lesher. All rights reserved.
8 * Tilghman Lesher <app_sayunixtime__200309@the-tilghman.com>
10 * This code is released by the author with no restrictions on usage.
14 #include <asterisk/file.h>
15 #include <asterisk/logger.h>
16 #include <asterisk/options.h>
17 #include <asterisk/channel.h>
18 #include <asterisk/pbx.h>
19 #include <asterisk/module.h>
20 #include <asterisk/say.h>
27 static char *tdesc = "Say time";
29 static char *app_sayunixtime = "SayUnixTime";
31 static char *sayunixtime_synopsis = "Says a specified time in a custom format";
33 static char *sayunixtime_descrip =
34 "SayUnixTime([unixtime][|[timezone][|format]])\n"
35 " unixtime: time, in seconds since Jan 1, 1970. May be negative.\n"
37 " timezone: timezone, see /usr/share/zoneinfo for a list.\n"
38 " defaults to machine default.\n"
39 " format: a format the time is to be said in. See voicemail.conf.\n"
40 " defaults to \"ABdY 'digits/at' IMp\"\n"
41 " Returns 0 or -1 on hangup.\n";
47 static int sayunixtime_exec(struct ast_channel *chan, void *data)
51 char *s,*zone=NULL,*timec;
53 char *format = "ABdY 'digits/at' IMp";
58 gettimeofday(&tv,NULL);
59 unixtime = (time_t)tv.tv_sec;
65 timec = strsep(&s,"|");
66 if ((timec) && (*timec != '\0')) {
68 if (sscanf(timec,"%ld",&timein) == 1) {
69 unixtime = (time_t)timein;
73 zone = strsep(&s,"|");
74 if (zone && (*zone == '\0'))
80 ast_log(LOG_ERROR, "Out of memory error\n");
85 res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone);
91 int unload_module(void)
93 STANDARD_HANGUP_LOCALUSERS;
94 return ast_unregister_application(app_sayunixtime);
99 return ast_register_application(app_sayunixtime, sayunixtime_exec, sayunixtime_synopsis, sayunixtime_descrip);
102 char *description(void)
110 STANDARD_USECOUNT(res);
116 return ASTERISK_GPL_KEY;