Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

DateTime.h

Go to the documentation of this file.
00001 #ifndef DATE_TIME_H 00002 #define DATE_TIME_H 00003 00004 #include <ctime> 00005 00006 const int NUM_LAST_DAYS = 7; 00007 const int NUM_LAST_WEEKS = 52; 00008 const int DAYS_IN_YEAR = 366; // maximum (leap years) 00009 const int HOURS_IN_DAY = 24; 00010 const int DAYS_IN_WEEK = 7; 00011 const int MONTHS_IN_YEAR = 12; 00012 00013 CString DayInYearToString( int iDayInYearIndex ); 00014 CString LastDayToString( int iLastDayIndex ); 00015 CString DayOfWeekToString( int iDayOfWeekIndex ); 00016 CString HourInDayToString( int iHourIndex ); 00017 CString MonthToString( int iMonthIndex ); 00018 CString LastWeekToString( int iLastWeekIndex ); 00019 00020 tm AddDays( tm start, int iDaysToMove ); 00021 tm GetYesterday( tm start ); 00022 int GetDayOfWeek( tm time ); 00023 tm GetNextSunday( tm start ); 00024 00025 tm GetDayInYearAndYear( int iDayInYearIndex, int iYear ); 00026 00027 00028 struct DateTime 00029 { 00030 int tm_sec; /* seconds after the minute - [0,59] */ 00031 int tm_min; /* minutes after the hour - [0,59] */ 00032 int tm_hour; /* hours since midnight - [0,23] */ 00033 int tm_mday; /* day of the month - [1,31] */ 00034 int tm_mon; /* months since January - [0,11] */ 00035 int tm_year; /* years since 1900 */ 00036 00037 DateTime(); 00038 void Init(); 00039 00040 bool operator<( const DateTime& other ) const 00041 { 00042 #define COMPARE( v ) if(v<other.v) return true; if(v>other.v) return false; 00043 COMPARE( tm_year ); 00044 COMPARE( tm_mon ); 00045 COMPARE( tm_mday ); 00046 COMPARE( tm_hour ); 00047 COMPARE( tm_min ); 00048 COMPARE( tm_sec ); 00049 #undef COMPARE 00050 // they're equal 00051 return false; 00052 } 00053 bool operator==( const DateTime& other ) const 00054 { 00055 #define COMPARE(x) if( x!=other.x ) return false; 00056 COMPARE( tm_year ); 00057 COMPARE( tm_mon ); 00058 COMPARE( tm_mday ); 00059 COMPARE( tm_hour ); 00060 COMPARE( tm_min ); 00061 COMPARE( tm_sec ); 00062 #undef COMPARE 00063 return true; 00064 } 00065 bool operator!=( const DateTime& other ) const { return !operator==(other); } 00066 00067 static DateTime GetNowDateTime(); 00068 static DateTime GetNowDate(); // GetNowDateTime() with time chopped off 00069 00070 void StripTime(); 00071 00072 CString GetString() const; 00073 bool FromString( const CString sDateTime ); 00074 }; 00075 00076 00077 #endif 00078 00079 /* 00080 * (c) 2001-2004 Chris Danford 00081 * All rights reserved. 00082 * 00083 * Permission is hereby granted, free of charge, to any person obtaining a 00084 * copy of this software and associated documentation files (the 00085 * "Software"), to deal in the Software without restriction, including 00086 * without limitation the rights to use, copy, modify, merge, publish, 00087 * distribute, and/or sell copies of the Software, and to permit persons to 00088 * whom the Software is furnished to do so, provided that the above 00089 * copyright notice(s) and this permission notice appear in all copies of 00090 * the Software and that both the above copyright notice(s) and this 00091 * permission notice appear in supporting documentation. 00092 * 00093 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00094 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00095 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00096 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00097 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00098 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00099 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00100 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00101 * PERFORMANCE OF THIS SOFTWARE. 00102 */

Generated on Thu Jan 27 20:57:19 2005 for StepMania by doxygen 1.3.7