• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

acsutilTimeStamp.h

Go to the documentation of this file.
00001 #ifndef acsutilTime_H
00002 #define acsutilTime_H
00003 
00004 /*******************************************************************
00005 * ALMA - Atacama Large Millimiter Array
00006 * (c) European Southern Observatory, 2004 
00007 *
00008 *This library is free software; you can redistribute it and/or
00009 *modify it under the terms of the GNU Lesser General Public
00010 *License as published by the Free Software Foundation; either
00011 *version 2.1 of the License, or (at your option) any later version.
00012 *
00013 *This library is distributed in the hope that it will be useful,
00014 *but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 *Lesser General Public License for more details.
00017 *
00018 *You should have received a copy of the GNU Lesser General Public
00019 *License along with this library; if not, write to the Free Software
00020 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00021 *
00022 * "@(#) $Id: acsutilTimeStamp.h,v 1.1 2005/12/12 19:12:29 dfugate Exp $"
00023 *
00024 * who       when        what
00025 * --------  ----------  ----------------------------------------------
00026 * msekoran  2001/03/12  modified
00027 */
00028 
00034 #ifndef __cplusplus
00035 #error This is a C++ include file and cannot be used from plain C
00036 #endif
00037 
00038 #include <acscommonC.h>
00039 #include <SString.h>
00040 #include <OS_NS_time.h>
00041 
00072 #if defined (ACE_LACKS_LONGLONG_T)
00073   static const CORBA::ULongLong UTCtoUNIXTimeBaseOffset (0xD8539C80, 2);
00074   // (Lower 32 bits of the offset in hex, Upper 32 bits of the offset in hex)
00075 #else
00076   static const CORBA::ULongLong UTCtoUNIXTimeBaseOffset = ACE_UINT64_LITERAL(0x2D8539C80);
00077 #endif
00078 
00079 
00084 ACS::Time getTimeStamp();
00085 
00091 ACS::TimeInterval getTime();
00092 
00097 ACE_CString getStringifiedTimeStamp();
00098 
00099 inline ACE_Time_Value UTCtoACE_Time_Value(const ACS::Time &time)
00100 {
00101     ACS::Time seconds = time / static_cast<ACE_UINT32>(10000000);
00102     ACS::Time microseconds = (time % static_cast<ACE_UINT32>(10000000)) / 10;
00103     return ACE_Time_Value (ACE_U64_TO_U32 (seconds),
00104                            ACE_U64_TO_U32 (microseconds));
00105 }
00106 
00111 inline ACE_CString getStringifiedUTC(ACS::TimeInterval time)
00112 {
00113   ACE_TCHAR str[24];
00114   ACE_TCHAR ctp[20];
00115 
00116   // convert to UNIX time
00117   time -= UTCtoUNIXTimeBaseOffset * ACE_static_cast(ACE_UINT32, 10000000);
00118 
00119   ACE_Time_Value tv = UTCtoACE_Time_Value(time);
00120 
00121   time_t ut(tv.sec());
00122   struct tm *utc_p = ACE_OS::gmtime(&ut);
00123   ACE_OS::strftime(ctp, sizeof(ctp), "%Y-%m-%dT%H:%M:%S", utc_p);
00124   
00125   ACE_OS::sprintf (str, ACE_TEXT ("%s.%03ld"),
00126                    ctp, tv.usec () / 1000);
00127   
00128   return str;
00129 }
00130 
00131 #endif 
00132 

Generated on Thu Jan 12 2012 23:13:50 for ACS-10.0 C++ API by  doxygen 1.7.0