TimeUtilities.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009  
00010 #ifndef TIMEUTILITIES_H
00011 #define TIMEUTILITIES_H
00012 
00013 #include <time.h>
00014 
00015 /**
00016  * Convenience functions when using time-based objects.
00017  */
00018 namespace TimeUtilities
00019 {
00020    /**
00021     * The number of seconds between midnight 1 Jan 1940 and midnight 1 Jan 1970.
00022     */
00023    const long TimeScaleOffset = 946771200;
00024 
00025    /**
00026     * Converts a time struct to seconds from 1940.
00027     *
00028     * @param   timeStruct
00029     *          The time struct from which to get seconds.
00030     *
00031     * @return  Returns the number of seconds after midnight 1 Jan 1940.  To
00032     *          convert this value to a time_t (seconds from 1970) object,
00033     *          simply subtract TimeUtilities::TimeScaleOffset.
00034     */
00035    unsigned int timeStructToSecondsFrom1940(const struct tm& timeStruct);
00036 
00037    /**
00038     * Converts seconds from 1940 to a time struct.
00039     *
00040     * @param   seconds
00041     *          The number of seconds after midnight 1 Jan 1940 from which to get
00042     *          a time struct.  To convert a time_t (seconds from 1970) to this
00043     *          value, simply add TimeUtilities::TimeScaleOffset.
00044     *
00045     * @return  The time struct based on the given seconds from 1940.
00046     */
00047    struct tm secondsFrom1940ToTimeStruct(unsigned int seconds);
00048 
00049    /**
00050     * Queries whether a given year is a leap year.
00051     *
00052     * @param   year
00053     *          The four-digit year to query if it is a leap year.
00054     *
00055     * @return  Returns \c true if the given year is a leap year; otherwise
00056     *          returns \c false.
00057     */
00058    bool isLeapYear(int year);
00059 }
00060 
00061 #endif

Software Development Kit - Opticks 4.9.0 Build 16218