Drizzled Public API Documentation

CSTime.h
00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Original author: Paul McCullagh (H&G2JCtL)
00020  * Continued development: Barry Leslie
00021  *
00022  * 2007-05-20
00023  *
00024  * Represents a time value from the database.
00025  *
00026  * NOTE: All times in the database are based on UTC
00027  * (Universal Coordinated Time)!
00028  *
00029  */
00030 
00031 #pragma once
00032 #ifndef __DBTIME_H__
00033 #define __DBTIME_H__
00034 
00035 #include <time.h>
00036 
00037 #include "CSDefs.h"
00038 #include "CSObject.h"
00039 
00040 class CSTime : public CSObject  {
00041 public:
00042   CSTime(): iIsNull(true) { }
00043   CSTime(s_int year, s_int mon, s_int day, s_int hour, s_int min, s_int sec, s_int nsec);
00044   virtual ~CSTime() { }
00045 
00046   bool isNull();
00047   
00048   void setNull();
00049 
00050   /*
00051    * Set the time. The value given is a local time
00052      * sec - seconds (0 - 60)
00053      * min - minutes (0 - 59)
00054      * hour - hours (0 - 23)
00055      * day - day of month (1 - 31)
00056    * mon - month of year (1 - 12)
00057    * year - where year >= 1970 (on UNIX)
00058    */
00059   void setLocal(s_int year, s_int mon, s_int day, s_int hour, s_int min, s_int sec, s_int nsec);
00060 
00061   /* Get the local time. */
00062   void getLocal(s_int& year, s_int& mon, s_int& day, s_int& hour, s_int& min, s_int& sec, s_int& nsec);
00063 
00064   /* Set the s_int time. */
00065   void setUTC(s_int year, s_int mon, s_int day, s_int hour, s_int min, s_int sec, s_int nsec);
00066 
00067   /* Get the universal time. */
00068   void getUTC(s_int& year, s_int& mon, s_int& day, s_int& hour, s_int& min, s_int& sec, s_int& nsec);
00069 
00070   /*
00071    * Returns the time as a string in the local time 
00072    * (time zone adjusted).
00073    */
00074   char *getCString();
00075 
00076   /*
00077    * As above, but using the given format.
00078    */
00079   char *getCString(const char *format);
00080 
00081   /* Set the time given a value in seconds and nanoseconds in UTC since 1970.
00082    * Used by UNIX.
00083    */
00084   void setUTC1970(time_t sec, s_int nsec);
00085   void getUTC1970(time_t& sec, s_int& nsec);
00086 
00087   /* Set the time given a 100 nanosecond value in UTC since 1601.
00088    * Used by Windows.
00089    */
00090   void setUTC1601(uint64_t nsec100);
00091   uint64_t getUTC1601();
00092 
00093   /* 
00094    * Tests if the time is more than 'max_age' seconds in the past.
00095    */
00096   bool olderThen(time_t max_age);
00097 
00098   static  uint64_t getTimeCurrentTicks();
00099 private:
00100   bool  iIsNull;
00101   char  iCString[100];
00102 
00103   /* The time based on UTC (GMT): */
00104   s_int iYear;
00105   s_int iMonth;
00106   s_int iDay;
00107   s_int iHours;
00108   s_int iMinutes;
00109   s_int iSeconds;
00110   s_int iNanoSeconds;   /* Plus this number of nano seconds. */
00111 
00112   uint64_t get1970as1601();
00113 };
00114 
00115 #endif