inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/wroot/date
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_wroot_date
00005 #define inlib_wroot_date
00006 
00007 #ifdef WIN32
00008 #include <windows.h>
00009 #else
00010 #include <time.h>
00011 #endif
00012 
00013 namespace inlib {
00014 namespace wroot {
00015 
00016 typedef unsigned int date;
00017 
00018 inline date get_date(){
00019   // Set Date/Time to current time as reported by the system.
00020   // Date and Time are encoded into one single unsigned 32 bit word.
00021   // Date is stored with the origin being the 1st january 1995.
00022   // Time has 1 second precision.
00023 #ifdef WIN32
00024   SYSTEMTIME tp;
00025   ::GetLocalTime(&tp);
00026   unsigned int year   = tp.wYear-1900;
00027   unsigned int month  = tp.wMonth;
00028   unsigned int day    = tp.wDay;
00029   unsigned int hour   = tp.wHour;
00030   unsigned int min    = tp.wMinute;
00031   unsigned int sec    = tp.wSecond;
00032 #else
00033   time_t tloc = ::time(0);
00034   struct tm *tp = (tm*)::localtime(&tloc);
00035   unsigned int year   = tp->tm_year;
00036   unsigned int month  = tp->tm_mon + 1;
00037   unsigned int day    = tp->tm_mday;
00038   unsigned int hour   = tp->tm_hour;
00039   unsigned int min    = tp->tm_min;
00040   unsigned int sec    = tp->tm_sec;
00041 #endif
00042   return ((year-95)<<26 | month<<22 | day<<17 | hour<<12 | min<<6 | sec);
00043 }
00044 
00045 }}
00046 
00047 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines