Main Page Class Hierarchy Compound List File List Compound Members File Members

# timefuncs.h

Go to the documentation of this file.

    00001 //---------------------------------------------------------------------------
    00002 #ifndef TimeFuncsH
    00003 #define TimeFuncsH
    00004 //---------------------------------------------------------------------------
    00005
    00006 #include <time.h>
    00007 #include <worm_statuscode.h>
    00008
    00009 //---------------------------------------------------------------------------
    00010
    00011 enum WORM_TIME_LOCALE
    00012 {
    00013     WORM_GMT_TIME
    00014   , WORM_LOCAL_TIME
    00015 };
    00016
    00017 enum WORM_TIME_FORMAT
    00018 {
    00019     WORM_TIMEFMT_8     = 0  // YYYYMMDD
    00020   , WORM_TIMEFMT_14    = 1  // YYYYMMDDhhmmss
    00021   , WORM_TIMEFMT_18    = 2  // YYYYMMDDhhmmss.sss
    00022   , WORM_TIMEFMT_UTC21 = 3  // YYYYMMDD_UTC_hh:mm:ss
    00023   , WORM_TIMEFMT_16    = 4  // YYYY/MM/DD hh:mm
    00024   , WORM_TIMEFMT_19    = 5  // YYYY/MM/DD hh:mm:ss
    00025   , WORM_TIMEFMT_23    = 6  // YYYY/MM/DD hh:mm:ss.sss
    00026   , WORM_TIMEFMT_26    = 7  // DOW MON DD HH:MM:SS YYYY\n
    00027 };
    00028
    00029 #define WORM_TIMESTR_LENGTH 26 // max length (with terminator) of above formats
    00030
    00031 typedef char WORM_DATETIMESTR[WORM_TIMESTR_LENGTH];
    00032
    00033 typedef unsigned long ULONG_TIME;
    00034
    00035 //
    00036 //  sec.nano_secs
    00037 //
    00038 typedef double HIGHRES_TIME;
    00039
    00040
    00041
    00042 //---------------------------------------------------------------------------
    00043 class TTimeFuncs
    00044 {
    00045 protected:
    00046
    00047    static const short MONTH_STARTS[2][12];
    00048
    00049 public:
    00050
    00051    static const char DOW[7][4]; // = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
    00052
    00053    static const char MOY[12][4]; // = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
    00054
    00055    // seconds since Midnight, Jan 1, 1970 with milliseconds as fraction portion
    00056    static HIGHRES_TIME GetHighResTime();
    00057
    00058    /*  DateString()
    00059    **
    00060    **  r_buffer must point to a buffer of at least WORM_TIMESTR_LENGTH length
    00061    **  Locale defaults to GMT
    00062    **
    00063    */
    00064    static char * DateString( char * r_buffer
    00065                            , WORM_TIME_FORMAT p_format
    00066                            , WORM_TIME_LOCALE p_locale = WORM_GMT_TIME
    00067                            , double p_time = -1.0 // -1.0 means 'now'
    00068                            );
    00069
    00070    /*  TimeToDouble -- converts a string in format YYYYMMDDHHMMSS.sss
    00071    **                  into a double representing seconds since Jan 1, 1970
    00072    **
    00073    */
    00074    static double TimeToDouble( const char * p_buffer );
    00075
    00076    static void MSecSleep( unsigned int p_msec );
    00077
    00078    static bool IsLeapyear( unsigned int p_year );
    00079
    00080    static bool YearJulianToMonDay( short   p_year
    00081                                  , short   p_julday
    00082                                  , short * r_monthnum
    00083                                  , short * r_monthday
    00084                                  );
    00085
    00086    static bool CrackDate( const char * p_buffer          // "YYYYMMDD...."
    00087                         , short      * r_year            // 1900 - n
    00088                         , short      * r_monthnum        // 1 - 12
    00089                         , short      * r_monthday        // 1 - 31
    00090                         , short      * r_year2           // 0 - 99
    00091                         , short      * r_julday   = NULL // 1 - 366
    00092                         , bool       * r_isleap   = NULL
    00093                         );
    00094    // NOTE: a compile error on the NULL can indicate that "#include <string.h>
    00095    //       is needed in the referencing class.
    00096
    00097    static bool CrackTime( const char * p_buffer  // "HHMMSS.sss" or "........HHMMSS.sss"
    00098                         , short      * p_hour
    00099                         , short      * p_min
    00100                         , short      * p_sec    = NULL
    00101                         , short      * p_msec   = NULL
    00102                         , double     * p_fpsec  = NULL
    00103                         );
    00104 };
    00105
    00106 #endif