00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "vul_get_timestamp.h"
00010
00011 #include <vcl_compiler.h>
00012
00013 #if defined(VCL_WIN32) && !defined(__CYGWIN__)
00014 #include <direct.h>
00015 #include <sys/timeb.h>
00016 #else
00017 #include <unistd.h>
00018 #ifdef __CYGWIN__
00019 #include <sys/time.h>
00020 #endif
00021 #endif
00022
00023
00024 #include <vcl_sys/time.h>
00025
00026
00027 #include <vcl_ctime.h>
00028 #include <vul/vul_string.h>
00029 #include <vcl_sstream.h>
00030 #include <vcl_iomanip.h>
00031
00032
00033
00034 #if !defined(VCL_WIN32) || defined(__CYGWIN__)
00035
00036 void vul_get_timestamp(int &secs, int &msecs)
00037 {
00038 struct timeval timestamp;
00039 struct timezone* dummy = 0;
00040 gettimeofday(×tamp, dummy);
00041
00042 secs = timestamp.tv_sec;
00043 msecs = timestamp.tv_usec/1000;
00044 }
00045 #elif defined(VCL_WIN32) && defined(VCL_BORLAND)
00046
00047 void vul_get_timestamp(int &secs, int &msecs)
00048 {
00049 struct timeb real;
00050 ftime(&real);
00051
00052 secs = real.time;
00053 msecs = real.millitm;
00054 }
00055 #else
00056
00057 void vul_get_timestamp(int &secs, int &msecs)
00058 {
00059 struct _timeb real;
00060 _ftime(&real);
00061
00062 secs = real.time;
00063 msecs = real.millitm;
00064 }
00065 #endif
00066
00067
00068
00069 vcl_string vul_get_time_as_string(vul_time_style style)
00070 {
00071 vcl_string timestr;
00072
00073
00074 vcl_time_t time_secs;
00075 vcl_time(&time_secs);
00076
00077
00078 struct vcl_tm *time;
00079 time = vcl_localtime(&time_secs);
00080
00081 switch (style)
00082 {
00083 case vul_numeric_msf:
00084 {
00085
00086
00087
00088
00089 vcl_ostringstream oss;
00090 oss.fill('0');
00091 oss << vcl_setw(4) << 1900+time->tm_year << ' '
00092 << vcl_setw(2) << 1 + time->tm_mon << ' '
00093 << vcl_setw(2) << time->tm_mday << ' '
00094 << vcl_setw(2) << time->tm_hour << ' '
00095 << vcl_setw(2) << time->tm_min << ' '
00096 << vcl_setw(2) << time->tm_sec;
00097 timestr = oss.str();
00098 }
00099 break;
00100
00101 default:
00102 {
00103
00104
00105 timestr = vcl_asctime(time);
00106 vul_string_right_trim(timestr, "\n");
00107 }
00108 break;
00109 }
00110
00111 return timestr;
00112 }
00113