2007-08-03 18:43:04 +00:00
|
|
|
/********************************************************************
|
2016-02-27 00:41:21 +00:00
|
|
|
* COPYRIGHT:
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 2008-2016, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
2007-08-03 18:43:04 +00:00
|
|
|
********************************************************************/
|
|
|
|
|
2007-08-10 23:31:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-02-27 00:41:21 +00:00
|
|
|
#include "dtptngts.h"
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/dtfmtsym.h"
|
|
|
|
#include "unicode/dtptngen.h"
|
2016-02-23 10:40:09 +00:00
|
|
|
#include "cmemory.h"
|
2007-08-03 18:43:04 +00:00
|
|
|
#include "loctest.h"
|
|
|
|
|
|
|
|
|
|
|
|
// This is an API test, not a unit test. It doesn't test very many cases, and doesn't
|
|
|
|
// try to test the full functionality. It just calls each function in the class and
|
|
|
|
// verifies that it works on a basic level.
|
|
|
|
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite DateTimePatternGeneratorAPI");
|
|
|
|
switch (index) {
|
2007-08-04 01:15:18 +00:00
|
|
|
TESTCASE(0, testAPI);
|
2009-12-10 09:13:49 +00:00
|
|
|
TESTCASE(1, testOptions);
|
2013-09-10 07:51:38 +00:00
|
|
|
TESTCASE(2, testAllFieldPatterns);
|
2015-11-18 12:29:17 +00:00
|
|
|
TESTCASE(3, testStaticGetSkeleton);
|
2016-02-27 00:41:21 +00:00
|
|
|
TESTCASE(4, testC);
|
2007-08-03 18:43:04 +00:00
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-27 00:41:21 +00:00
|
|
|
#define MAX_LOCALE 11
|
2007-08-07 07:22:18 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
/**
|
|
|
|
* Test various generic API methods of DateTimePatternGenerator for API coverage.
|
|
|
|
*/
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
|
|
|
|
{
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString patternData[] = {
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString("yM"), // 00
|
|
|
|
UnicodeString("yMMM"), // 01
|
|
|
|
UnicodeString("yMd"), // 02
|
|
|
|
UnicodeString("yMMMd"), // 03
|
|
|
|
UnicodeString("Md"), // 04
|
|
|
|
UnicodeString("MMMd"), // 05
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("MMMMd"), // 06
|
|
|
|
UnicodeString("yQQQ"), // 07
|
|
|
|
UnicodeString("hhmm"), // 08
|
|
|
|
UnicodeString("HHmm"), // 09
|
|
|
|
UnicodeString("jjmm"), // 10
|
|
|
|
UnicodeString("mmss"), // 11
|
|
|
|
UnicodeString("yyyyMMMM"), // 12
|
|
|
|
UnicodeString("MMMEd"), // 13
|
|
|
|
UnicodeString("Ed"), // 14
|
|
|
|
UnicodeString("jmmssSSS"), // 15
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("JJmm"), // 16
|
2007-08-11 20:32:54 +00:00
|
|
|
UnicodeString(),
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2008-11-19 04:19:02 +00:00
|
|
|
const char* testLocale[MAX_LOCALE][4] = {
|
2010-10-20 22:06:10 +00:00
|
|
|
{"en", "US", "", ""}, // 0
|
|
|
|
{"en", "US", "", "calendar=japanese"}, // 1
|
|
|
|
{"de", "DE", "", ""}, // 2
|
|
|
|
{"fi", "", "", ""}, // 3
|
2011-12-05 04:49:40 +00:00
|
|
|
{"es", "", "", ""}, // 4
|
|
|
|
{"ja", "", "", ""}, // 5
|
|
|
|
{"ja", "", "", "calendar=japanese"}, // 6
|
|
|
|
{"zh", "Hans", "CN", ""}, // 7
|
|
|
|
{"zh", "TW", "", "calendar=roc"}, // 8
|
|
|
|
{"ru", "", "", ""}, // 9
|
2012-02-17 08:42:10 +00:00
|
|
|
{"zh", "", "", "calendar=chinese"}, // 10
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2010-10-20 22:06:10 +00:00
|
|
|
// For Weds, Jan 13, 1999, 23:58:59
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString patternResults[] = {
|
2010-10-20 22:06:10 +00:00
|
|
|
// en_US // 0 en_US
|
|
|
|
UnicodeString("1/1999"), // 00: yM
|
|
|
|
UnicodeString("Jan 1999"), // 01: yMMM
|
|
|
|
UnicodeString("1/13/1999"), // 02: yMd
|
|
|
|
UnicodeString("Jan 13, 1999"), // 03: yMMMd
|
|
|
|
UnicodeString("1/13"), // 04: Md
|
|
|
|
UnicodeString("Jan 13"), // 05: MMMd
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("January 13"), // 06: MMMMd
|
|
|
|
UnicodeString("Q1 1999"), // 07: yQQQ
|
|
|
|
UnicodeString("11:58 PM"), // 08: hhmm
|
|
|
|
UnicodeString("23:58"), // 09: HHmm
|
|
|
|
UnicodeString("11:58 PM"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss
|
|
|
|
UnicodeString("January 1999"), // 12: yyyyMMMM
|
|
|
|
UnicodeString("Wed, Jan 13"), // 13: MMMEd -> EEE, MMM d
|
|
|
|
UnicodeString("13 Wed"), // 14: Ed -> d EEE
|
|
|
|
UnicodeString("11:58:59.123 PM"), // 15: jmmssSSS -> "h:mm:ss.SSS a"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("11:58"), // 16: JJmm
|
2010-10-20 22:06:10 +00:00
|
|
|
|
|
|
|
// en_US@calendar=japanese // 1 en_US@calendar=japanese
|
2011-03-12 14:57:18 +00:00
|
|
|
UnicodeString("1/11 H"), // 0: yM
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString("Jan 11 Heisei"), // 1: yMMM
|
2011-03-12 14:57:18 +00:00
|
|
|
UnicodeString("1/13/11 H"), // 2: yMd
|
|
|
|
UnicodeString("Jan 13, 11 Heisei"), // 3: yMMMd
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString("1/13"), // 4: Md
|
|
|
|
UnicodeString("Jan 13"), // 5: MMMd
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("January 13"), // 6: MMMMd
|
|
|
|
UnicodeString("Q1 11 Heisei"), // 7: yQQQ
|
|
|
|
UnicodeString("11:58 PM"), // 8: hhmm
|
|
|
|
UnicodeString("23:58"), // 9: HHmm
|
|
|
|
UnicodeString("11:58 PM"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss
|
|
|
|
UnicodeString("January 11 Heisei"), // 12: yyyyMMMM
|
|
|
|
UnicodeString("Wed, Jan 13"), // 13: MMMEd -> EEE, MMM d"
|
|
|
|
UnicodeString("13 Wed"), // 14: Ed -> d EEE
|
|
|
|
UnicodeString("11:58:59.123 PM"), // 15: jmmssSSS -> "h:mm:ss.SSS a"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("11:58"), // 16: JJmm
|
2008-11-19 04:19:02 +00:00
|
|
|
|
2010-10-20 22:06:10 +00:00
|
|
|
// de_DE // 2 de_DE
|
|
|
|
UnicodeString("1.1999"), // 00: yM
|
2012-08-28 21:56:06 +00:00
|
|
|
UnicodeString("Jan. 1999"), // 01: yMMM
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString("13.1.1999"), // 02: yMd
|
2012-08-28 21:56:06 +00:00
|
|
|
UnicodeString("13. Jan. 1999"), // 03: yMMMd
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString("13.1."), // 04: Md
|
2012-08-28 21:56:06 +00:00
|
|
|
UnicodeString("13. Jan."), // 05: MMMd
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("13. Januar"), // 06: MMMMd
|
|
|
|
UnicodeString("Q1 1999"), // 07: yQQQ
|
|
|
|
UnicodeString("11:58 nachm."), // 08: hhmm
|
|
|
|
UnicodeString("23:58"), // 09: HHmm
|
|
|
|
UnicodeString("23:58"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss
|
|
|
|
UnicodeString("Januar 1999"), // 12: yyyyMMMM
|
2012-08-28 21:56:06 +00:00
|
|
|
UnicodeString("Mi., 13. Jan."), // 13: MMMEd -> EEE, d. MMM
|
2012-02-02 22:53:19 +00:00
|
|
|
UnicodeString("Mi., 13."), // 14: Ed -> EEE d.
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("23:58:59,123"), // 15: jmmssSSS -> "HH:mm:ss,SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("23:58"), // 16: JJmm
|
2008-12-19 20:10:03 +00:00
|
|
|
|
2010-10-20 22:06:10 +00:00
|
|
|
// fi // 3 fi
|
|
|
|
UnicodeString("1.1999"), // 00: yM (fixed expected result per ticket:6626:)
|
|
|
|
UnicodeString("tammi 1999"), // 01: yMMM
|
|
|
|
UnicodeString("13.1.1999"), // 02: yMd
|
|
|
|
UnicodeString("13. tammikuuta 1999"), // 03: yMMMd
|
|
|
|
UnicodeString("13.1."), // 04: Md
|
|
|
|
UnicodeString("13. tammikuuta"), // 05: MMMd
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("13. tammikuuta"), // 06: MMMMd
|
|
|
|
UnicodeString("1. nelj. 1999"), // 07: yQQQ
|
|
|
|
UnicodeString("11.58 ip."), // 08: hhmm
|
|
|
|
UnicodeString("23.58"), // 09: HHmm
|
|
|
|
UnicodeString("23.58"), // 10: jjmm
|
|
|
|
UnicodeString("58.59"), // 11: mmss
|
|
|
|
UnicodeString("tammikuu 1999"), // 12: yyyyMMMM
|
|
|
|
UnicodeString("ke 13. tammikuuta"), // 13: MMMEd -> EEE d. MMM
|
|
|
|
UnicodeString("ke 13."), // 14: Ed -> ccc d.
|
|
|
|
UnicodeString("23.58.59,123"), // 15: jmmssSSS -> "H.mm.ss,SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("23.58"), // 16: JJmm
|
2011-12-05 04:49:40 +00:00
|
|
|
|
|
|
|
// es // 4 es
|
|
|
|
UnicodeString("1/1999"), // 00: yM -> "M/y"
|
2015-03-06 22:58:33 +00:00
|
|
|
UnicodeString("ene. 1999"), // 01: yMMM -> "MMM y"
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("13/1/1999"), // 02: yMd -> "d/M/y"
|
2015-03-06 22:58:33 +00:00
|
|
|
UnicodeString("13 ene. 1999"), // 03: yMMMd -> "d MMM y"
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("13/1"), // 04: Md -> "d/M"
|
2015-03-06 22:58:33 +00:00
|
|
|
UnicodeString("13 ene."), // 05: MMMd -> "d 'de' MMM"
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("13 de enero"), // 06: MMMMd -> "d 'de' MMMM"
|
|
|
|
UnicodeString("T1 1999"), // 07: yQQQ -> "QQQ y"
|
2013-09-07 20:46:42 +00:00
|
|
|
UnicodeString("11:58 p. m."), // 08: hhmm -> "hh:mm a"
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("23:58"), // 09: HHmm -> "HH:mm"
|
|
|
|
UnicodeString("23:58"), // 10: jjmm -> "HH:mm"
|
|
|
|
UnicodeString("58:59"), // 11: mmss -> "mm:ss"
|
|
|
|
UnicodeString("enero de 1999"), // 12: yyyyMMMM -> "MMMM 'de' yyyy"
|
2015-03-06 22:58:33 +00:00
|
|
|
CharsToUnicodeString("mi\\u00E9., 13 ene."), // 13: MMMEd -> "E, d MMM"
|
2013-09-07 20:46:42 +00:00
|
|
|
CharsToUnicodeString("mi\\u00E9. 13"), // 14: Ed -> "EEE d"
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("23:58:59,123"), // 15: jmmssSSS -> "H:mm:ss,SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("23:58"), // 16: JJmm
|
2011-12-05 04:49:40 +00:00
|
|
|
|
|
|
|
// ja // 5 ja
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString("1999/1"), // 00: yM -> y/M
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // 01: yMMM -> y\u5E74M\u6708
|
|
|
|
UnicodeString("1999/1/13"), // 02: yMd -> y/M/d
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> y\u5E74M\u6708d\u65E5
|
|
|
|
UnicodeString("1/13"), // 04: Md -> M/d
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd -> M\u6708d\u65E5
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd -> M\u6708d\u65E5
|
2013-09-07 20:46:42 +00:00
|
|
|
CharsToUnicodeString("1999/Q1"), // 07: yQQQ -> y/QQQ
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("\\u5348\\u5F8C11:58"), // 08: hhmm
|
|
|
|
UnicodeString("23:58"), // 09: HHmm -> HH:mm
|
|
|
|
UnicodeString("23:58"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss -> mm:ss
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // 12: yyyyMMMM -> y\u5E74M\u6708
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5(\\u6C34)"), // 13: MMMEd -> M\u6708d\u65E5(EEE)
|
|
|
|
CharsToUnicodeString("13\\u65E5(\\u6C34)"), // 14: Ed -> d\u65E5(EEE)
|
|
|
|
UnicodeString("23:58:59.123"), // 15: jmmssSSS -> "H:mm:ss.SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("23:58"), // 16: JJmm
|
2011-12-05 04:49:40 +00:00
|
|
|
|
|
|
|
// ja@calendar=japanese // 6 ja@calendar=japanese
|
2010-10-20 22:06:10 +00:00
|
|
|
CharsToUnicodeString("\\u5E73\\u621011/1"), // 00: yM -> Gy/m
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u6708"), // 01: yMMM -> Gy\u5E74M\u6708
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011/1/13"), // 02: yMd -> Gy/m/d
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> Gy\u5E74M\u6708d\u65E5
|
|
|
|
UnicodeString("1/13"), // 04: Md -> M/d
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd -> M\u6708d\u65E5
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd -> M\u6708d\u65E5
|
2014-09-02 23:18:20 +00:00
|
|
|
CharsToUnicodeString("\\u5E73\\u621011/Q1"), // 07: yQQQ -> Gy/QQQ
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("\\u5348\\u5F8C11:58"), // 08: hhmm ->
|
|
|
|
UnicodeString("23:58"), // 09: HHmm -> HH:mm (as for ja)
|
|
|
|
UnicodeString("23:58"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss -> mm:ss (as for ja)
|
2013-02-14 09:51:25 +00:00
|
|
|
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u6708"), // 12: yyyyMMMM -> Gyyyy\u5E74M\u6708
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5(\\u6C34)"), // 13: MMMEd -> M\u6708d\u65E5(EEE)
|
|
|
|
CharsToUnicodeString("13\\u65E5(\\u6C34)"), // 14: Ed -> d\u65E5(EEE)
|
|
|
|
UnicodeString("23:58:59.123"), // 15: jmmssSSS -> "H:mm:ss.SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("23:58"), // 16: JJmm
|
2011-12-05 04:49:40 +00:00
|
|
|
|
|
|
|
// zh_Hans_CN // 7 zh_Hans_CN
|
2014-09-02 23:18:20 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // 00: yM -> y\u5E74M\u6708
|
2010-10-20 22:06:10 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // 01: yMMM -> yyyy\u5E74MMM (fixed expected result per ticket:6626:)
|
2012-08-28 21:56:06 +00:00
|
|
|
CharsToUnicodeString("1999/1/13"), // 02: yMd
|
2010-10-20 22:06:10 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> yyyy\u5E74MMMd\u65E5 (fixed expected result per ticket:6626:)
|
2012-08-28 21:56:06 +00:00
|
|
|
UnicodeString("1/13"), // 04: Md
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd -> M\u6708d\u65E5 (fixed expected result per ticket:6626:)
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd -> M\u6708d\u65E5
|
2012-10-19 03:36:01 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E74\\u7B2C1\\u5B63\\u5EA6"), // 07: yQQQ
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 08: hhmm
|
|
|
|
UnicodeString("23:58"), // 09: HHmm
|
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // 12: yyyyMMMM -> yyyy\u5E74MMM
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5\\u5468\\u4E09"), // 13: MMMEd -> MMMd\u65E5EEE
|
|
|
|
CharsToUnicodeString("13\\u65E5\\u5468\\u4E09"), // 14: Ed -> d\u65E5EEE
|
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58:59.123"), // 15: jmmssSSS -> "ah:mm:ss.SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("11:58"), // 16: JJmm
|
2011-12-05 04:49:40 +00:00
|
|
|
|
2016-02-27 00:41:21 +00:00
|
|
|
// zh_TW@calendar=roc // 8 zh_TW@calendar=roc
|
2010-10-20 22:06:10 +00:00
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88/1"), // 00: yM -> Gy/M
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u6708"), // 01: yMMM -> Gy\u5E74M\u6708
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88/1/13"), // 02: yMd -> Gy/M/d
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u670813\\u65E5"), // 03: yMMMd -> Gy\u5E74M\u6708d\u65E5
|
|
|
|
UnicodeString("1/13"), // 04: Md -> M/d
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 05: MMMd ->M\u6708d\u65E5
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // 06: MMMMd ->M\u6708d\u65E5
|
2013-02-19 19:52:15 +00:00
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u5B63"), // 07: yQQQ -> Gy QQQ
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 08: hhmm ->
|
|
|
|
UnicodeString("23:58"), // 09: HHmm ->
|
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss ->
|
2013-02-14 09:51:25 +00:00
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u6708"), // 12: yyyyMMMM -> Gy\u5E74M\u670
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5\\u9031\\u4E09"), // 13: MMMEd -> M\u6708d\u65E5EEE
|
2012-02-02 22:53:19 +00:00
|
|
|
CharsToUnicodeString("13\\u65E5\\uff08\\u9031\\u4E09\\uff09"), // 14: Ed -> d\u65E5\\uff08EEEi\\uff09
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58:59.123"), // 15: jmmssSSS -> "ah:mm:ss.SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("11:58"), // 16: JJmm
|
2011-12-05 04:49:40 +00:00
|
|
|
|
|
|
|
// ru // 9 ru
|
2012-02-02 22:53:19 +00:00
|
|
|
UnicodeString("01.1999"), // 00: yM -> MM.y
|
2015-08-27 20:23:27 +00:00
|
|
|
CharsToUnicodeString("\\u044F\\u043D\\u0432. 1999 \\u0433."), // 01: yMMM -> LLL y
|
2013-03-04 11:10:20 +00:00
|
|
|
UnicodeString("13.01.1999"), // 02: yMd -> dd.MM.y
|
2012-10-19 03:36:01 +00:00
|
|
|
CharsToUnicodeString("13 \\u044F\\u043D\\u0432. 1999 \\u0433."), // 03: yMMMd -> d MMM y
|
2013-03-04 11:10:20 +00:00
|
|
|
UnicodeString("13.01"), // 04: Md -> dd.MM
|
2012-02-02 22:53:19 +00:00
|
|
|
CharsToUnicodeString("13 \\u044F\\u043D\\u0432."), // 05: MMMd -> d MMM
|
2011-12-05 04:49:40 +00:00
|
|
|
CharsToUnicodeString("13 \\u044F\\u043D\\u0432\\u0430\\u0440\\u044F"), // 06: MMMMd -> d MMMM
|
2012-10-19 03:36:01 +00:00
|
|
|
CharsToUnicodeString("1-\\u0439 \\u043A\\u0432. 1999 \\u0433."), // 07: yQQQ -> y QQQ
|
2015-08-27 20:23:27 +00:00
|
|
|
CharsToUnicodeString("11:58 \\u041F\\u041F"), // 08: hhmm -> hh:mm a
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("23:58"), // 09: HHmm -> HH:mm
|
|
|
|
UnicodeString("23:58"), // 10: jjmm -> HH:mm
|
|
|
|
UnicodeString("58:59"), // 11: mmss -> mm:ss
|
2015-08-27 20:23:27 +00:00
|
|
|
CharsToUnicodeString("\\u044F\\u043D\\u0432\\u0430\\u0440\\u044C 1999 \\u0433."), // 12: yyyyMMMM -> LLLL y
|
|
|
|
CharsToUnicodeString("\\u0441\\u0440, 13 \\u044F\\u043D\\u0432."), // 13: MMMEd -> ccc, d MMM
|
|
|
|
CharsToUnicodeString("\\u0441\\u0440, 13"), // 14: Ed -> EEE, d
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("23:58:59,123"), // 15: jmmssSSS -> "H:mm:ss,SSS"
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("23:58"), // 16: JJmm
|
2009-01-16 01:18:05 +00:00
|
|
|
|
2012-02-17 08:42:10 +00:00
|
|
|
// zh@calendar=chinese // 10 zh@calendar=chinese
|
2015-02-23 16:47:52 +00:00
|
|
|
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u51AC\\u6708"), // 00: yMMM
|
|
|
|
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u51AC\\u6708"), // 01: yMMM
|
|
|
|
CharsToUnicodeString("1998\\u5E74\\u51AC\\u670826"), // 02: yMMMd
|
|
|
|
CharsToUnicodeString("1998\\u5E74\\u51AC\\u670826"), // 03: yMMMd
|
2012-02-17 08:42:10 +00:00
|
|
|
UnicodeString("11-26"), // 04: Md
|
2014-02-24 07:17:41 +00:00
|
|
|
CharsToUnicodeString("\\u51AC\\u670826\\u65E5"), // 05: MMMd
|
|
|
|
CharsToUnicodeString("\\u51AC\\u670826\\u65E5"), // 06: MMMMd
|
2015-02-23 16:47:52 +00:00
|
|
|
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u7b2c\\u56db\\u5B63\\u5EA6"), // 07: yQQQ
|
2012-02-17 08:42:10 +00:00
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 08: hhmm
|
|
|
|
UnicodeString("23:58"), // 09: HHmm
|
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // 10: jjmm
|
|
|
|
UnicodeString("58:59"), // 11: mmss
|
2015-02-23 16:47:52 +00:00
|
|
|
CharsToUnicodeString("1998\\u620A\\u5BC5\\u5E74\\u51AC\\u6708"), // 12: yyyyMMMM
|
2014-02-24 07:17:41 +00:00
|
|
|
CharsToUnicodeString("\\u51AC\\u670826\\u65E5\\u5468\\u4E09"), // 13: MMMEd
|
2012-02-17 08:42:10 +00:00
|
|
|
CharsToUnicodeString("26\\u65E5\\u5468\\u4E09"), // 14: Ed -> d\u65E5EEE
|
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58:59.123"), // 15: jmmssSS
|
2013-09-12 22:49:07 +00:00
|
|
|
UnicodeString("11:58"), // 16: JJmm
|
2012-02-17 08:42:10 +00:00
|
|
|
|
2007-08-11 20:32:54 +00:00
|
|
|
UnicodeString(),
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
|
|
|
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString patternTests2[] = {
|
|
|
|
UnicodeString("yyyyMMMdd"),
|
2009-04-22 16:29:27 +00:00
|
|
|
UnicodeString("yyyyqqqq"),
|
2008-08-07 17:06:38 +00:00
|
|
|
UnicodeString("yMMMdd"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("EyyyyMMMdd"),
|
|
|
|
UnicodeString("yyyyMMdd"),
|
|
|
|
UnicodeString("yyyyMMM"),
|
|
|
|
UnicodeString("yyyyMM"),
|
|
|
|
UnicodeString("yyMM"),
|
2008-06-11 16:31:33 +00:00
|
|
|
UnicodeString("yMMMMMd"),
|
|
|
|
UnicodeString("EEEEEMMMMMd"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("MMMd"),
|
|
|
|
UnicodeString("MMMdhmm"),
|
|
|
|
UnicodeString("EMMMdhmms"),
|
|
|
|
UnicodeString("MMdhmm"),
|
|
|
|
UnicodeString("EEEEMMMdhmms"),
|
|
|
|
UnicodeString("yyyyMMMddhhmmss"),
|
|
|
|
UnicodeString("EyyyyMMMddhhmmss"),
|
|
|
|
UnicodeString("hmm"),
|
|
|
|
UnicodeString("hhmm"),
|
2009-04-22 16:29:27 +00:00
|
|
|
UnicodeString("hhmmVVVV"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString(""),
|
|
|
|
};
|
|
|
|
UnicodeString patternResults2[] = {
|
2008-08-07 17:06:38 +00:00
|
|
|
UnicodeString("Oct 14, 1999"),
|
2009-04-22 16:29:27 +00:00
|
|
|
UnicodeString("4th quarter 1999"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("Oct 14, 1999"),
|
|
|
|
UnicodeString("Thu, Oct 14, 1999"),
|
|
|
|
UnicodeString("10/14/1999"),
|
|
|
|
UnicodeString("Oct 1999"),
|
|
|
|
UnicodeString("10/1999"),
|
|
|
|
UnicodeString("10/99"),
|
2008-08-07 17:06:38 +00:00
|
|
|
UnicodeString("O 14, 1999"),
|
2008-06-11 16:31:33 +00:00
|
|
|
UnicodeString("T, O 14"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("Oct 14"),
|
2012-08-28 21:56:06 +00:00
|
|
|
UnicodeString("Oct 14, 6:58 AM"),
|
|
|
|
UnicodeString("Thu, Oct 14, 6:58:59 AM"),
|
|
|
|
UnicodeString("10/14, 6:58 AM"),
|
|
|
|
UnicodeString("Thursday, Oct 14, 6:58:59 AM"),
|
|
|
|
UnicodeString("Oct 14, 1999, 6:58:59 AM"),
|
|
|
|
UnicodeString("Thu, Oct 14, 1999, 6:58:59 AM"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("6:58 AM"),
|
2009-12-10 09:13:49 +00:00
|
|
|
UnicodeString("6:58 AM"),
|
2011-05-03 14:59:01 +00:00
|
|
|
UnicodeString("6:58 AM GMT"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString(""),
|
|
|
|
};
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 07:22:18 +00:00
|
|
|
// results for getSkeletons() and getPatternForSkeleton()
|
2016-02-27 00:41:21 +00:00
|
|
|
const UnicodeString testSkeletonsResults[] = {
|
|
|
|
UnicodeString("HH:mm"),
|
|
|
|
UnicodeString("MMMMd"),
|
|
|
|
UnicodeString("MMMMMdd"),
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
2016-02-27 00:41:21 +00:00
|
|
|
|
|
|
|
const UnicodeString testBaseSkeletonsResults[] = {
|
|
|
|
UnicodeString("Hm"),
|
|
|
|
UnicodeString("MMMMd"),
|
2011-12-05 04:49:40 +00:00
|
|
|
UnicodeString("MMMMMd"),
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeString newDecimal(" "); // space
|
|
|
|
UnicodeString newAppendItemName("hrs.");
|
|
|
|
UnicodeString newAppendItemFormat("{1} {0}");
|
|
|
|
UnicodeString newDateTimeFormat("{1} {0}");
|
2007-08-03 18:43:04 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UnicodeString conflictingPattern;
|
2013-03-21 01:42:01 +00:00
|
|
|
UDateTimePatternConflict conflictingStatus = UDATPG_NO_CONFLICT;
|
|
|
|
(void)conflictingStatus; // Suppress set but not used warning.
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
// ======= Test CreateInstance with default locale
|
|
|
|
logln("Testing DateTimePatternGenerator createInstance from default locale");
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
DateTimePatternGenerator *instFromDefaultLocale=DateTimePatternGenerator::createInstance(status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (default) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete instFromDefaultLocale;
|
|
|
|
}
|
|
|
|
|
2016-02-27 00:41:21 +00:00
|
|
|
// ======= Test CreateInstance with given locale
|
2007-08-03 18:43:04 +00:00
|
|
|
logln("Testing DateTimePatternGenerator createInstance from French locale");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
DateTimePatternGenerator *instFromLocale=DateTimePatternGenerator::createInstance(Locale::getFrench(), status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-27 00:41:21 +00:00
|
|
|
// ======= Test clone DateTimePatternGenerator
|
2007-08-03 18:43:04 +00:00
|
|
|
logln("Testing DateTimePatternGenerator::clone()");
|
|
|
|
status = U_ZERO_ERROR;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
UnicodeString decimalSymbol = instFromLocale->getDecimal();
|
|
|
|
UnicodeString newDecimalSymbol = UnicodeString("*");
|
|
|
|
decimalSymbol = instFromLocale->getDecimal();
|
|
|
|
instFromLocale->setDecimal(newDecimalSymbol);
|
|
|
|
DateTimePatternGenerator *cloneDTPatternGen=instFromLocale->clone();
|
|
|
|
decimalSymbol = cloneDTPatternGen->getDecimal();
|
|
|
|
if (decimalSymbol != newDecimalSymbol) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: inconsistency is found in cloned object.");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2007-08-07 23:16:36 +00:00
|
|
|
if ( !(*cloneDTPatternGen == *instFromLocale) ) {
|
|
|
|
errln("ERROR: inconsistency is found in cloned object.");
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 23:16:36 +00:00
|
|
|
if ( *cloneDTPatternGen != *instFromLocale ) {
|
|
|
|
errln("ERROR: inconsistency is found in cloned object.");
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
delete instFromLocale;
|
|
|
|
delete cloneDTPatternGen;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
|
|
|
// ======= Test simple use cases
|
2007-08-03 18:43:04 +00:00
|
|
|
logln("Testing simple use cases");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
Locale deLocale=Locale::getGermany();
|
|
|
|
UDate sampleDate=LocaleTest::date(99, 9, 13, 23, 58, 59);
|
|
|
|
DateTimePatternGenerator *gen = DateTimePatternGenerator::createInstance(deLocale, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getGermany()) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
UnicodeString findPattern = gen->getBestPattern(UnicodeString("MMMddHmm"), status);
|
|
|
|
SimpleDateFormat *format = new SimpleDateFormat(findPattern, deLocale, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create SimpleDateFormat (Locale::getGermany())");
|
2007-08-26 20:10:45 +00:00
|
|
|
delete gen;
|
|
|
|
return;
|
2007-08-07 03:14:19 +00:00
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
TimeZone *zone = TimeZone::createTimeZone(UnicodeString("ECT"));
|
2007-08-26 20:10:45 +00:00
|
|
|
if (zone==NULL) {
|
2007-08-07 03:14:19 +00:00
|
|
|
dataerrln("ERROR: Could not create TimeZone ECT");
|
2007-08-26 20:10:45 +00:00
|
|
|
delete gen;
|
|
|
|
delete format;
|
|
|
|
return;
|
2007-08-07 03:14:19 +00:00
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
format->setTimeZone(*zone);
|
|
|
|
UnicodeString dateReturned, expectedResult;
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2014-09-02 23:18:20 +00:00
|
|
|
expectedResult=UnicodeString("14. Okt., 08:58", -1, US_INV);
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test in getBestPattern with Locale::getGermany()).");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
// add new pattern
|
2007-08-07 03:14:19 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2016-02-27 00:41:21 +00:00
|
|
|
conflictingStatus = gen->addPattern(UnicodeString("d'. von' MMMM", -1, US_INV), true, conflictingPattern, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("ERROR: Could not addPattern - d\'. von\' MMMM");
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
UnicodeString testPattern=gen->getBestPattern(UnicodeString("MMMMdd"), status);
|
|
|
|
testPattern=gen->getBestPattern(UnicodeString("MMMddHmm"), status);
|
2010-03-04 05:41:47 +00:00
|
|
|
format->applyPattern(gen->getBestPattern(UnicodeString("MMMMdHmm"), status));
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2014-09-02 23:18:20 +00:00
|
|
|
expectedResult=UnicodeString("14. von Oktober, 08:58", -1, US_INV);
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2010-03-04 05:41:47 +00:00
|
|
|
errln(UnicodeString("ERROR: Simple test addPattern failed!: d\'. von\' MMMM Got: ") + dateReturned + UnicodeString(" Expected: ") + expectedResult);
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
delete format;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// get a pattern and modify it
|
2016-02-27 00:41:21 +00:00
|
|
|
format = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull,
|
2007-08-03 18:43:04 +00:00
|
|
|
deLocale);
|
|
|
|
format->setTimeZone(*zone);
|
|
|
|
UnicodeString pattern;
|
|
|
|
pattern = format->toPattern(pattern);
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2014-09-02 23:18:20 +00:00
|
|
|
expectedResult=CharsToUnicodeString("Donnerstag, 14. Oktober 1999 um 08:58:59 Mitteleurop\\u00E4ische Sommerzeit");
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test uses full date format.");
|
|
|
|
errln(UnicodeString(" Got: ") + dateReturned + UnicodeString(" Expected: ") + expectedResult);
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
|
|
|
// modify it to change the zone.
|
2007-08-03 18:43:04 +00:00
|
|
|
UnicodeString newPattern = gen->replaceFieldTypes(pattern, UnicodeString("vvvv"), status);
|
|
|
|
format->applyPattern(newPattern);
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2014-09-02 23:18:20 +00:00
|
|
|
expectedResult=CharsToUnicodeString("Donnerstag, 14. Oktober 1999 um 08:58:59 Mitteleurop\\u00E4ische Zeit");
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test modify the timezone!");
|
|
|
|
errln(UnicodeString(" Got: ")+ dateReturned + UnicodeString(" Expected: ") + expectedResult);
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// setDeciaml(), getDeciaml()
|
|
|
|
gen->setDecimal(newDecimal);
|
|
|
|
if (newDecimal != gen->getDecimal()) {
|
|
|
|
errln("ERROR: unexpected result from setDecimal() and getDecimal()!.\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// setAppenItemName() , getAppendItemName()
|
|
|
|
gen->setAppendItemName(UDATPG_HOUR_FIELD, newAppendItemName);
|
|
|
|
if (newAppendItemName != gen->getAppendItemName(UDATPG_HOUR_FIELD)) {
|
|
|
|
errln("ERROR: unexpected result from setAppendItemName() and getAppendItemName()!.\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// setAppenItemFormat() , getAppendItemFormat()
|
|
|
|
gen->setAppendItemFormat(UDATPG_HOUR_FIELD, newAppendItemFormat);
|
|
|
|
if (newAppendItemFormat != gen->getAppendItemFormat(UDATPG_HOUR_FIELD)) {
|
|
|
|
errln("ERROR: unexpected result from setAppendItemFormat() and getAppendItemFormat()!.\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// setDateTimeFormat() , getDateTimeFormat()
|
|
|
|
gen->setDateTimeFormat(newDateTimeFormat);
|
|
|
|
if (newDateTimeFormat != gen->getDateTimeFormat()) {
|
|
|
|
errln("ERROR: unexpected result from setDateTimeFormat() and getDateTimeFormat()!.\n");
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 23:16:36 +00:00
|
|
|
// ======== Test getSkeleton and getBaseSkeleton
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pattern = UnicodeString("dd-MMM");
|
|
|
|
UnicodeString expectedSkeleton = UnicodeString("MMMdd");
|
|
|
|
UnicodeString expectedBaseSkeleton = UnicodeString("MMMd");
|
|
|
|
UnicodeString retSkeleton = gen->getSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
|
|
|
|
errln("ERROR: Unexpected result from getSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
|
|
|
|
}
|
|
|
|
retSkeleton = gen->getBaseSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
|
|
|
|
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
|
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
|
2007-08-07 23:16:36 +00:00
|
|
|
pattern = UnicodeString("dd/MMMM/yy");
|
|
|
|
expectedSkeleton = UnicodeString("yyMMMMdd");
|
2011-12-05 04:49:40 +00:00
|
|
|
expectedBaseSkeleton = UnicodeString("yMMMMd");
|
2007-08-07 23:16:36 +00:00
|
|
|
retSkeleton = gen->getSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
|
|
|
|
errln("ERROR: Unexpected result from getSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
|
|
|
|
}
|
|
|
|
retSkeleton = gen->getBaseSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
|
|
|
|
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
|
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
delete format;
|
|
|
|
delete zone;
|
|
|
|
delete gen;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2008-01-03 01:40:16 +00:00
|
|
|
{
|
|
|
|
// Trac# 6104
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pattern = UnicodeString("YYYYMMM");
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString expR = CharsToUnicodeString("1999\\u5E741\\u6708"); // fixed expected result per ticket:6626:
|
2008-01-03 01:40:16 +00:00
|
|
|
Locale loc("ja");
|
|
|
|
UDate testDate1= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
|
|
|
|
UnicodeString rDate;
|
|
|
|
SimpleDateFormat sdf(bPattern, loc, status);
|
|
|
|
rDate.remove();
|
|
|
|
rDate = sdf.format(testDate1, rDate);
|
|
|
|
|
|
|
|
logln(UnicodeString(" ja locale with skeleton: YYYYMMM Best Pattern:") + bPattern);
|
|
|
|
logln(UnicodeString(" Formatted date:") + rDate);
|
|
|
|
|
|
|
|
if ( expR!= rDate ) {
|
2016-02-27 00:41:21 +00:00
|
|
|
errln(UnicodeString("\nERROR: Test Japanese month hack Got: ") + rDate +
|
2008-01-03 01:40:16 +00:00
|
|
|
UnicodeString(" Expected: ") + expR );
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2008-01-03 01:40:16 +00:00
|
|
|
delete patGen;
|
|
|
|
}
|
|
|
|
{ // Trac# 6104
|
|
|
|
Locale loc("zh");
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString expR = CharsToUnicodeString("1999\\u5E741\\u6708"); // fixed expected result per ticket:6626:
|
2008-01-03 01:40:16 +00:00
|
|
|
UDate testDate1= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
|
|
|
|
UnicodeString rDate;
|
|
|
|
SimpleDateFormat sdf(bPattern, loc, status);
|
|
|
|
rDate.remove();
|
|
|
|
rDate = sdf.format(testDate1, rDate);
|
|
|
|
|
|
|
|
logln(UnicodeString(" zh locale with skeleton: YYYYMMM Best Pattern:") + bPattern);
|
|
|
|
logln(UnicodeString(" Formatted date:") + rDate);
|
|
|
|
if ( expR!= rDate ) {
|
2016-02-27 00:41:21 +00:00
|
|
|
errln(UnicodeString("\nERROR: Test Chinese month hack Got: ") + rDate +
|
2008-01-03 01:40:16 +00:00
|
|
|
UnicodeString(" Expected: ") + expR );
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
delete patGen;
|
2008-01-03 01:40:16 +00:00
|
|
|
}
|
2008-02-08 07:10:28 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Trac# 6172 duplicate time pattern
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pattern = UnicodeString("hmv");
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString expR = UnicodeString("h:mm a v"); // avail formats has hm -> "h:mm a" (fixed expected result per ticket:6626:)
|
2008-02-08 07:10:28 +00:00
|
|
|
Locale loc("en");
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
|
|
|
|
logln(UnicodeString(" en locale with skeleton: hmv Best Pattern:") + bPattern);
|
|
|
|
|
|
|
|
if ( expR!= bPattern ) {
|
2016-02-27 00:41:21 +00:00
|
|
|
errln(UnicodeString("\nERROR: Test EN time format Got: ") + bPattern +
|
2008-02-08 07:10:28 +00:00
|
|
|
UnicodeString(" Expected: ") + expR );
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2008-02-08 07:10:28 +00:00
|
|
|
delete patGen;
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// ======= Test various skeletons.
|
|
|
|
logln("Testing DateTimePatternGenerator with various skeleton");
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
int32_t localeIndex=0;
|
|
|
|
int32_t resultIndex=0;
|
|
|
|
UnicodeString resultDate;
|
2011-02-10 04:46:32 +00:00
|
|
|
UDate testDate= LocaleTest::date(99, 0, 13, 23, 58, 59) + 123.0;
|
2007-08-03 18:43:04 +00:00
|
|
|
while (localeIndex < MAX_LOCALE )
|
2016-02-27 00:41:21 +00:00
|
|
|
{
|
2007-08-03 18:43:04 +00:00
|
|
|
int32_t dataIndex=0;
|
|
|
|
UnicodeString bestPattern;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2008-11-19 04:19:02 +00:00
|
|
|
Locale loc(testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], testLocale[localeIndex][3]);
|
|
|
|
logln("\n\n Locale: %s_%s_%s@%s", testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], testLocale[localeIndex][3]);
|
2007-08-03 18:43:04 +00:00
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
2007-08-07 03:14:19 +00:00
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale index:%d . - exitting\n", localeIndex);
|
|
|
|
return;
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
while (patternData[dataIndex].length() > 0) {
|
2007-08-11 20:32:54 +00:00
|
|
|
log(patternData[dataIndex]);
|
2007-08-03 18:43:04 +00:00
|
|
|
bestPattern = patGen->getBestPattern(patternData[dataIndex++], status);
|
2007-08-11 20:32:54 +00:00
|
|
|
logln(UnicodeString(" -> ") + bestPattern);
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 07:22:18 +00:00
|
|
|
SimpleDateFormat sdf(bestPattern, loc, status);
|
2007-08-11 20:32:54 +00:00
|
|
|
resultDate.remove();
|
2007-08-07 07:22:18 +00:00
|
|
|
resultDate = sdf.format(testDate, resultDate);
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( resultDate != patternResults[resultIndex] ) {
|
2008-11-18 18:27:40 +00:00
|
|
|
errln(UnicodeString("\nERROR: Test various skeletons[") + (dataIndex-1) + UnicodeString("], localeIndex ") + localeIndex +
|
2010-10-20 22:06:10 +00:00
|
|
|
UnicodeString(". Got: \"") + resultDate + UnicodeString("\" Expected: \"") + patternResults[resultIndex] + "\"" );
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
resultIndex++;
|
|
|
|
}
|
|
|
|
delete patGen;
|
|
|
|
localeIndex++;
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-12-22 05:30:33 +00:00
|
|
|
// ======= More tests ticket#6110
|
|
|
|
logln("Testing DateTimePatternGenerator with various skeleton");
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-12-22 05:30:33 +00:00
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
localeIndex=0;
|
|
|
|
resultIndex=0;
|
|
|
|
testDate= LocaleTest::date(99, 9, 13, 23, 58, 59);
|
2016-02-27 00:41:21 +00:00
|
|
|
{
|
2007-12-22 05:30:33 +00:00
|
|
|
int32_t dataIndex=0;
|
|
|
|
UnicodeString bestPattern;
|
|
|
|
logln("\n\n Test various skeletons for English locale...");
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(Locale::getEnglish(), status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale English . - exitting\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TimeZone *enZone = TimeZone::createTimeZone(UnicodeString("ECT/GMT"));
|
|
|
|
if (enZone==NULL) {
|
|
|
|
dataerrln("ERROR: Could not create TimeZone ECT");
|
|
|
|
delete patGen;
|
|
|
|
return;
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
SimpleDateFormat *enFormat = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull,
|
2007-12-22 05:30:33 +00:00
|
|
|
DateFormat::kFull, Locale::getEnglish());
|
|
|
|
enFormat->setTimeZone(*enZone);
|
|
|
|
while (patternTests2[dataIndex].length() > 0) {
|
|
|
|
logln(patternTests2[dataIndex]);
|
|
|
|
bestPattern = patGen->getBestPattern(patternTests2[dataIndex], status);
|
|
|
|
logln(UnicodeString(" -> ") + bestPattern);
|
|
|
|
enFormat->applyPattern(bestPattern);
|
|
|
|
resultDate.remove();
|
|
|
|
resultDate = enFormat->format(testDate, resultDate);
|
|
|
|
if ( resultDate != patternResults2[resultIndex] ) {
|
|
|
|
errln(UnicodeString("\nERROR: Test various skeletons[") + dataIndex
|
2016-02-27 00:41:21 +00:00
|
|
|
+ UnicodeString("]. Got: ") + resultDate + UnicodeString(" Expected: ") +
|
2007-12-22 05:30:33 +00:00
|
|
|
patternResults2[resultIndex] );
|
|
|
|
}
|
|
|
|
dataIndex++;
|
|
|
|
resultIndex++;
|
|
|
|
}
|
|
|
|
delete patGen;
|
|
|
|
delete enZone;
|
|
|
|
delete enFormat;
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-27 00:41:21 +00:00
|
|
|
// ======= Test random skeleton
|
2007-08-03 18:43:04 +00:00
|
|
|
DateTimePatternGenerator *randDTGen= DateTimePatternGenerator::createInstance(status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
2007-08-07 23:16:36 +00:00
|
|
|
UChar newChar;
|
2007-09-06 18:00:08 +00:00
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<10; ++i) {
|
2007-08-11 20:32:54 +00:00
|
|
|
UnicodeString randomSkeleton;
|
2007-08-03 18:43:04 +00:00
|
|
|
int32_t len = rand() % 20;
|
|
|
|
for (int32_t j=0; j<len; ++j ) {
|
2007-08-11 20:32:54 +00:00
|
|
|
while ((newChar = (UChar)(rand()%0x7f))>=(UChar)0x20) {
|
2007-08-07 23:16:36 +00:00
|
|
|
randomSkeleton += newChar;
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
UnicodeString bestPattern = randDTGen->getBestPattern(randomSkeleton, status);
|
|
|
|
}
|
|
|
|
delete randDTGen;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// UnicodeString randomString=Unicode
|
|
|
|
// ======= Test getStaticClassID()
|
|
|
|
|
|
|
|
logln("Testing getStaticClassID()");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
DateTimePatternGenerator *test= DateTimePatternGenerator::createInstance(status);
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
if(test->getDynamicClassID() != DateTimePatternGenerator::getStaticClassID()) {
|
|
|
|
errln("ERROR: getDynamicClassID() didn't return the expected value");
|
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
delete test;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// ====== Test createEmptyInstance()
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
logln("Testing createEmptyInstance()");
|
|
|
|
status = U_ZERO_ERROR;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
test = DateTimePatternGenerator::createEmptyInstance(status);
|
|
|
|
if(U_FAILURE(status)) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Fail to create an empty instance ! - exitting.\n");
|
|
|
|
delete test;
|
|
|
|
return;
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
|
|
|
conflictingStatus = test->addPattern(UnicodeString("MMMMd"), true, conflictingPattern, status);
|
2007-08-03 18:43:04 +00:00
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
testPattern=test->getBestPattern(UnicodeString("MMMMdd"), status);
|
2016-02-27 00:41:21 +00:00
|
|
|
conflictingStatus = test->addPattern(UnicodeString("HH:mm"), true, conflictingPattern, status);
|
2011-12-05 04:49:40 +00:00
|
|
|
conflictingStatus = test->addPattern(UnicodeString("MMMMMdd"), true, conflictingPattern, status); //duplicate pattern
|
2007-08-03 18:43:04 +00:00
|
|
|
StringEnumeration *output=NULL;
|
|
|
|
output = test->getRedundants(status);
|
|
|
|
expectedResult=UnicodeString("MMMMd");
|
|
|
|
if (output != NULL) {
|
|
|
|
output->reset(status);
|
|
|
|
const UnicodeString *dupPattern=output->snext(status);
|
|
|
|
if ( (dupPattern==NULL) || (*dupPattern != expectedResult) ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Fail in getRedundants !\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// ======== Test getSkeletons and getBaseSkeletons
|
2007-09-06 18:00:08 +00:00
|
|
|
StringEnumeration* ptrSkeletonEnum = test->getSkeletons(status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("ERROR: Fail to get skeletons !\n");
|
|
|
|
}
|
|
|
|
UnicodeString returnPattern, *ptrSkeleton;
|
|
|
|
ptrSkeletonEnum->reset(status);
|
|
|
|
int32_t count=ptrSkeletonEnum->count(status);
|
|
|
|
for (i=0; i<count; ++i) {
|
|
|
|
ptrSkeleton = (UnicodeString *)ptrSkeletonEnum->snext(status);
|
|
|
|
returnPattern = test->getPatternForSkeleton(*ptrSkeleton);
|
|
|
|
if ( returnPattern != testSkeletonsResults[i] ) {
|
|
|
|
errln(UnicodeString("ERROR: Unexpected result from getSkeletons and getPatternForSkeleton\nGot: ") + returnPattern
|
|
|
|
+ UnicodeString("\nExpected: ") + testSkeletonsResults[i]
|
|
|
|
+ UnicodeString("\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringEnumeration* ptrBaseSkeletonEnum = test->getBaseSkeletons(status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("ERROR: Fail to get base skeletons !\n");
|
2016-02-27 00:41:21 +00:00
|
|
|
}
|
2007-09-06 18:00:08 +00:00
|
|
|
count=ptrBaseSkeletonEnum->count(status);
|
|
|
|
for (i=0; i<count; ++i) {
|
|
|
|
ptrSkeleton = (UnicodeString *)ptrBaseSkeletonEnum->snext(status);
|
|
|
|
if ( *ptrSkeleton != testBaseSkeletonsResults[i] ) {
|
|
|
|
errln("ERROR: Unexpected result from getBaseSkeletons() !\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 00:00:00 +00:00
|
|
|
// ========= DateTimePatternGenerator sample code in Userguide
|
|
|
|
// set up the generator
|
|
|
|
Locale locale = Locale::getFrench();
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
DateTimePatternGenerator *generator = DateTimePatternGenerator::createInstance( locale, status);
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2007-09-18 00:00:00 +00:00
|
|
|
// get a pattern for an abbreviated month and day
|
2016-02-27 00:41:21 +00:00
|
|
|
pattern = generator->getBestPattern(UnicodeString("MMMd"), status);
|
|
|
|
SimpleDateFormat formatter(pattern, locale, status);
|
2007-09-18 00:00:00 +00:00
|
|
|
|
2007-10-09 20:22:16 +00:00
|
|
|
zone = TimeZone::createTimeZone(UnicodeString("GMT"));
|
2007-12-06 18:33:45 +00:00
|
|
|
formatter.setTimeZone(*zone);
|
2007-09-18 00:00:00 +00:00
|
|
|
// use it to format (or parse)
|
|
|
|
UnicodeString formatted;
|
2016-02-27 00:41:21 +00:00
|
|
|
formatted = formatter.format(Calendar::getNow(), formatted, status);
|
2007-09-18 00:00:00 +00:00
|
|
|
// for French, the result is "13 sept."
|
|
|
|
formatted.remove();
|
2007-12-22 05:30:33 +00:00
|
|
|
// cannot use the result from getNow() because the value change evreyday.
|
|
|
|
testDate= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
2007-12-06 18:33:45 +00:00
|
|
|
formatted = formatter.format(testDate, formatted, status);
|
2007-10-09 20:22:16 +00:00
|
|
|
expectedResult=UnicodeString("14 janv.");
|
2007-09-18 00:00:00 +00:00
|
|
|
if ( formatted != expectedResult ) {
|
|
|
|
errln("ERROR: Userguide sample code result!");
|
|
|
|
errln(UnicodeString(" Got: ")+ formatted + UnicodeString(" Expected: ") + expectedResult);
|
|
|
|
}
|
|
|
|
|
2007-10-09 20:22:16 +00:00
|
|
|
delete zone;
|
2007-09-06 18:00:08 +00:00
|
|
|
delete output;
|
|
|
|
delete ptrSkeletonEnum;
|
|
|
|
delete ptrBaseSkeletonEnum;
|
|
|
|
delete test;
|
2007-09-18 00:00:00 +00:00
|
|
|
delete generator;
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
2009-12-10 09:13:49 +00:00
|
|
|
/**
|
|
|
|
* Test handling of options
|
|
|
|
*
|
|
|
|
* For reference, as of ICU 4.3.3,
|
|
|
|
* root/gregorian has
|
|
|
|
* Hm{"H:mm"}
|
|
|
|
* Hms{"H:mm:ss"}
|
|
|
|
* hm{"h:mm a"}
|
|
|
|
* hms{"h:mm:ss a"}
|
|
|
|
* en/gregorian has
|
|
|
|
* Hm{"H:mm"}
|
|
|
|
* Hms{"H:mm:ss"}
|
|
|
|
* hm{"h:mm a"}
|
2010-03-04 05:41:47 +00:00
|
|
|
* be/gregorian has
|
2009-12-10 09:13:49 +00:00
|
|
|
* HHmmss{"HH.mm.ss"}
|
|
|
|
* Hm{"HH.mm"}
|
|
|
|
* hm{"h.mm a"}
|
|
|
|
* hms{"h.mm.ss a"}
|
|
|
|
*/
|
2009-12-16 16:36:32 +00:00
|
|
|
typedef struct DTPtnGenOptionsData {
|
|
|
|
const char *locale;
|
|
|
|
const char *skel;
|
|
|
|
const char *expectedPattern;
|
|
|
|
UDateTimePatternMatchOptions options;
|
|
|
|
} DTPtnGenOptionsData;
|
2009-12-10 09:13:49 +00:00
|
|
|
void IntlTestDateTimePatternGeneratorAPI::testOptions(/*char *par*/)
|
|
|
|
{
|
|
|
|
DTPtnGenOptionsData testData[] = {
|
2009-12-16 16:36:32 +00:00
|
|
|
// locale skel expectedPattern options
|
2010-02-18 14:30:15 +00:00
|
|
|
{ "en", "Hmm", "HH:mm", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en", "HHmm", "HH:mm", UDATPG_MATCH_NO_OPTIONS },
|
2009-12-16 16:36:32 +00:00
|
|
|
{ "en", "hhmm", "h:mm a", UDATPG_MATCH_NO_OPTIONS },
|
2010-02-18 14:30:15 +00:00
|
|
|
{ "en", "Hmm", "HH:mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
|
2009-12-16 16:36:32 +00:00
|
|
|
{ "en", "HHmm", "HH:mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
|
|
|
|
{ "en", "hhmm", "hh:mm a", UDATPG_MATCH_HOUR_FIELD_LENGTH },
|
2015-08-27 20:23:27 +00:00
|
|
|
{ "da", "Hmm", "HH.mm", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "da", "HHmm", "HH.mm", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "da", "hhmm", "h.mm a", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "da", "Hmm", "H.mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
|
|
|
|
{ "da", "HHmm", "HH.mm", UDATPG_MATCH_HOUR_FIELD_LENGTH },
|
|
|
|
{ "da", "hhmm", "hh.mm a", UDATPG_MATCH_HOUR_FIELD_LENGTH },
|
2013-04-29 22:10:29 +00:00
|
|
|
//
|
2014-03-04 08:46:17 +00:00
|
|
|
{ "en", "yyyy", "yyyy", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en", "YYYY", "YYYY", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en", "U", "y", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=japanese", "yyyy", "y G", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=japanese", "YYYY", "Y G", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=japanese", "U", "y G", UDATPG_MATCH_NO_OPTIONS },
|
2015-02-23 16:47:52 +00:00
|
|
|
{ "en@calendar=chinese", "yyyy", "r(U)", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=chinese", "YYYY", "Y(Y)", UDATPG_MATCH_NO_OPTIONS }, // not a good result, want r(Y) or r(U)
|
|
|
|
{ "en@calendar=chinese", "U", "r(U)", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=chinese", "Gy", "r(U)", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=chinese", "GU", "r(U)", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=chinese", "ULLL", "MMM U", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=chinese", "yMMM", "MMM r(U)", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "en@calendar=chinese", "GUMMM", "MMM r(U)", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "yyyy", "rU\\u5E74", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "YYYY", "YY\\u5E74", UDATPG_MATCH_NO_OPTIONS }, // not a good result, may want r(Y) or r(U)
|
|
|
|
{ "zh@calendar=chinese", "U", "rU\\u5E74", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "Gy", "rU\\u5E74", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "GU", "rU\\u5E74", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "ULLL", "U\\u5E74MMM", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "yMMM", "rU\\u5E74MMM", UDATPG_MATCH_NO_OPTIONS },
|
|
|
|
{ "zh@calendar=chinese", "GUMMM", "rU\\u5E74MMM", UDATPG_MATCH_NO_OPTIONS },
|
2009-12-10 09:13:49 +00:00
|
|
|
};
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
int count = UPRV_LENGTHOF(testData);
|
2009-12-10 09:13:49 +00:00
|
|
|
const DTPtnGenOptionsData * testDataPtr = testData;
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2009-12-10 09:13:49 +00:00
|
|
|
for (; count-- > 0; ++testDataPtr) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2009-12-16 16:36:32 +00:00
|
|
|
|
|
|
|
Locale locale(testDataPtr->locale);
|
|
|
|
UnicodeString skel(testDataPtr->skel);
|
2014-03-04 08:46:17 +00:00
|
|
|
UnicodeString expectedPattern(UnicodeString(testDataPtr->expectedPattern).unescape());
|
2009-12-16 16:36:32 +00:00
|
|
|
UDateTimePatternMatchOptions options = testDataPtr->options;
|
|
|
|
|
|
|
|
DateTimePatternGenerator * dtpgen = DateTimePatternGenerator::createInstance(locale, status);
|
2010-02-24 16:17:03 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("Unable to create DateTimePatternGenerator instance for locale(%s): %s", locale.getName(), u_errorName(status));
|
|
|
|
delete dtpgen;
|
|
|
|
continue;
|
|
|
|
}
|
2009-12-16 16:36:32 +00:00
|
|
|
UnicodeString pattern = dtpgen->getBestPattern(skel, options, status);
|
|
|
|
if (pattern.compare(expectedPattern) != 0) {
|
|
|
|
errln( UnicodeString("ERROR in getBestPattern, locale ") + UnicodeString(testDataPtr->locale) +
|
|
|
|
UnicodeString(", skeleton ") + skel +
|
|
|
|
((options)?UnicodeString(", options!=0"):UnicodeString(", options==0")) +
|
|
|
|
UnicodeString(", expected pattern ") + expectedPattern +
|
2009-12-10 09:13:49 +00:00
|
|
|
UnicodeString(", got ") + pattern );
|
|
|
|
}
|
|
|
|
delete dtpgen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 07:51:38 +00:00
|
|
|
/**
|
|
|
|
* Test that DTPG can handle all valid pattern character / length combinations
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define FIELD_LENGTHS_COUNT 6
|
|
|
|
#define FIELD_LENGTH_MAX 8
|
|
|
|
#define MUST_INCLUDE_COUNT 5
|
|
|
|
|
|
|
|
typedef struct AllFieldsTestItem {
|
|
|
|
char patternChar;
|
|
|
|
int8_t fieldLengths[FIELD_LENGTHS_COUNT+1]; // up to FIELD_LENGTHS_COUNT lengths to try
|
|
|
|
// (length <=FIELD_LENGTH_MAX) plus 0 terminator
|
|
|
|
char mustIncludeOneOf[MUST_INCLUDE_COUNT+1];// resulting pattern must include at least one of
|
|
|
|
// these as a pattern char (0-terminated list)
|
|
|
|
} AllFieldsTestItem;
|
|
|
|
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::testAllFieldPatterns(/*char *par*/)
|
|
|
|
{
|
|
|
|
const char * localeNames[] = {
|
|
|
|
"root",
|
|
|
|
"root@calendar=japanese",
|
|
|
|
"root@calendar=chinese",
|
|
|
|
"en",
|
|
|
|
"en@calendar=japanese",
|
|
|
|
"en@calendar=chinese",
|
|
|
|
NULL // terminator
|
|
|
|
};
|
|
|
|
AllFieldsTestItem testData[] = {
|
|
|
|
//pat fieldLengths generated pattern must
|
|
|
|
//chr to test include one of these
|
|
|
|
{ 'G', {1,2,3,4,5,0}, "G" }, // era
|
|
|
|
// year
|
|
|
|
{ 'y', {1,2,3,4,0}, "yU" }, // year
|
|
|
|
{ 'Y', {1,2,3,4,0}, "Y" }, // year for week of year
|
|
|
|
{ 'u', {1,2,3,4,5,0}, "yuU" }, // extended year
|
|
|
|
{ 'U', {1,2,3,4,5,0}, "yU" }, // cyclic year name
|
|
|
|
// quarter
|
|
|
|
{ 'Q', {1,2,3,4,0}, "Qq" }, // x
|
|
|
|
{ 'q', {1,2,3,4,0}, "Qq" }, // standalone
|
|
|
|
// month
|
|
|
|
{ 'M', {1,2,3,4,5,0}, "ML" }, // x
|
|
|
|
{ 'L', {1,2,3,4,5,0}, "ML" }, // standalone
|
|
|
|
// week
|
|
|
|
{ 'w', {1,2,0}, "w" }, // week of year
|
|
|
|
{ 'W', {1,0}, "W" }, // week of month
|
|
|
|
// day
|
|
|
|
{ 'd', {1,2,0}, "d" }, // day of month
|
|
|
|
{ 'D', {1,2,3,0}, "D" }, // day of year
|
|
|
|
{ 'F', {1,0}, "F" }, // day of week in month
|
|
|
|
{ 'g', {7,0}, "g" }, // modified julian day
|
|
|
|
// weekday
|
|
|
|
{ 'E', {1,2,3,4,5,6}, "Eec" }, // day of week
|
|
|
|
{ 'e', {1,2,3,4,5,6}, "Eec" }, // local day of week
|
|
|
|
{ 'c', {1,2,3,4,5,6}, "Eec" }, // standalone local day of week
|
|
|
|
// day period
|
|
|
|
// { 'a', {1,0}, "a" }, // am or pm // not clear this one is supposed to work (it doesn't)
|
|
|
|
// hour
|
|
|
|
{ 'h', {1,2,0}, "hK" }, // 12 (1-12)
|
|
|
|
{ 'H', {1,2,0}, "Hk" }, // 24 (0-23)
|
|
|
|
{ 'K', {1,2,0}, "hK" }, // 12 (0-11)
|
|
|
|
{ 'k', {1,2,0}, "Hk" }, // 24 (1-24)
|
|
|
|
{ 'j', {1,2,0}, "hHKk" }, // locale default
|
|
|
|
// minute
|
|
|
|
{ 'm', {1,2,0}, "m" }, // x
|
|
|
|
// second & fractions
|
|
|
|
{ 's', {1,2,0}, "s" }, // x
|
|
|
|
{ 'S', {1,2,3,4,0}, "S" }, // fractional second
|
|
|
|
{ 'A', {8,0}, "A" }, // milliseconds in day
|
|
|
|
// zone
|
|
|
|
{ 'z', {1,2,3,4,0}, "z" }, // x
|
|
|
|
{ 'Z', {1,2,3,4,5,0}, "Z" }, // x
|
|
|
|
{ 'O', {1,4,0}, "O" }, // x
|
|
|
|
{ 'v', {1,4,0}, "v" }, // x
|
|
|
|
{ 'V', {1,2,3,4,0}, "V" }, // x
|
|
|
|
{ 'X', {1,2,3,4,5,0}, "X" }, // x
|
|
|
|
{ 'x', {1,2,3,4,5,0}, "x" }, // x
|
|
|
|
};
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2013-09-10 07:51:38 +00:00
|
|
|
const char ** localeNamesPtr = localeNames;
|
|
|
|
const char * localeName;
|
|
|
|
while ( (localeName = *localeNamesPtr++) != NULL) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
Locale locale = Locale::createFromName(localeName);
|
|
|
|
DateTimePatternGenerator * dtpg = DateTimePatternGenerator::createInstance(locale, status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
const AllFieldsTestItem * testDataPtr = testData;
|
2016-02-23 10:40:09 +00:00
|
|
|
int itemCount = UPRV_LENGTHOF(testData);
|
2013-09-10 07:51:38 +00:00
|
|
|
for (; itemCount-- > 0; ++testDataPtr) {
|
|
|
|
char skelBuf[FIELD_LENGTH_MAX];
|
|
|
|
int32_t chrIndx, lenIndx;
|
|
|
|
for (chrIndx = 0; chrIndx < FIELD_LENGTH_MAX; chrIndx++) {
|
|
|
|
skelBuf[chrIndx] = testDataPtr->patternChar;
|
|
|
|
}
|
|
|
|
for (lenIndx = 0; lenIndx < FIELD_LENGTHS_COUNT; lenIndx++) {
|
|
|
|
int32_t skelLen = testDataPtr->fieldLengths[lenIndx];
|
|
|
|
if (skelLen <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2013-09-10 20:34:57 +00:00
|
|
|
if (skelLen > FIELD_LENGTH_MAX) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-10 07:51:38 +00:00
|
|
|
UnicodeString skeleton(skelBuf, skelLen, US_INV);
|
|
|
|
UnicodeString pattern = dtpg->getBestPattern(skeleton, status);
|
2013-09-10 20:34:57 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("DateTimePatternGenerator getBestPattern for locale %s, skelChar %c skelLength %d fails: %s",
|
|
|
|
locale.getName(), testDataPtr->patternChar, skelLen, u_errorName(status));
|
|
|
|
} else if (pattern.length() <= 0) {
|
|
|
|
errln("DateTimePatternGenerator getBestPattern for locale %s, skelChar %c skelLength %d produces 0-length pattern",
|
|
|
|
locale.getName(), testDataPtr->patternChar, skelLen);
|
|
|
|
} else {
|
2013-09-10 07:51:38 +00:00
|
|
|
// test that resulting pattern has at least one char in mustIncludeOneOf
|
|
|
|
UnicodeString mustIncludeOneOf(testDataPtr->mustIncludeOneOf, -1, US_INV);
|
|
|
|
int32_t patIndx, patLen = pattern.length();
|
|
|
|
UBool inQuoted = FALSE;
|
|
|
|
for (patIndx = 0; patIndx < patLen; patIndx++) {
|
|
|
|
UChar c = pattern.charAt(patIndx);
|
|
|
|
if (c == 0x27) {
|
|
|
|
inQuoted = !inQuoted;
|
2013-09-10 21:29:14 +00:00
|
|
|
} else if (!inQuoted && c <= 0x007A && c >= 0x0041) {
|
2013-09-10 07:51:38 +00:00
|
|
|
if (mustIncludeOneOf.indexOf(c) >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (patIndx >= patLen) {
|
|
|
|
errln(UnicodeString("DateTimePatternGenerator getBestPattern for locale ") +
|
|
|
|
UnicodeString(locale.getName(),-1,US_INV) +
|
|
|
|
", skeleton " + skeleton +
|
|
|
|
", produces pattern without required chars: " + pattern);
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
2013-09-10 07:51:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete dtpg;
|
|
|
|
} else {
|
|
|
|
dataerrln("Create DateTimePatternGenerator instance for locale(%s) fails: %s",
|
|
|
|
locale.getName(), u_errorName(status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 12:29:17 +00:00
|
|
|
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::testStaticGetSkeleton(/*char *par*/)
|
|
|
|
{
|
|
|
|
// Verify that staticGetSkeleton() doesn't mangle skeletons. (Ticket #11985)
|
|
|
|
static const char* const testData[] = {
|
|
|
|
"jmm",
|
|
|
|
"jjmm",
|
|
|
|
"Jmm",
|
|
|
|
"JJmm"
|
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
for (size_t i = 0; i < UPRV_LENGTHOF(testData); i++) {
|
2015-11-18 12:29:17 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UnicodeString skeleton = DateTimePatternGenerator::staticGetSkeleton(testData[i], status);
|
|
|
|
if (!assertSuccess("staticGetSkeleton", status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assertEquals("Skeleton", testData[i], skeleton);
|
|
|
|
}
|
|
|
|
}
|
2016-02-27 00:41:21 +00:00
|
|
|
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::testC() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const int32_t numLocales = 6;
|
|
|
|
|
|
|
|
const char* tests[numLocales][3] = {
|
|
|
|
{"zh", "Cm", "Bh:mm"},
|
|
|
|
{"de", "Cm", "HH:mm"},
|
|
|
|
{"en", "Cm", "h:mm a"},
|
|
|
|
{"en-BN", "Cm", "h:mm b"},
|
|
|
|
{"gu-IN", "Cm", "h:mm B"},
|
|
|
|
{"und-IN", "Cm", "h:mm a"},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < numLocales; ++i) {
|
|
|
|
DateTimePatternGenerator *gen = DateTimePatternGenerator::createInstance(Locale(tests[i][0]), status);
|
|
|
|
UnicodeString pattern = gen->getBestPattern(tests[i][1], status);
|
|
|
|
UnicodeString expectedPattern = tests[i][2];
|
|
|
|
|
|
|
|
char message[100] = "\0";
|
|
|
|
strcat(message, tests[i][0]);
|
|
|
|
strcat(message, "/");
|
|
|
|
strcat(message, tests[i][1]);
|
|
|
|
assertEquals(message, expectedPattern, pattern);
|
2016-03-01 07:37:31 +00:00
|
|
|
delete gen;
|
2016-02-27 00:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|