better calories tracking

This commit is contained in:
Chris Danford
2004-02-22 23:29:13 +00:00
parent 9e6a952a41
commit 06c9073fcf
8 changed files with 246 additions and 59 deletions
+71
View File
@@ -63,3 +63,74 @@ CString HourInDayToString( int iHourInDayIndex )
return ssprintf("%02d:00", iHourInDayIndex);
}
static const CString MONTH_TO_NAME[MONTHS_IN_YEAR] =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
};
CString MonthToString( int iMonthIndex )
{
return MONTH_TO_NAME[iMonthIndex];
}
CString LastWeekToString( int iLastWeekIndex )
{
switch( iLastWeekIndex )
{
case 0: return "This week"; break;
case 1: return "Last week"; break;
default: return ssprintf("%d weeks ago",iLastWeekIndex); break;
}
}
tm AddDays( tm start, int iDaysToMove )
{
start.tm_mday += iDaysToMove;
time_t seconds = mktime( &start );
ASSERT( seconds != (time_t)-1 );
tm time;
localtime_r( &seconds, &time );
return time;
}
tm GetYesterday( tm start )
{
return AddDays( start, -1 );
}
int GetDayOfWeek( tm time )
{
int iDayOfWeek = time.tm_wday;
ASSERT( iDayOfWeek < DAYS_IN_WEEK );
return iDayOfWeek;
}
tm GetNextSunday( tm start )
{
return AddDays( start, DAYS_IN_WEEK-GetDayOfWeek(start) );
}
tm GetDayInYearAndYear( int iDayInYearIndex, int iYear )
{
time_t now = time( NULL );
tm when = *localtime( &now );
when.tm_mday = iDayInYearIndex;
when.tm_year = iYear - 1900;
time_t then = mktime( &when );
when = *localtime( &then );
return when;
}