Main Page   Class Hierarchy   Compound List   File List   Compound Members  

TimeUtils.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #include "TimeUtils.hpp"
00021 
00022 #include <ctime>
00023 #include <cstring>
00024 #include <cstdio>
00025 
00026 long ms_difftime (struct timeval* P_final, struct timeval* P_init)
00027 {
00028   long L_val_sec, L_val_usec;
00029 
00030   L_val_sec = P_final->tv_sec - P_init->tv_sec;
00031   L_val_usec = P_final->tv_usec - P_init->tv_usec;
00032   if (L_val_usec < 0) L_val_usec += 1000000, L_val_sec--;
00033   return (L_val_sec*1000 + L_val_usec/1000);
00034 
00035 }
00036 
00037 void time_tochar (char *P_time, struct timeval* P_tv)
00038 {
00039   struct tm * L_currentDate;
00040   
00041   // Get the current date and time
00042   L_currentDate = localtime ((const time_t *)&P_tv->tv_sec);
00043   
00044   // Format the time
00045   if (L_currentDate == NULL) {
00046     memset (P_time, 0, TIME_STRING_LENGTH);
00047   } else {
00048     sprintf(P_time, 
00049             "%4.4d-%2.2d-%2.2d.%2.2d:%2.2d:%2.2d.%3.3d", 
00050             L_currentDate->tm_year + 1900,
00051             L_currentDate->tm_mon + 1,
00052             L_currentDate->tm_mday,
00053             L_currentDate->tm_hour,
00054             L_currentDate->tm_min,
00055             L_currentDate->tm_sec,
00056             (int)((P_tv->tv_usec)/1000));
00057   }
00058 } 
00059 
00060 void time_tochar_minus (char *P_time, struct timeval* P_tv)
00061 {
00062   struct tm * L_currentDate;
00063   
00064   // Get the current date and time
00065   L_currentDate = localtime ((const time_t *)&P_tv->tv_sec);
00066   
00067   // Format the time
00068   if (L_currentDate == NULL) {
00069     memset (P_time, 0, TIME_STRING_LENGTH);
00070   } else {
00071     sprintf(P_time, 
00072             "%4.4d-%2.2d-%2.2d.%2.2d-%2.2d-%2.2d.%3.3d", 
00073             L_currentDate->tm_year + 1900,
00074             L_currentDate->tm_mon + 1,
00075             L_currentDate->tm_mday,
00076             L_currentDate->tm_hour,
00077             L_currentDate->tm_min,
00078             L_currentDate->tm_sec,
00079             (int)((P_tv->tv_usec)/1000));
00080   }
00081 } 
00082 

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002