00001 #include "epoc-time.h" 00002 00003 TTime UnixEpochTime() 00004 { 00005 TDateTime dateTime; 00006 dateTime.Set(1970, EJanuary, 0, 0, 0, 0, 0); 00007 return TTime(dateTime); 00008 } 00009 00010 // "epocTime" is assumed to be in UTC. 00011 time_t UtcEpocTimeToUnixTime(const TTime& epocTime) 00012 { 00013 return (time_t)((epocTime.Int64() - UnixEpochTime().Int64()) / 1000000); 00014 } 00015 00016 // "epocTime" is assumed to be local time. 00017 time_t LocalEpocTimeToUnixTime(const TTime& epocTime) 00018 { 00019 TLocale loc; 00020 TTimeIntervalSeconds utcOffset = loc.UniversalTimeOffset(); 00021 return (UtcEpocTimeToUnixTime(epocTime) - utcOffset.Int()); 00022 } 00023 00024 void UnixTimeToUtcEpocTime(TTime& epocTime, time_t unixTime) 00025 { 00026 epocTime = UnixEpochTime() + TTimeIntervalSeconds(unixTime); 00027 } 00028 00029 void UnixTimeToLocalEpocTime(TTime& epocTime, time_t unixTime) 00030 { 00031 TLocale loc; 00032 TTimeIntervalSeconds utcOffset = loc.UniversalTimeOffset(); 00033 UnixTimeToUtcEpocTime(epocTime, unixTime); 00034 epocTime += utcOffset; 00035 } 00036 00037 TTimeIntervalMicroSeconds32 SecsToUsecs(TInt secs) 00038 { 00039 TInt64 us64 = TInt64(secs) * 1000000LL; 00040 // max time is around 35 minutes only 00041 TInt us = ((us64 > 2147483647LL) ? 2147483647 : (int)us64); 00042 return TTimeIntervalMicroSeconds32(us); 00043 } 00044 00045 /** 00046 00047 epoc-time.cpp 00048 00049 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00050 and the authors. All rights reserved. 00051 00052 Authors: Tero Hasu <tero.hasu@hut.fi> 00053 00054 Permission is hereby granted, free of charge, to any person 00055 obtaining a copy of this software and associated documentation files 00056 (the "Software"), to deal in the Software without restriction, 00057 including without limitation the rights to use, copy, modify, merge, 00058 publish, distribute, sublicense, and/or sell copies of the Software, 00059 and to permit persons to whom the Software is furnished to do so, 00060 subject to the following conditions: 00061 00062 The above copyright notice and this permission notice shall be 00063 included in all copies or substantial portions of the Software. 00064 00065 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00066 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00067 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00068 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00069 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00070 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00071 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00072 SOFTWARE. 00073 00074 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1