diff options
author | allen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2000-09-19 23:38:04 +0000 |
---|---|---|
committer | allen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2000-09-19 23:38:04 +0000 |
commit | fc3a1d5ff1931ece60c5d070917078d1fb6a3ed2 (patch) | |
tree | 68e4138bb4ec52a5006dac5f66da279496833aa0 /src/util/Time.c | |
parent | 9e27232ef75abb92c5aa2de960e61ff27d3b5ade (diff) |
Added CCTK_CurrentTime and CCTK_CurrentDate
git-svn-id: http://svn.cactuscode.org/flesh/trunk@1826 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util/Time.c')
-rw-r--r-- | src/util/Time.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/util/Time.c b/src/util/Time.c new file mode 100644 index 00000000..54b4112c --- /dev/null +++ b/src/util/Time.c @@ -0,0 +1,97 @@ + /*@@ + @file Time.c + @date Wed Sep 17 2000 + @author Gabrielle Allen + @desc + Date and time routines + @enddesc + @version $Header$ + @@*/ + +/* #define DEBUG_TIME */ + +#include <time.h> +#include <string.h> + +#include "cctk_Flesh.h" + +static char *rcsid = "$Header$"; + +CCTK_FILEVERSION(util_Time_c) + + +/******************************************************************** + ********************* External Routines ********************** + ********************************************************************/ + + /*@@ + @routine Util_CurrentTime + @date Tue Sep 19 + @author Gabrielle Allen + @desc + Fills string with current local time, returning the number + of characters filled. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +int Util_CurrentTime(int len, char *now) +{ + int retval; + time_t timep; + const char *fmt = "%X"; + + timep = time(NULL); + strftime(now, len, fmt, localtime(&timep)); + + retval = strlen(now); + retval=retval > len ? 0 : retval; + +#ifdef DEBUG_TIME + printf("CurrentTime = %s\n",now); +#endif + + return retval; +} + + + /*@@ + @routine Util_CurrentDate + @date Tue Sep 19 + @author Gabrielle Allen + @desc + Fills string with current local date, returning the number of + characters filled. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +int Util_CurrentDate(int len, char *now) +{ + int retval; + time_t timep; + const char *fmt = "%a %d %b %Y"; + + timep = time(NULL); + strftime(now, 50, fmt, localtime(&timep)); + + retval = strlen(now); + retval=retval > len ? 0 : retval; + +#ifdef DEBUG_TIME + printf("CurrentDate = %s\n",thedate); +#endif + + return retval; +} + |