1 // TortoiseGit - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseGit
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 #include "resource.h"
\r
22 #include "TortoiseGitBlameAppUtils.h"
\r
23 #include "Registry.h"
\r
25 CAppUtils::CAppUtils(void)
\r
29 CAppUtils::~CAppUtils(void)
\r
34 * FUNCTION : FormatDateAndTime
\r
35 * DESCRIPTION : Generates a displayable string from a CTime object in
\r
36 * system short or long format or as a relative value
\r
38 * option - DATE_SHORTDATE or DATE_LONGDATE
\r
39 * bIncluedeTime - whether to show time as well as date
\r
40 * bRelative - if true then relative time is shown if reasonable
\r
41 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
\r
42 * rather than locale
\r
43 * RETURN : CString containing date/time
\r
45 CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/,
\r
46 bool bRelative /*=false*/)
\r
51 datetime = ToRelativeTimeString( cTime );
\r
55 // should we use the locale settings for formatting the date/time?
\r
56 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE))
\r
60 cTime.GetAsSystemTime( sysTime );
\r
64 GetDateFormat(LOCALE_USER_DEFAULT, option, &sysTime, NULL, buf,
\r
65 sizeof(buf)/sizeof(TCHAR)-1);
\r
69 datetime += _T(" ");
\r
70 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, sizeof(buf)/sizeof(TCHAR)-1);
\r
76 // no, so fixed format
\r
79 datetime = cTime.Format(_T("%Y-%m-%d %H:%M:%S"));
\r
83 datetime = cTime.Format(_T("%Y-%m-%d"));
\r
91 * Converts a given time to a relative display string (relative to current time)
\r
92 * Given time must be in local timezone
\r
94 CString CAppUtils::ToRelativeTimeString(CTime time)
\r
97 // convert to COleDateTime
\r
99 time.GetAsSystemTime( sysTime );
\r
100 COleDateTime oleTime( sysTime );
\r
101 answer = ToRelativeTimeString(oleTime, COleDateTime::GetCurrentTime());
\r
106 * Generates a display string showing the relative time between the two given times as COleDateTimes
\r
108 CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo)
\r
111 COleDateTimeSpan ts = RelativeTo - time;
\r
113 if(fabs(ts.GetTotalDays()) >= 3*365)
\r
115 answer .FormatMessage(_T("%1!d! Years ago"), (int)(ts.GetTotalDays()/365));
\r
118 if(fabs(ts.GetTotalDays()) >= 60)
\r
120 answer.FormatMessage( _T("%1!d! Months ago"), (int)(ts.GetTotalDays()/30) );
\r
124 if(fabs(ts.GetTotalDays()) >= 14)
\r
126 answer.FormatMessage(_T("%1!d! Weeks ago"), (int)(ts.GetTotalDays()/7) );
\r
130 if(fabs(ts.GetTotalDays()) >= 2)
\r
132 answer.FormatMessage(_T("%1!d! Days ago"), (int)(ts.GetTotalDays()) );
\r
136 if(fabs(ts.GetTotalHours()) >= 2)
\r
138 answer.FormatMessage(_T("%1!d! Hours ago"), (int)(ts.GetTotalHours()) );
\r
142 if(fabs(ts.GetTotalMinutes()) >= 2)
\r
144 answer.FormatMessage(_T("%1!d! Minutes ago"), (int)(ts.GetTotalMinutes()) );
\r
148 answer.FormatMessage(_T("%1!d! Seconds ago"), (int)(ts.GetTotalSeconds()) );
\r