Summary:ASTERISK-04001: [patch] Add strftime() function
Reporter:Tilghman Lesher (tilghman)Labels:
Date Opened:2005-04-27 12:55:04Date Closed:2008-01-15 15:33:24.000-0600
Versions:Frequency of
Environment:Attachments:( 0) 20050504__acf_strftime.diff.txt
Description:Adds the availability of strftime([<epoch>][,[timezone][,format]]), to allow the dialplan to obtain a string representation of an arbitrary time (or current time, if unspecified).  This eliminates the need for any future hardcoded times in Asterisk channel variables, such as ${TIMESTAMP} and ${DATETIME}.  These will probably be kept for legacy reasons, but after this function, no more are necessary.

Since the C function strftime(3) is the basis for this Asterisk function, supported format codes are exactly as what is supported on the particular platform Asterisk is running on (may be slightly different for each).


Disclaimer on file.
Comments:By: Kevin P. Fleming (kpfleming) 2005-04-28 11:49:18


The synopsis text says that it formats the current time, but in reality it formats the current time or a specified timestamp. I think the synopsis also shouldn't use 'epoch' as the name of the timestamp value...remember, these help texts are for end-users, not programmers. Maybe just 'timestamp' would be appropriate?

I'm not keen on it being called strftime, it's not "the Asterisk way" :-) We haven't yet standardized on these function names, but I think something like FormatTime() (or FORMAT_TIME(), if they should be upper case) would be a better choice.

By: Tilghman Lesher (tilghman) 2005-04-28 14:26:22

That was rude.  "It's not the Asterisk way"?  You may have been hired by Digium, but that doesn't give you license to bash other developers.

By: Kevin P. Fleming (kpfleming) 2005-04-29 10:40:42

Rude? Did you not see the smiley face following it? In what way was that "bashing" you at all? Geez man, you are way, way too sensitive.

Please show me _any_ other function or app that's exposed in the Asterisk dialplan that has a name even similarly cryptic to this one.

By: Tilghman Lesher (tilghman) 2005-04-29 11:45:20

So it's okay to insult someone, as long as you add a smiley to the end of the insult?

Cut() is similarly named; it holds the same name as the cut(1) command in Unix, provides a similar syntax, and performs the same operation.  If anything, date() might be a good alternative function name, as date(1) passes the format unadulterated to strftime(3).

In terms of the word epoch, we have the builtin variable ${EPOCH}, so I don't see what your objection is to that name.

By: Kevin P. Fleming (kpfleming) 2005-04-29 12:04:34

If you consider a request for a different name to be a personal insult, then I can't do anything about that. Sorry.

Yeah, I wasn't thrilled about Cut() either, but I couldn't come up with any better name at the time. At least it's the analog of a command-line tool, as opposed to a library function, so end users will have more likelihood to have seen it before.

Re: EPOCH... ugh, yeah, I forgot about that one. I hereby propose we add an alias called TIMESTAMP and deprecate EPOCH <G>

I'm OK with using 'date', but I wonder if we should use DATE, to go along with FIELDQTY, CDR and LEN being uppercase?

By: Tilghman Lesher (tilghman) 2005-04-29 12:08:44

BZZZZZZZZZZZT.  We already have a TIMESTAMP.  Good lord, if you're going to be an Asterisk developer, I would have thought you should at least know the system.  Until then, this is pointless.  Am I going to have to point out every single flaw in your argument until you finally agree that I've actually REALLY thought about these issues, and what I'm proposing actually does make sense?

By: Tilghman Lesher (tilghman) 2005-04-29 12:09:47

And btw, regex(), if(), ifnull() and several other functions are all lowercase.

By: Brian West (bkw918) 2005-04-29 14:39:34

I say the function name is fine.  It's descriptive of what it does.  I mean really should wa call it ast_thingybober_strftime...  oh oh or STRFtime or StrfTime .. no no no strftime is fine with me boys and girls.


By: Michael Jerris (mikej) 2005-04-29 14:43:42

<FLAMESUIT> Think random phone system operators, not linux\unix people or coders boys and girls... we have to be able to be more descriptive than strftime.  Just my humble opinion </FLAMESUIT>

By: Tilghman Lesher (tilghman) 2005-04-29 15:00:01

It's not like you can't punch 'strftime' into Google and get a description of what it is.  Compare that to any generic phrase, for which there could be thousands of different commands, each mutually imcompatible.  Better, strftime is even standardized to mean a specific set of functionality, which further disambiguates its purpose.  It doesn't get much clearer than that.

By: Michael Jerris (mikej) 2005-04-29 15:32:17

Okay, FORMAT_TIME it is then.... :)

By: Anthony Minessale (anthm) 2005-04-29 16:30:02

I'm not too fond of semantics arguements and my opinion probably is biased but I say you help all the people (100's of developers) who already know what strftime means by naming it strftime() allowing them to bypass RTFM at the expense of confusing 10 ppl who will be confused anyway even if it was named USE_MACROS_TO_FORMAT_THE_TIME_YOU_CLOD() the dialplan already is a pretty tricky yet flexible thing and most people who would make one complicated to do a strftime() mid priority probably know what it means.


By: Brian West (bkw918) 2005-05-04 17:53:52

I think its ready like it is.


By: Kevin P. Fleming (kpfleming) 2005-05-04 20:53:09

Then you are all welcome to convince Mark... based on his conversation with me, the policy for dialplan function names is English words (or standard abbreviations), in uppercase, with words separated by underscores.

By: Tilghman Lesher (tilghman) 2005-05-04 23:01:54

Per Mark, I've uppercased STRFTIME in this updated patch.

By: Kevin P. Fleming (kpfleming) 2005-05-05 01:43:33

Committed to CVS HEAD, modified slightly to be placed in new 'funcs' subdirectory. Thanks!

By: Digium Subversion (svnbot) 2008-01-15 15:33:24.000-0600

Repository: asterisk
Revision: 5584

U   trunk/funcs/func_strings.c

r5584 | kpfleming | 2008-01-15 15:33:24 -0600 (Tue, 15 Jan 2008) | 2 lines

add STRFTIME dialplan function (bug ASTERISK-4001, modified to use new funcs subdirectory)