00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "jutil.hh"
00023 using namespace jutil;
00024
00025 #include <time.h>
00026
00027 #ifdef WIN32
00028 #define snprintf _snprintf
00029 #define strcasecmp stricmp
00030 #include <string.h>
00031 #elif defined(MACOS)
00032 #include <ctype.h>
00033 #include <stdio.h>
00034
00035
00036
00037 int strcasecmp(const char *s1, const char *s2)
00038 {
00039 char c1, c2;
00040 while (1)
00041 {
00042 c1 = tolower(*s1++);
00043 c2 = tolower(*s2++);
00044 if (c1 < c2) return -1;
00045 if (c1 > c2) return 1;
00046 if (c1 == 0) return 0;
00047 }
00048 }
00049 #else
00050 #include <stdio.h>
00051 #endif
00052
00053 bool CaseInsensitiveCmp::operator()(const std::string& lhs, const std::string& rhs) const
00054 {
00055 return (strcasecmp(lhs.c_str(), rhs.c_str()) < 0);
00056 }
00057
00058 std::string jutil::getTimeStamp()
00059 {
00060 time_t t;
00061 struct tm *new_time;
00062 static char timestamp[18];
00063 int ret;
00064
00065 t = time(NULL);
00066
00067 if(t == (time_t)-1)
00068 return NULL;
00069 new_time = gmtime(&t);
00070
00071 ret = snprintf(timestamp, 18, "%d%02d%02dT%02d:%02d:%02d", 1900+new_time->tm_year,
00072 new_time->tm_mon+1, new_time->tm_mday, new_time->tm_hour,
00073 new_time->tm_min, new_time->tm_sec);
00074
00075 if(ret == -1)
00076 return "";
00077
00078 return std::string(timestamp);
00079 }