datetime_test
--HG-- rename : c/timeconv_test/Makefile => c/datetime_test/Makefile
This commit is contained in:
parent
a93061c18c
commit
ebb76185ad
|
@ -16,7 +16,7 @@
|
|||
CC=cc
|
||||
CXX=c++
|
||||
LIBRARIES=
|
||||
TARGET0=timeconv_test
|
||||
TARGET0=datetime_test
|
||||
TARGET= $(TARGET0)
|
||||
INCLUDE1=$(HOME)/projects/include
|
||||
INCLUDE2=/usr/local/include
|
||||
|
@ -91,18 +91,18 @@ clean:
|
|||
# R U L E S |
|
||||
#________________________________|
|
||||
target_objs0 = \
|
||||
timeconv_test.o \
|
||||
timeconv.o
|
||||
datetime_test.o \
|
||||
datetime.o
|
||||
|
||||
$(TARGET0): $(target_objs0)
|
||||
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
|
||||
|
||||
|
||||
timeconv_test.o: \
|
||||
timeconv_test.c \
|
||||
$(INCLUDE1)/timeconv.h
|
||||
datetime_test.o: \
|
||||
datetime_test.c \
|
||||
$(INCLUDE1)/datetime.h
|
||||
|
||||
timeconv.o: \
|
||||
$(INCLUDE1)/timeconv.c \
|
||||
$(INCLUDE1)/timeconv.h
|
||||
datetime.o: \
|
||||
$(INCLUDE1)/datetime.c \
|
||||
$(INCLUDE1)/datetime.h
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "datetime.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct tm tm;
|
||||
time_t tt;
|
||||
char buf[64];
|
||||
|
||||
tm.tm_year = 2011 - 1900;
|
||||
tm.tm_mon = 12 - 1;
|
||||
tm.tm_mday = 9;
|
||||
tm.tm_hour = 15;
|
||||
tm.tm_min = 15;
|
||||
tm.tm_sec = 52;
|
||||
|
||||
putenv("TZ=GMT+0");
|
||||
|
||||
tt = mktime(&tm);
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
|
||||
tm = *gmtime(&tt);
|
||||
|
||||
strftime(buf, sizeof(buf), "%Y.%m.%d %H.%M.%S", &tm);
|
||||
puts(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "timeconv.h"
|
||||
|
||||
void pack_conv_test()
|
||||
{
|
||||
struct tm t;
|
||||
struct timeval tv;
|
||||
struct timespec ts;
|
||||
struct timecent tc;
|
||||
struct timemils tl;
|
||||
uint64_t pack64 = 0;
|
||||
char buf[256];
|
||||
size_t i = 0;
|
||||
|
||||
putenv("TZ=GMT+0");
|
||||
|
||||
t.tm_sec = 1;
|
||||
t.tm_min = 2;
|
||||
t.tm_hour = 3;
|
||||
t.tm_mday = 4;
|
||||
t.tm_mon = 5-1;
|
||||
t.tm_year = 2011-1900;
|
||||
t.tm_isdst = 0;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
tv.tv_sec = mktime(&t);
|
||||
ts.tv_sec = mktime(&t);
|
||||
tc.tv_sec = mktime(&t);
|
||||
tl.tv_sec = mktime(&t);
|
||||
|
||||
switch (i) {
|
||||
case 0: pack64 = usec_from_timeval(tv);
|
||||
tv.tv_usec = 798431;
|
||||
memset(&tv, 0, sizeof(tv));
|
||||
tv = timeval_from_usec(pack64);
|
||||
break;
|
||||
case 1: pack64 = nsec_from_timespec(ts);
|
||||
ts.tv_nsec = 798431;
|
||||
memset(&ts, 0, sizeof(ts));
|
||||
ts = timespec_from_nsec(pack64);
|
||||
break;
|
||||
case 2: pack64 = csec_from_timecent(tc);
|
||||
tc.tv_csec = 798431;
|
||||
memset(&tc, 0, sizeof(tc));
|
||||
tc = timecent_from_csec(pack64);
|
||||
break;
|
||||
case 3: pack64 = msec_from_timemils(tl);
|
||||
tl.tv_msec = 798431;
|
||||
memset(&tl, 0, sizeof(tl));
|
||||
tl = timemils_from_msec(pack64);
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
strftime(buf, sizeof(buf), "%Y.%m.%d %H:%M:%S", gmtime(&tv.tv_sec));
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
void struct_conv_test()
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timespec ts;
|
||||
struct timecent tc;
|
||||
struct timemils tl;
|
||||
|
||||
tv = timeval_from_timespec(ts);
|
||||
ts = timespec_from_timeval(tv);
|
||||
|
||||
tv = timeval_from_timecent(tc);
|
||||
tc = timecent_from_timeval(tv);
|
||||
|
||||
tv = timeval_from_timemils(tl);
|
||||
tl = timemils_from_timeval(tv);
|
||||
|
||||
ts = timespec_from_timecent(tc);
|
||||
tc = timecent_from_timespec(ts);
|
||||
|
||||
ts = timespec_from_timemils(tl);
|
||||
tl = timemils_from_timespec(ts);
|
||||
|
||||
tc = timecent_from_timemils(tl);
|
||||
tl = timemils_from_timecent(tc);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pack_conv_test();
|
||||
|
||||
struct_conv_test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue