00001
00002
00003
00004 #include "datetime.h"
00005 static char* defaultformat = "%b %d %Y %H:%M:%S";
00006
00007
00008
00009
00010 int strttime(char* timestr, char* timeformat, rodsLong_t* t) {
00011 if(*timeformat==0) {
00012 timeformat = defaultformat;
00013 }
00014 struct tm tm;
00015 if (strptime(timestr, timeformat, &tm) == 0) {
00016 return 0;
00017 }
00018
00019
00020
00021
00022
00023 tm.tm_isdst = -1;
00024 *t = (rodsLong_t) mktime(&tm);
00025 if (*t == -1) {
00026 return 0;
00027 }
00028
00029 return 1;
00030 }
00031
00032
00033
00034
00035
00036 int ttimestr(char* timestr, int n, char* timeformat, rodsLong_t* t) {
00037 if(*timeformat==0) {
00038 timeformat = defaultformat;
00039 }
00040 time_t t2 = (time_t) *t;
00041 struct tm tm = *localtime(&t2);
00042 if (strftime(timestr, n, timeformat, &tm) == 0) {
00043 return 0;
00044 }
00045 return 1;
00046 }
00047