File indexing completed on 2022-11-29 18:25:10

0001 /*
0002     Copyright 2010 John Layt <john@layt.net>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "kdatetimeformattertest.h"
0021 
0022 #include <locale.h>
0023 
0024 #include <QString>
0025 
0026 #include <QTest>
0027 #include "kdatetime.h"
0028 #include "kcalendarsystem.h"
0029 #include "klocale.h"
0030 #include "kconfiggroup.h"
0031 
0032 QTEST_MAIN(KDateTimeFormatterTest)
0033 
0034 void KDateTimeFormatterTest::testFormatDateTimePosix()
0035 {
0036     KLocale::global()->setLanguage(QStringList("en_US"));
0037     KLocale::global()->setCalendarSystem(KLocale::QDateCalendar);
0038     KLocale::global()->setDateFormatShort("%y-%m-%d");
0039 
0040     KDateTimeFormatter formatter;
0041 
0042     //Test default settings
0043     KDateTime testDate(QDate(2005, 10, 20));
0044     QCOMPARE(formatter.formatDateTime(testDate, "%Y"), QString("2005"));
0045     QCOMPARE(formatter.formatDateTime(testDate, "%C"), QString("20"));
0046     QCOMPARE(formatter.formatDateTime(testDate, "%y"), QString("05"));
0047     QCOMPARE(formatter.formatDateTime(testDate, "%m"), QString("10"));
0048     QCOMPARE(formatter.formatDateTime(testDate, "%n"), QString("10"));
0049     QCOMPARE(formatter.formatDateTime(testDate, "%d"), QString("20"));
0050     QCOMPARE(formatter.formatDateTime(testDate, "%e"), QString("20"));
0051     QCOMPARE(formatter.formatDateTime(testDate, "%B"), QString("October"));
0052     QCOMPARE(formatter.formatDateTime(testDate, "%b"), QString("Oct"));
0053     QCOMPARE(formatter.formatDateTime(testDate, "%h"), QString("Oct"));
0054     QCOMPARE(formatter.formatDateTime(testDate, "%A"), QString("Thursday"));
0055     QCOMPARE(formatter.formatDateTime(testDate, "%a"), QString("Thu"));
0056     QCOMPARE(formatter.formatDateTime(testDate, "%j"), QString("293"));
0057     QCOMPARE(formatter.formatDateTime(testDate, "%V"), QString("42"));
0058     QCOMPARE(formatter.formatDateTime(testDate, "%G"), QString("2005"));
0059     QCOMPARE(formatter.formatDateTime(testDate, "%g"), QString("05"));
0060     QCOMPARE(formatter.formatDateTime(testDate, "%u"), QString("4"));
0061     QCOMPARE(formatter.formatDateTime(testDate, "%D"), QString("10/20/05"));
0062     QCOMPARE(formatter.formatDateTime(testDate, "%F"), QString("2005-10-20"));
0063     QCOMPARE(formatter.formatDateTime(testDate, "%x"), QString("05-10-20"));
0064     QCOMPARE(formatter.formatDateTime(testDate, "%%"), QString("%"));
0065     QCOMPARE(formatter.formatDateTime(testDate, "%t"), QString("\t"));
0066 
0067     QCOMPARE(formatter.formatDateTime(testDate, "-%Y-%C-%y-%m-%n-%d-%e-%B-%b-%h-%A-%a-%j-%V-%G-%g-%u:%D:%F:%x:%%-%t-"),
0068              QString("-2005-20-05-10-10-20-20-October-Oct-Oct-Thursday-Thu-293-42-2005-05-4:10/20/05:2005-10-20:05-10-20:%-\t-"));
0069 
0070     //Test the minimum widths are respected
0071     QCOMPARE(formatter.formatDateTime(testDate, "%1Y"),  QString("2005"));
0072     QCOMPARE(formatter.formatDateTime(testDate, "%1C"),  QString("20"));
0073     QCOMPARE(formatter.formatDateTime(testDate, "%1y"),  QString("05"));
0074     QCOMPARE(formatter.formatDateTime(testDate, "%1m"),  QString("10"));
0075     QCOMPARE(formatter.formatDateTime(testDate, "%1n"),  QString("10"));
0076     QCOMPARE(formatter.formatDateTime(testDate, "%1d"),  QString("20"));
0077     QCOMPARE(formatter.formatDateTime(testDate, "%1e"),  QString("20"));
0078     QCOMPARE(formatter.formatDateTime(testDate, "%01B"), QString("October"));
0079     QCOMPARE(formatter.formatDateTime(testDate, "%01b"), QString("Oct"));
0080     QCOMPARE(formatter.formatDateTime(testDate, "%01h"), QString("Oct"));
0081     QCOMPARE(formatter.formatDateTime(testDate, "%01A"), QString("Thursday"));
0082     QCOMPARE(formatter.formatDateTime(testDate, "%01a"), QString("Thu"));
0083     QCOMPARE(formatter.formatDateTime(testDate, "%1j"),  QString("293"));
0084     QCOMPARE(formatter.formatDateTime(testDate, "%1V"),  QString("42"));
0085     QCOMPARE(formatter.formatDateTime(testDate, "%1G"),  QString("2005"));
0086     QCOMPARE(formatter.formatDateTime(testDate, "%1g"),  QString("05"));
0087     QCOMPARE(formatter.formatDateTime(testDate, "%1u"),  QString("4"));
0088     QCOMPARE(formatter.formatDateTime(testDate, "%1D"),  QString("10/20/05"));
0089     QCOMPARE(formatter.formatDateTime(testDate, "%1F"),  QString("2005-10-20"));
0090     QCOMPARE(formatter.formatDateTime(testDate, "%1x"),  QString("05-10-20"));
0091     QCOMPARE(formatter.formatDateTime(testDate, "%1%"),  QString("%"));
0092     QCOMPARE(formatter.formatDateTime(testDate, "%1t"),  QString("\t"));
0093 
0094     testDate.setDate(QDate(2005, 1, 2));
0095 
0096     //Test various padding options with minimum width
0097     QCOMPARE(formatter.formatDateTime(testDate, "%"),     QString(""));
0098     QCOMPARE(formatter.formatDateTime(testDate, "%m"),    QString("01"));
0099     QCOMPARE(formatter.formatDateTime(testDate, "%n"),    QString("1"));
0100     QCOMPARE(formatter.formatDateTime(testDate, "%d"),    QString("02"));
0101     QCOMPARE(formatter.formatDateTime(testDate, "%e"),    QString("2"));
0102     QCOMPARE(formatter.formatDateTime(testDate, "%j"),    QString("002"));
0103     QCOMPARE(formatter.formatDateTime(testDate, "%_m"),   QString(" 1"));
0104     QCOMPARE(formatter.formatDateTime(testDate, "%_n"),   QString("1"));
0105     QCOMPARE(formatter.formatDateTime(testDate, "%_d"),   QString(" 2"));
0106     QCOMPARE(formatter.formatDateTime(testDate, "%_e"),   QString("2"));
0107     QCOMPARE(formatter.formatDateTime(testDate, "%_j"),   QString("  2"));
0108     QCOMPARE(formatter.formatDateTime(testDate, "%-m"),   QString("1"));
0109     QCOMPARE(formatter.formatDateTime(testDate, "%-n"),   QString("1"));
0110     QCOMPARE(formatter.formatDateTime(testDate, "%-d"),   QString("2"));
0111     QCOMPARE(formatter.formatDateTime(testDate, "%-e"),   QString("2"));
0112     QCOMPARE(formatter.formatDateTime(testDate, "%-j"),   QString("2"));
0113     QCOMPARE(formatter.formatDateTime(testDate, "%0m"),   QString("01"));
0114     QCOMPARE(formatter.formatDateTime(testDate, "%0n"),   QString("1"));
0115     QCOMPARE(formatter.formatDateTime(testDate, "%0d"),   QString("02"));
0116     QCOMPARE(formatter.formatDateTime(testDate, "%0e"),   QString("2"));
0117     QCOMPARE(formatter.formatDateTime(testDate, "%0j"),   QString("002"));
0118     QCOMPARE(formatter.formatDateTime(testDate, "%-_j"),  QString("  2"));
0119     QCOMPARE(formatter.formatDateTime(testDate, "%_-j"),  QString("2"));
0120     QCOMPARE(formatter.formatDateTime(testDate, "%-_0j"), QString("002"));
0121 
0122     //Test various padding options with width override
0123     QCOMPARE(formatter.formatDateTime(testDate, "%1m"),   QString("01"));
0124     QCOMPARE(formatter.formatDateTime(testDate, "%-05m"), QString("00001"));
0125     QCOMPARE(formatter.formatDateTime(testDate, "%10m"),  QString("0000000001"));
0126     QCOMPARE(formatter.formatDateTime(testDate, "%15m"),  QString("000000000000001"));
0127     QCOMPARE(formatter.formatDateTime(testDate, "%-5m"),  QString("1"));
0128     QCOMPARE(formatter.formatDateTime(testDate, "%_5m"),  QString("    1"));
0129     QCOMPARE(formatter.formatDateTime(testDate, "%_15m"), QString("              1"));
0130     QCOMPARE(formatter.formatDateTime(testDate, "%1B"),   QString("January"));
0131     QCOMPARE(formatter.formatDateTime(testDate, "%15B"),  QString("        January"));
0132     QCOMPARE(formatter.formatDateTime(testDate, "%-15B"), QString("January"));
0133     QCOMPARE(formatter.formatDateTime(testDate, "%_15B"), QString("        January"));
0134     QCOMPARE(formatter.formatDateTime(testDate, "%015B"), QString("00000000January"));
0135 
0136     //Test week number in previous year
0137     QCOMPARE(formatter.formatDateTime(testDate, "%V"), QString("53"));
0138     QCOMPARE(formatter.formatDateTime(testDate, "%G"), QString("2004"));
0139     QCOMPARE(formatter.formatDateTime(testDate, "%g"), QString("04"));
0140 
0141     //test case overrides
0142     QCOMPARE(formatter.formatDateTime(testDate, "%B"),  QString("January"));
0143     QCOMPARE(formatter.formatDateTime(testDate, "%^B"), QString("JANUARY"));
0144     QCOMPARE(formatter.formatDateTime(testDate, "%#B"), QString("JANUARY"));
0145     QCOMPARE(formatter.formatDateTime(testDate, "%m"),  QString("01"));
0146     QCOMPARE(formatter.formatDateTime(testDate, "%^m"), QString("01"));
0147     QCOMPARE(formatter.formatDateTime(testDate, "%#m"), QString("01"));
0148 
0149     //Test various year options
0150 
0151     testDate.setDate(QDate(789, 1, 1));
0152     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("0789"));
0153     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("07"));
0154     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("89"));
0155     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("789"));
0156     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("7"));
0157     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("89"));
0158     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString(" 789"));
0159     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString(" 7"));
0160     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("89"));
0161     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("0789"));
0162     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("07"));
0163     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("89"));
0164     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("AD"));
0165     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("789"));
0166     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("789 AD"));
0167 
0168     testDate.setDate(QDate(709, 1, 1));
0169     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("0709"));
0170     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("07"));
0171     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("09"));
0172     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("709"));
0173     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("7"));
0174     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("9"));
0175     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString(" 709"));
0176     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString(" 7"));
0177     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString(" 9"));
0178     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("0709"));
0179     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("07"));
0180     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("09"));
0181     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("AD"));
0182     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("709"));
0183     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("709 AD"));
0184 
0185     testDate.setDate(QDate(89, 1, 1));
0186     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("0089"));
0187     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("00"));
0188     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("89"));
0189     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("89"));
0190     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("0"));
0191     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("89"));
0192     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("  89"));
0193     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString(" 0"));
0194     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("89"));
0195     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("0089"));
0196     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("00"));
0197     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("89"));
0198     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("AD"));
0199     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("89"));
0200     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("89 AD"));
0201 
0202     testDate.setDate(QDate(9, 1, 1));
0203     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("0009"));
0204     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("00"));
0205     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("09"));
0206     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("9"));
0207     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("0"));
0208     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("9"));
0209     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("   9"));
0210     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString(" 0"));
0211     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString(" 9"));
0212     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("0009"));
0213     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("00"));
0214     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("09"));
0215     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("AD"));
0216     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("9"));
0217     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("9 AD"));
0218 
0219     testDate.setDate(QDate(-9, 1, 1));
0220     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("-0009"));
0221     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("-00"));
0222     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("-09"));
0223     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("-9"));
0224     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("-0"));
0225     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("-9"));
0226     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("  -9"));
0227     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString("-0"));
0228     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("-9"));
0229     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("-0009"));
0230     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("-00"));
0231     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("-09"));
0232     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("BC"));
0233     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("9"));
0234     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("9 BC"));
0235 
0236     testDate.setDate(QDate(-89, 1, 1));
0237     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("-0089"));
0238     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("-00"));
0239     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("-89"));
0240     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("-89"));
0241     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("-0"));
0242     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("-89"));
0243     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString(" -89"));
0244     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString("-0"));
0245     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("-89"));
0246     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("-0089"));
0247     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("-00"));
0248     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("-89"));
0249     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("BC"));
0250     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("89"));
0251     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("89 BC"));
0252 
0253     testDate.setDate(QDate(-789, 1, 1));
0254     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("-0789"));
0255     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("-07"));
0256     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("-89"));
0257     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("-789"));
0258     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("-7"));
0259     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("-89"));
0260     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("-789"));
0261     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString("-7"));
0262     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("-89"));
0263     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("-0789"));
0264     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("-07"));
0265     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("-89"));
0266     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("BC"));
0267     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("789"));
0268     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("789 BC"));
0269 
0270     testDate.setDate(QDate(-709, 1, 1));
0271     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("-0709"));
0272     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("-07"));
0273     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("-09"));
0274     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("-709"));
0275     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("-7"));
0276     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("-9"));
0277     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("-709"));
0278     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString("-7"));
0279     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("-9"));
0280     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("-0709"));
0281     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("-07"));
0282     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("-09"));
0283     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("BC"));
0284     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("709"));
0285     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("709 BC"));
0286 
0287     testDate.setDate(QDate(-1789, 1, 1));
0288     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("-1789"));
0289     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("-17"));
0290     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("-89"));
0291     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("-1789"));
0292     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("-17"));
0293     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("-89"));
0294     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("-1789"));
0295     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString("-17"));
0296     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("-89"));
0297     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("-1789"));
0298     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("-17"));
0299     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("-89"));
0300     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("BC"));
0301     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("1789"));
0302     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("1789 BC"));
0303 
0304     testDate.setDate(QDate(-1709, 1, 1));
0305     QCOMPARE(formatter.formatDateTime(testDate, "%Y"),  QString("-1709"));
0306     QCOMPARE(formatter.formatDateTime(testDate, "%C"),  QString("-17"));
0307     QCOMPARE(formatter.formatDateTime(testDate, "%y"),  QString("-09"));
0308     QCOMPARE(formatter.formatDateTime(testDate, "%-Y"), QString("-1709"));
0309     QCOMPARE(formatter.formatDateTime(testDate, "%-C"), QString("-17"));
0310     QCOMPARE(formatter.formatDateTime(testDate, "%-y"), QString("-9"));
0311     QCOMPARE(formatter.formatDateTime(testDate, "%_Y"), QString("-1709"));
0312     QCOMPARE(formatter.formatDateTime(testDate, "%_C"), QString("-17"));
0313     QCOMPARE(formatter.formatDateTime(testDate, "%_y"), QString("-9"));
0314     QCOMPARE(formatter.formatDateTime(testDate, "%0Y"), QString("-1709"));
0315     QCOMPARE(formatter.formatDateTime(testDate, "%0C"), QString("-17"));
0316     QCOMPARE(formatter.formatDateTime(testDate, "%0y"), QString("-09"));
0317     QCOMPARE(formatter.formatDateTime(testDate, "%EC"), QString("BC"));
0318     QCOMPARE(formatter.formatDateTime(testDate, "%Ey"), QString("1709"));
0319     QCOMPARE(formatter.formatDateTime(testDate, "%EY"), QString("1709 BC"));
0320     /*
0321         // Test POSIX format
0322         testDate.setDate( QDate( 2010, 1, 2 ) );
0323         QCOMPARE( formatter.formatDateTime( testDate, "%Y-%n-%d", KLocale::KdeFormat ),   QString( "2010-1-02" ) );
0324         QCOMPARE( formatter.formatDateTime( testDate, "%Y-%n-%d", KLocale::PosixFormat ), QString( "2010-\n-02" ) );
0325         QCOMPARE( formatter.formatDateTime( testDate, "%e", KLocale::KdeFormat ),   QString( "2" ) );
0326         QCOMPARE( formatter.formatDateTime( testDate, "%e", KLocale::PosixFormat ), QString( " 2" ) );
0327     */
0328 }
0329 
0330 void KDateTimeFormatterTest::testFormatUnicode()
0331 {
0332     KLocale::global()->setLanguage(QStringList("en_US"));
0333     KLocale::global()->setCalendarSystem(KLocale::QDateCalendar);
0334     KLocale::global()->setDateFormatShort("%y-%m-%d");
0335 
0336     KDateTimeFormatter formatter;
0337 
0338     KDateTime testDateTime(QDate(2005, 10, 20));
0339     compareFormatUnicode(formatter, testDateTime, "yyyy");
0340     compareFormatUnicode(formatter, testDateTime, "yy");
0341     compareFormatUnicode(formatter, testDateTime, "MMMM");
0342     compareFormatUnicode(formatter, testDateTime, "MMM");
0343     compareFormatUnicode(formatter, testDateTime, "MM");
0344     compareFormatUnicode(formatter, testDateTime, "M");
0345     compareFormatUnicode(formatter, testDateTime, "dddd");
0346     compareFormatUnicode(formatter, testDateTime, "ddd");
0347     compareFormatUnicode(formatter, testDateTime, "dd");
0348     compareFormatUnicode(formatter, testDateTime, "d");
0349     compareFormatUnicode(formatter, testDateTime, "yyyy-MM-dd");
0350 
0351     testDateTime.setDate(QDate(-2005, 10, 20));
0352     compareFormatUnicode(formatter, testDateTime, "yyyy");
0353     compareFormatUnicode(formatter, testDateTime, "yy");
0354     compareFormatUnicode(formatter, testDateTime, "MMMM");
0355     compareFormatUnicode(formatter, testDateTime, "MMM");
0356     compareFormatUnicode(formatter, testDateTime, "MM");
0357     compareFormatUnicode(formatter, testDateTime, "M");
0358     compareFormatUnicode(formatter, testDateTime, "dddd");
0359     compareFormatUnicode(formatter, testDateTime, "ddd");
0360     compareFormatUnicode(formatter, testDateTime, "dd");
0361     compareFormatUnicode(formatter, testDateTime, "d");
0362     compareFormatUnicode(formatter, testDateTime, "yyyy-MM-dd");
0363 }
0364 
0365 void KDateTimeFormatterTest::compareFormatUnicode(KDateTimeFormatter formatter, const KDateTime &testDateTime, const QString &testFormat)
0366 {
0367     QCOMPARE(formatter.formatDateTime(testDateTime, testFormat, KLocale::TimeFormatOptions(), KLocale::global()->calendar(), KLocale::global(), KLocale::global()->dateTimeDigitSet(), KLocale::UnicodeFormat), testDateTime.dateTime().toString(testFormat));
0368 }