]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
allow epoch in strftime_tz
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 9 Dec 2010 20:09:38 +0000 (14:09 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 10 Dec 2010 23:47:46 +0000 (17:47 -0600)
src/mod/applications/mod_commands/mod_commands.c

index eacde5994997e2d72bb379c77378da2edfc37ba6..9d6920e6cdae36ff8a3e2ed7770b4a870d3867af 100644 (file)
@@ -4278,21 +4278,33 @@ SWITCH_STANDARD_API(strftime_tz_api_function)
        char *format = NULL;
        const char *tz_name = NULL;
        char date[80] = "";
+       char *mycmd = NULL, *p;
+       switch_time_t when = 0;
 
-       if (!zstr(cmd)) {
-               format = strchr(cmd, ' ');
-               tz_name = cmd;
-               if (format) {
+       if (cmd) mycmd = strdup(cmd);
+
+       if (!zstr(mycmd)) {
+               tz_name = mycmd;
+
+               if ((format = strchr(mycmd, ' '))) {
                        *format++ = '\0';
                }
+               
+               if ((p = strchr(format, '|'))) {
+                       *p++ = '\0';
+                       when = atol(format);
+                       format = p;
+               }
        }
 
-       if (switch_strftime_tz(tz_name, format, date, sizeof(date), 0) == SWITCH_STATUS_SUCCESS) {      /* The lookup of the zone may fail. */
+       if (switch_strftime_tz(tz_name, format, date, sizeof(date), when * 1000000) == SWITCH_STATUS_SUCCESS) { /* The lookup of the zone may fail. */
                stream->write_function(stream, "%s", date);
        } else {
                stream->write_function(stream, "-ERR Invalid Timezone\n");
        }
 
+       switch_safe_free(mycmd);
+
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -4715,7 +4727,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "show", "Show", show_function, SHOW_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "sql_escape", "Escape a string to prevent sql injection", sql_escape, SQL_ESCAPE_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "status", "status", status_function, "");
-       SWITCH_ADD_API(commands_api_interface, "strftime_tz", "strftime_tz", strftime_tz_api_function, "<Timezone_name> [format string]");
+       SWITCH_ADD_API(commands_api_interface, "strftime_tz", "strftime_tz", strftime_tz_api_function, "<Timezone_name> [<epoch>|][format string]");
        SWITCH_ADD_API(commands_api_interface, "stun", "stun", stun_function, "<stun_server>[:port]");
        SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, "<mss> [count]");