Make date() command available to all architectures.

Allow the user to specify the date/time format string.
This commit is contained in:
Andrew Johnson
2007-05-01 20:23:57 +00:00
parent 854e8adb71
commit ae887b7527
2 changed files with 27 additions and 21 deletions
+27
View File
@@ -13,6 +13,7 @@
#define epicsExportSharedSymbols
#include "iocsh.h"
#include "epicsTime.h"
#include "epicsThread.h"
#include "epicsMutex.h"
#include "envDefs.h"
@@ -22,6 +23,31 @@
#include "libComRegister.h"
void date(const char *format)
{
epicsTimeStamp now;
char nowText[80] = {'\0'};
if (epicsTimeGetCurrent(&now)) {
puts("Current time not available.");
return;
}
if (format == NULL || format[0] == '\0')
format = "%Y/%m/%d %H:%M:%S.%06f";
epicsTimeToStrftime(nowText, sizeof(nowText), format, &now);
puts(nowText);
}
/* date */
static const iocshArg dateArg0 = { "format",iocshArgString};
static const iocshArg * const dateArgs[] = {&dateArg0};
static const iocshFuncDef dateFuncDef = {"date", 1, dateArgs};
static void dateCallFunc (const iocshArgBuf *args)
{
date(args[0].sval);
}
/* chdir */
static const iocshArg chdirArg0 = { "directory name",iocshArgString};
static const iocshArg * const chdirArgs[1] = {&chdirArg0};
@@ -267,6 +293,7 @@ static void epicsThreadResumeCallFunc(const iocshArgBuf *args)
void epicsShareAPI libComRegister(void)
{
iocshRegister(&dateFuncDef, dateCallFunc);
iocshRegister(&chdirFuncDef, chdirCallFunc);
iocshRegister(&pwdFuncDef, pwdCallFunc);
-21
View File
@@ -217,24 +217,3 @@ int epicsTimeGetEvent (epicsTimeStamp *pDest, int eventNumber)
return(epicsTimeERROR);
}
/* Unless
putenv("TIMEZONE=<name>::<minutesWest>:<start daylight>:<end daylight>")
is executed before and epics software is loaded, UTC rather than local
time will be displayed
*/
void date()
{
epicsTimeStamp now;
char nowText[40];
size_t rtn;
rtn = epicsTimeGetCurrent(&now);
if(rtn) {
printf("epicsTimeGetCurrent failed\n");
return;
}
nowText[0] = 0;
rtn = epicsTimeToStrftime(nowText,sizeof(nowText),
"%Y/%m/%d %H:%M:%S.%06f",&now);
printf("%s\n",nowText);
}