[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Re: patch to fix #46917
From: Ariya Hidayat <ariya () kde ! org>
Date: 2002-08-29 6:18:07
[Download RAW message or body]
> As for 55 defaults to 2055, it's in KLocale (because 55<69, at least that's
> the way in kdelibs 3.0.3). Excel defaults to 1955 because the limit is 20
> not 69. Changing KSpread to behave like this will require dumping the use
> KLocale::readDate().
Well, I found a hack to do this and still making use of KLocale::readDate(),
see the attached patch.
In short: when entering date with 2 digit years, e.g 3/4/45, the year is
interpreter as year 19xx if xx is >=30, else it's year 20xx (in this case,
1945 instead of KLocale's 2045). This makes it compatible with Excel.
Please review.
PS: The limit is actually 30, not 20 (I was wrong before).
["year.patch" (text/x-diff)]
Index: kspread_cell.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_cell.cc,v
retrieving revision 1.443
diff -u -3 -p -r1.443 kspread_cell.cc
--- kspread_cell.cc 2002/08/29 06:58:29 1.443
+++ kspread_cell.cc 2002/08/29 07:23:03
@@ -3904,8 +3904,23 @@ bool KSpreadCell::tryParseDate( const QS
QString fmt = locale()->dateFormatShort();
if( ( fmt.contains( "%y" ) == 1 ) && ( tmpDate.year() > 2999 ) )
- tmpDate = tmpDate.addYears( -1900 );
-
+ tmpDate = tmpDate.addYears( -1900 );
+
+ // this is another HACK !
+ // with two digit years, 0-69 is treated as year 2000-2069 (see KLocale)
+ // however, in Excel only 0-29 is year 2000-2029, 30 or later is 1930 onwards
+
+ // the following provides workaround for KLocale so we're compatible with Excel
+ // (e.g 3/4/45 is Mar 4, 1945 not Mar 4, 2045)
+ if( ( tmpDate.year() >= 2030 ) && ( tmpDate.year() <= 2069 ) )
+ {
+ QString yearFourDigits = QString::number( tmpDate.year() );
+ QString yearTwoDigits = QString::number( tmpDate.year() % 100 );
+
+ // if year is 2045, check to see if "2045" isn't there --> actual input is "45"
+ if( ( str.contains( yearTwoDigits ) >= 1 ) && ( str.contains( yearFourDigits ) == 0 ) )
+ tmpDate = tmpDate.addYears( -100 );
+ }
}
if (valid)
{
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic