Interpret a year like 10 as 2010 and not as 1910 if the now time is near 2010. Add test case for that.
Should fix #7257. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41146 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5a44e07cca
commit
08444962ae
@ -766,11 +766,12 @@ computeDate(const char* format, bool* optional, parsed_element* elements,
|
||||
if (now == -1)
|
||||
now = time(NULL);
|
||||
|
||||
int nowYear = -1;
|
||||
if (dateMask.IsComplete())
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
else {
|
||||
localtime_r(&now, &tm);
|
||||
|
||||
nowYear = tm.tm_year;
|
||||
if (dateMask.HasTime()) {
|
||||
tm.tm_min = 0;
|
||||
tm.tm_sec = 0;
|
||||
@ -820,10 +821,31 @@ computeDate(const char* format, bool* optional, parsed_element* elements,
|
||||
break;
|
||||
case 'y':
|
||||
case 'Y':
|
||||
{
|
||||
if (nowYear < 0) {
|
||||
struct tm tmNow;
|
||||
localtime_r(&now, &tmNow);
|
||||
nowYear = tmNow.tm_year;
|
||||
}
|
||||
int nowYearInCentury = nowYear % 100;
|
||||
int nowCentury = 1900 + nowYear - nowYearInCentury;
|
||||
|
||||
tm.tm_year = element->value;
|
||||
if (tm.tm_year > 1900)
|
||||
if (tm.tm_year < 1900) {
|
||||
// just a relative year like 11 (2011)
|
||||
|
||||
// interpret something like 50 as 1950 but
|
||||
// something like 11 as 2011 (assuming now is 2011)
|
||||
if (nowYearInCentury + 10 < tm.tm_year % 100)
|
||||
tm.tm_year -= 100;
|
||||
|
||||
tm.tm_year += nowCentury - 1900;
|
||||
}
|
||||
else {
|
||||
tm.tm_year -= 1900;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'z': // time zone
|
||||
case 'Z':
|
||||
{
|
||||
|
@ -86,6 +86,7 @@ main(int argc, char** argv)
|
||||
{739702803, "Mon, June 10th, 1993 10:00:03 am +0100", ABSOLUTE, true, false},
|
||||
{739731603, "Mon, June 10th, 1993 10:00:03 am -0700", ABSOLUTE, true, false},
|
||||
{739654203, "Mon, June 10th, 1993 06:00:03 am ACDT", ABSOLUTE, true, false},
|
||||
{1291204800, "01 Dec 10 12:00", ABSOLUTE, false, true},
|
||||
{-1, NULL, 0, false}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user