DateTime.h
Go to the documentation of this file.
00001 #ifndef CASTOR_DATETIME_H
00002 #define CASTOR_DATETIME_H 1
00003 
00004 #include <sys/time.h>
00005 #include <time.h>
00006 
00007 #define EPOCH_ADJUST (62135596800LL)
00008 
00009 namespace castor {
00010         
00011         struct DateTime {
00012 
00013                 protected:
00014 
00015                         long long ticks;
00016 
00017                 public:
00018 
00023                         DateTime(long long t) : ticks(t) {
00024                         }
00025 
00026                         DateTime(const DateTime &other) :
00027                                 ticks(other.ticks)
00028                         {
00029                         }
00030 
00031                         static inline DateTime getUtcNow() {
00032                                 struct timeval tv;
00033                                 memset(&tv, 0, sizeof(tv));
00034                                 gettimeofday(&tv, NULL);
00035                                 return DateTime(((static_cast<unsigned long long>(tv.tv_sec) + EPOCH_ADJUST) * 1000000 + tv.tv_usec) * 10);
00036                         }
00037 
00038                         static inline unsigned long long getUtcNowC() {
00039                                 struct timeval tv;
00040                                 memset(&tv, 0, sizeof(tv));
00041                                 gettimeofday(&tv, NULL);
00042                                 return (((static_cast<unsigned long long>(tv.tv_sec) + EPOCH_ADJUST) * 1000000 + tv.tv_usec) * 10);
00043                         }
00044 
00045                         inline long long getTicks() {
00046                                 return this->ticks;
00047                         }
00048         };
00049 }
00050 
00051 #endif /* CASTOR_DATETIME_H */
00052 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39