[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Timestamp class inside.
From: |
Paul E Johnson |
Subject: |
Timestamp class inside. |
Date: |
Sat, 03 Mar 2001 14:54:15 -0600 |
I want to put the day/time of creation into file names in order to keep
records on runs. I put the same stamp on files that save parameters,
data, etc, and after a few weeks it is the only way I've found to
remember what I did. I found myself rewriting the code that fetches the
time and converts to a string over and over, making the same mistakes
over and over. Aha, create a class, use over and over! I settled in on
this way, that avoids overrunning buffers (so far as I know), doesn't
leak memory, and gives output I want. Feel free to use it if you like,
or improve and redistribute.
I wish something like this was in Swarm itself so I could call it from a
Java program, so I won't have to learn how to do the timestamp in Java
:). If you have Java code that does this, please share.
TimeStamp.h:
#import <defobj/Create.h>
@interface TimeStamp:CreateDrop
{
}
+(char *) getTimeStamp;
@end
TimeStamp.m:
#import "TimeStamp.h"
#import <misc.h>
@implementation TimeStamp
+(char *) getTimeStamp
{
int i;
char * cD;
char * charDate;
int notch=0;
time_t currentTime = time (NULL);
cD = ctime(¤tTime);
charDate= strcpy (( char *)
xmalloc(sizeof(char)*(1+strlen(cD))),cD);
charDate[strlen(cD)-1]= 0; //remove newline
for(i=0; i< strlen(cD); i++)
{
if (charDate[i]==' ') charDate[i]='_';
else if (charDate[i]==':')
{
if (notch == 0)
{
charDate[i] = 'h';
notch = 1;
}
else if (notch == 1)
charDate[i]='m';
}
else if (charDate[i] == '\n')
charDate[i] = '\0';
}
return charDate;
}
@end
I call the static method one time at the beginning of a job, save the
resulting string, and then use it for the output files.
FILE *outputFile;
char outputFileName[50];
char *charDate = NULL;
charDate = [TimeStamp getTimeStamp];
sprintf(outputFileName, "DataCulture_%s", charDate);
So after this all runs, I've got a data output file with a name that
helps:
DataCulture_Sat_Mar__3_14h50m55_2001
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
- Timestamp class inside.,
Paul E Johnson <=