1
/********************************************************************************
2
* Copyright (C) 2008-2010, International Business Machines Corporation and
3
* others. All Rights Reserved.
4
*******************************************************************************
8
*******************************************************************************
11
#ifndef __DTITVFMT_H__
12
#define __DTITVFMT_H__
15
#include "unicode/utypes.h"
19
* \brief C++ API: Format and parse date interval in a language-independent manner.
22
#if !UCONFIG_NO_FORMATTING
24
#include "unicode/ucal.h"
25
#include "unicode/smpdtfmt.h"
26
#include "unicode/dtintrv.h"
27
#include "unicode/dtitvinf.h"
28
#include "unicode/dtptngen.h"
35
* DateIntervalFormat is a class for formatting and parsing date
36
* intervals in a language-independent manner.
37
* Only formatting is supported, parsing is not supported.
40
* Date interval means from one date to another date,
41
* for example, from "Jan 11, 2008" to "Jan 18, 2008".
42
* We introduced class DateInterval to represent it.
43
* DateInterval is a pair of UDate, which is
44
* the standard milliseconds since 24:00 GMT, Jan 1, 1970.
47
* DateIntervalFormat formats a DateInterval into
48
* text as compactly as possible.
49
* For example, the date interval format from "Jan 11, 2008" to "Jan 18,. 2008"
50
* is "Jan 11-18, 2008" for English.
51
* And it parses text into DateInterval,
52
* although initially, parsing is not supported.
55
* There is no structural information in date time patterns.
56
* For any punctuations and string literals inside a date time pattern,
57
* we do not know whether it is just a separator, or a prefix, or a suffix.
58
* Without such information, so, it is difficult to generate a sub-pattern
59
* (or super-pattern) by algorithm.
60
* So, formatting a DateInterval is pattern-driven. It is very
61
* similar to formatting in SimpleDateFormat.
62
* We introduce class DateIntervalInfo to save date interval
63
* patterns, similar to date time pattern in SimpleDateFormat.
66
* Logically, the interval patterns are mappings
67
* from (skeleton, the_largest_different_calendar_field)
68
* to (date_interval_pattern).
74
* only keeps the field pattern letter and ignores all other parts
75
* in a pattern, such as space, punctuations, and string literals.
78
* hides the order of fields.
81
* might hide a field's pattern letter length.
85
* For those non-digit calendar fields, the pattern letter length is
86
* important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
87
* and the field's pattern letter length is honored.
89
* For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
90
* the field pattern length is ignored and the best match, which is defined
91
* in date time patterns, will be returned without honor the field pattern
92
* letter length in skeleton.
95
* The calendar fields we support for interval formatting are:
96
* year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute.
97
* Those calendar fields can be defined in the following order:
98
* year > month > date > hour (in day) > minute
100
* The largest different calendar fields between 2 calendars is the
101
* first different calendar field in above order.
103
* For example: the largest different calendar fields between "Jan 10, 2007"
104
* and "Feb 20, 2008" is year.
107
* For other calendar fields, the compact interval formatting is not
108
* supported. And the interval format will be fall back to fall-back
109
* patterns, which is mostly "{date0} - {date1}".
112
* There is a set of pre-defined static skeleton strings.
113
* There are pre-defined interval patterns for those pre-defined skeletons
114
* in locales' resource files.
115
* For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd",
116
* in en_US, if the largest different calendar field between date1 and date2
117
* is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy",
118
* such as "Jan 10, 2007 - Jan 10, 2008".
119
* If the largest different calendar field between date1 and date2 is "month",
120
* the date interval pattern is "MMM d - MMM d, yyyy",
121
* such as "Jan 10 - Feb 10, 2007".
122
* If the largest different calendar field between date1 and date2 is "day",
123
* the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007".
125
* For date skeleton, the interval patterns when year, or month, or date is
126
* different are defined in resource files.
127
* For time skeleton, the interval patterns when am/pm, or hour, or minute is
128
* different are defined in resource files.
131
* If a skeleton is not found in a locale's DateIntervalInfo, which means
132
* the interval patterns for the skeleton is not defined in resource file,
133
* the interval pattern will falls back to the interval "fallback" pattern
134
* defined in resource file.
135
* If the interval "fallback" pattern is not defined, the default fall-back
136
* is "{date0} - {data1}".
139
* For the combination of date and time,
140
* The rule to generate interval patterns are:
143
* when the year, month, or day differs, falls back to fall-back
144
* interval pattern, which mostly is the concatenate the two original
145
* expressions with a separator between,
146
* For example, interval pattern from "Jan 10, 2007 10:10 am"
147
* to "Jan 11, 2007 10:10am" is
148
* "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
151
* otherwise, present the date followed by the range expression
153
* For example, interval pattern from "Jan 10, 2007 10:10 am"
154
* to "Jan 10, 2007 11:10am" is "Jan 10, 2007 10:10 am - 11:10am"
160
* If two dates are the same, the interval pattern is the single date pattern.
161
* For example, interval pattern from "Jan 10, 2007" to "Jan 10, 2007" is
164
* Or if the presenting fields between 2 dates have the exact same values,
165
* the interval pattern is the single date pattern.
166
* For example, if user only requests year and month,
167
* the interval pattern from "Jan 10, 2007" to "Jan 20, 2007" is "Jan 2007".
170
* DateIntervalFormat needs the following information for correct
171
* formatting: time zone, calendar type, pattern, date format symbols,
172
* and date interval patterns.
173
* It can be instantiated in 2 ways:
176
* create an instance using default or given locale plus given skeleton.
177
* Users are encouraged to created date interval formatter this way and
178
* to use the pre-defined skeleton macros, such as
179
* UDAT_YEAR_NUM_MONTH, which consists the calendar fields and
183
* create an instance using default or given locale plus given skeleton
184
* plus a given DateIntervalInfo.
185
* This factory method is for powerful users who want to provide their own
187
* Locale provides the timezone, calendar, and format symbols information.
188
* Local plus skeleton provides full pattern information.
189
* DateIntervalInfo provides the date interval patterns.
194
* For the calendar field pattern letter, such as G, y, M, d, a, h, H, m, s etc.
195
* DateIntervalFormat uses the same syntax as that of
199
* Code Sample: general usage
202
* // the date interval object which the DateIntervalFormat formats on
204
* DateInterval* dtInterval = new DateInterval(1000*3600*24, 1000*3600*24*2);
205
* UErrorCode status = U_ZERO_ERROR;
206
* DateIntervalFormat* dtIntervalFmt = DateIntervalFormat::createInstance(
207
* UDAT_YEAR_MONTH_DAY,
208
* Locale("en", "GB", ""), status);
209
* UnicodeUnicodeString dateIntervalString;
210
* FieldPosition pos = 0;
212
* dtIntervalFmt->format(dtInterval, dateIntervalUnicodeString, pos, status);
213
* delete dtIntervalFmt;
218
class U_I18N_API DateIntervalFormat : public Format {
222
* Construct a DateIntervalFormat from skeleton and the default locale.
224
* This is a convenient override of
225
* createInstance(const UnicodeString& skeleton, const Locale& locale,
227
* with the value of locale as default locale.
229
* @param skeleton the skeleton on which interval format based.
230
* @param status output param set to success/failure code on exit
231
* @return a date time interval formatter which the caller owns.
234
static DateIntervalFormat* U_EXPORT2 createInstance(
235
const UnicodeString& skeleton,
239
* Construct a DateIntervalFormat from skeleton and a given locale.
241
* In this factory method,
242
* the date interval pattern information is load from resource files.
243
* Users are encouraged to created date interval formatter this way and
244
* to use the pre-defined skeleton macros.
247
* There are pre-defined skeletons (defined in udate.h) having predefined
248
* interval patterns in resource files.
249
* Users are encouraged to use those macros.
251
* DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
253
* The given Locale provides the interval patterns.
254
* For example, for en_GB, if skeleton is UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY,
255
* which is "yMMMEEEd",
256
* the interval patterns defined in resource file to above skeleton are:
257
* "EEE, d MMM, yyyy - EEE, d MMM, yyyy" for year differs,
258
* "EEE, d MMM - EEE, d MMM, yyyy" for month differs,
259
* "EEE, d - EEE, d MMM, yyyy" for day differs,
260
* @param skeleton the skeleton on which interval format based.
261
* @param locale the given locale
262
* @param status output param set to success/failure code on exit
263
* @return a date time interval formatter which the caller owns.
267
static DateIntervalFormat* U_EXPORT2 createInstance(
268
const UnicodeString& skeleton,
269
const Locale& locale,
273
* Construct a DateIntervalFormat from skeleton
274
* DateIntervalInfo, and default locale.
276
* This is a convenient override of
277
* createInstance(const UnicodeString& skeleton, const Locale& locale,
278
* const DateIntervalInfo& dtitvinf, UErrorCode&)
279
* with the locale value as default locale.
281
* @param skeleton the skeleton on which interval format based.
282
* @param dtitvinf the DateIntervalInfo object.
283
* @param status output param set to success/failure code on exit
284
* @return a date time interval formatter which the caller owns.
287
static DateIntervalFormat* U_EXPORT2 createInstance(
288
const UnicodeString& skeleton,
289
const DateIntervalInfo& dtitvinf,
293
* Construct a DateIntervalFormat from skeleton
294
* a DateIntervalInfo, and the given locale.
297
* In this factory method, user provides its own date interval pattern
298
* information, instead of using those pre-defined data in resource file.
299
* This factory method is for powerful users who want to provide their own
302
* There are pre-defined skeletons (defined in udate.h) having predefined
303
* interval patterns in resource files.
304
* Users are encouraged to use those macros.
306
* DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
308
* The DateIntervalInfo provides the interval patterns.
309
* and the DateIntervalInfo ownership remains to the caller.
311
* User are encouraged to set default interval pattern in DateIntervalInfo
312
* as well, if they want to set other interval patterns ( instead of
313
* reading the interval patterns from resource files).
314
* When the corresponding interval pattern for a largest calendar different
315
* field is not found ( if user not set it ), interval format fallback to
316
* the default interval pattern.
317
* If user does not provide default interval pattern, it fallback to
318
* "{date0} - {date1}"
320
* @param skeleton the skeleton on which interval format based.
321
* @param locale the given locale
322
* @param dtitvinf the DateIntervalInfo object.
323
* @param status output param set to success/failure code on exit
324
* @return a date time interval formatter which the caller owns.
327
static DateIntervalFormat* U_EXPORT2 createInstance(
328
const UnicodeString& skeleton,
329
const Locale& locale,
330
const DateIntervalInfo& dtitvinf,
337
virtual ~DateIntervalFormat();
340
* Clone this Format object polymorphically. The caller owns the result and
341
* should delete it when done.
342
* @return A copy of the object.
345
virtual Format* clone(void) const;
348
* Return true if the given Format objects are semantically equal. Objects
349
* of different subclasses are considered unequal.
350
* @param other the object to be compared with.
351
* @return true if the given Format objects are semantically equal.
354
virtual UBool operator==(const Format& other) const;
357
* Return true if the given Format objects are not semantically equal.
358
* Objects of different subclasses are considered unequal.
359
* @param other the object to be compared with.
360
* @return true if the given Format objects are not semantically equal.
363
UBool operator!=(const Format& other) const;
366
using Format::format;
369
* Format an object to produce a string. This method handles Formattable
370
* objects with a DateInterval type.
371
* If a the Formattable object type is not a DateInterval,
372
* then it returns a failing UErrorCode.
374
* @param obj The object to format.
375
* Must be a DateInterval.
376
* @param appendTo Output parameter to receive result.
377
* Result is appended to existing contents.
378
* @param fieldPosition On input: an alignment field, if desired.
379
* On output: the offsets of the alignment field.
380
* @param status Output param filled with success/failure status.
381
* @return Reference to 'appendTo' parameter.
384
virtual UnicodeString& format(const Formattable& obj,
385
UnicodeString& appendTo,
386
FieldPosition& fieldPosition,
387
UErrorCode& status) const ;
392
* Format a DateInterval to produce a string.
394
* @param dtInterval DateInterval to be formatted.
395
* @param appendTo Output parameter to receive result.
396
* Result is appended to existing contents.
397
* @param fieldPosition On input: an alignment field, if desired.
398
* On output: the offsets of the alignment field.
399
* @param status Output param filled with success/failure status.
400
* @return Reference to 'appendTo' parameter.
403
UnicodeString& format(const DateInterval* dtInterval,
404
UnicodeString& appendTo,
405
FieldPosition& fieldPosition,
406
UErrorCode& status) const ;
410
* Format 2 Calendars to produce a string.
412
* Note: "fromCalendar" and "toCalendar" are not const,
413
* since calendar is not const in SimpleDateFormat::format(Calendar&),
415
* @param fromCalendar calendar set to the from date in date interval
416
* to be formatted into date interval string
417
* @param toCalendar calendar set to the to date in date interval
418
* to be formatted into date interval string
419
* @param appendTo Output parameter to receive result.
420
* Result is appended to existing contents.
421
* @param fieldPosition On input: an alignment field, if desired.
422
* On output: the offsets of the alignment field.
423
* @param status Output param filled with success/failure status.
424
* Caller needs to make sure it is SUCCESS
425
* at the function entrance
426
* @return Reference to 'appendTo' parameter.
429
UnicodeString& format(Calendar& fromCalendar,
430
Calendar& toCalendar,
431
UnicodeString& appendTo,
432
FieldPosition& fieldPosition,
433
UErrorCode& status) const ;
436
* Date interval parsing is not supported. Please do not use.
438
* This method should handle parsing of
439
* date time interval strings into Formattable objects with
440
* DateInterval type, which is a pair of UDate.
442
* Before calling, set parse_pos.index to the offset you want to start
443
* parsing at in the source. After calling, parse_pos.index is the end of
444
* the text you parsed. If error occurs, index is unchanged.
446
* When parsing, leading whitespace is discarded (with a successful parse),
447
* while trailing whitespace is left as is.
449
* See Format::parseObject() for more.
451
* @param source The string to be parsed into an object.
452
* @param result Formattable to be set to the parse result.
453
* If parse fails, return contents are undefined.
454
* @param parse_pos The position to start parsing at. Since no parsing
455
* is supported, upon return this param is unchanged.
456
* @return A newly created Formattable* object, or NULL
457
* on failure. The caller owns this and should
458
* delete it when done.
461
virtual void parseObject(const UnicodeString& source,
463
ParsePosition& parse_pos) const;
467
* Gets the date time interval patterns.
468
* @return the date time interval patterns associated with
469
* this date interval formatter.
472
const DateIntervalInfo* getDateIntervalInfo(void) const;
476
* Set the date time interval patterns.
477
* @param newIntervalPatterns the given interval patterns to copy.
478
* @param status output param set to success/failure code on exit
481
void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
486
* Gets the date formatter
487
* @return the date formatter associated with this date interval formatter.
490
const DateFormat* getDateFormat(void) const;
493
* Return the class ID for this class. This is useful only for comparing to
494
* a return value from getDynamicClassID(). For example:
496
* . Base* polymorphic_pointer = createPolymorphicObject();
497
* . if (polymorphic_pointer->getDynamicClassID() ==
498
* . erived::getStaticClassID()) ...
500
* @return The class ID for all objects of this class.
503
static UClassID U_EXPORT2 getStaticClassID(void);
506
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
507
* method is to implement a simple version of RTTI, since not all C++
508
* compilers support genuine RTTI. Polymorphic operator==() and clone()
509
* methods call this method.
511
* @return The class ID for this object. All objects of a
512
* given class have the same class ID. Objects of
513
* other classes have different class IDs.
516
virtual UClassID getDynamicClassID(void) const;
524
DateIntervalFormat(const DateIntervalFormat&);
527
* Assignment operator.
530
DateIntervalFormat& operator=(const DateIntervalFormat&);
535
* This is for ICU internal use only. Please do not use.
536
* Save the interval pattern information.
537
* Interval pattern consists of 2 single date patterns and the separator.
538
* For example, interval pattern "MMM d - MMM d, yyyy" consists
539
* a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
540
* and a separator "-".
541
* The pattern is divided into 2 parts. For above example,
542
* the first part is "MMM d - ", and the second part is "MMM d, yyyy".
543
* Also, the first date appears in an interval pattern could be
544
* the earlier date or the later date.
545
* And such information is saved in the interval pattern as well.
549
UnicodeString firstPart;
550
UnicodeString secondPart;
552
* Whether the first date in interval pattern is later date or not.
553
* Fallback format set the default ordering.
554
* And for a particular interval pattern, the order can be
555
* overriden by prefixing the interval pattern with "latestFirst:" or
557
* For example, given 2 date, Jan 10, 2007 to Feb 10, 2007.
558
* if the fallback format is "{0} - {1}",
559
* and the pattern is "d MMM - d MMM yyyy", the interval format is
560
* "10 Jan - 10 Feb, 2007".
561
* If the pattern is "latestFirst:d MMM - d MMM yyyy",
562
* the interval format is "10 Feb - 10 Jan, 2007"
564
UBool laterDateFirst;
569
* default constructor
572
DateIntervalFormat();
575
* Construct a DateIntervalFormat from DateFormat,
576
* a DateIntervalInfo, and skeleton.
577
* DateFormat provides the timezone, calendar,
578
* full pattern, and date format symbols information.
579
* It should be a SimpleDateFormat object which
580
* has a pattern in it.
581
* the DateIntervalInfo provides the interval patterns.
583
* Note: the DateIntervalFormat takes ownership of both
584
* DateFormat and DateIntervalInfo objects.
585
* Caller should not delete them.
587
* @param locale the locale of this date interval formatter.
588
* @param dtitvinf the DateIntervalInfo object to be adopted.
589
* @param skeleton the skeleton of the date formatter
590
* @param status output param set to success/failure code on exit
593
DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
594
const UnicodeString* skeleton, UErrorCode& status);
598
* Construct a DateIntervalFormat from DateFormat
599
* and a DateIntervalInfo.
601
* It is a wrapper of the constructor.
603
* @param locale the locale of this date interval formatter.
604
* @param dtitvinf the DateIntervalInfo object to be adopted.
605
* @param skeleton the skeleton of this formatter.
606
* @param status Output param set to success/failure code.
607
* @return a date time interval formatter which the caller owns.
610
static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
611
DateIntervalInfo* dtitvinf,
612
const UnicodeString* skeleton,
616
* Create a simple date/time formatter from skeleton, given locale,
617
* and date time pattern generator.
619
* @param skeleton the skeleton on which date format based.
620
* @param locale the given locale.
621
* @param dtpng the date time pattern generator.
622
* @param status Output param to be set to success/failure code.
623
* If it is failure, the returned date formatter will
625
* @return a simple date formatter which the caller owns.
628
static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance(
629
const UnicodeString& skeleton,
630
const Locale& locale,
631
DateTimePatternGenerator* dtpng,
636
* Below are for generating interval patterns local to the formatter
641
* Format 2 Calendars using fall-back interval pattern
643
* The full pattern used in this fall-back format is the
644
* full pattern of the date formatter.
646
* @param fromCalendar calendar set to the from date in date interval
647
* to be formatted into date interval string
648
* @param toCalendar calendar set to the to date in date interval
649
* to be formatted into date interval string
650
* @param appendTo Output parameter to receive result.
651
* Result is appended to existing contents.
652
* @param pos On input: an alignment field, if desired.
653
* On output: the offsets of the alignment field.
654
* @param status output param set to success/failure code on exit
655
* @return Reference to 'appendTo' parameter.
658
UnicodeString& fallbackFormat(Calendar& fromCalendar,
659
Calendar& toCalendar,
660
UnicodeString& appendTo,
662
UErrorCode& status) const;
667
* Initialize interval patterns locale to this formatter
669
* This code is a bit complicated since
670
* 1. the interval patterns saved in resource bundle files are interval
671
* patterns based on date or time only.
672
* It does not have interval patterns based on both date and time.
673
* Interval patterns on both date and time are algorithm generated.
675
* For example, it has interval patterns on skeleton "dMy" and "hm",
676
* but it does not have interval patterns on skeleton "dMyhm".
678
* The rule to generate interval patterns for both date and time skeleton are
679
* 1) when the year, month, or day differs, concatenate the two original
680
* expressions with a separator between,
681
* For example, interval pattern from "Jan 10, 2007 10:10 am"
682
* to "Jan 11, 2007 10:10am" is
683
* "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
685
* 2) otherwise, present the date followed by the range expression
687
* For example, interval pattern from "Jan 10, 2007 10:10 am"
688
* to "Jan 10, 2007 11:10am" is
689
* "Jan 10, 2007 10:10 am - 11:10am"
691
* 2. even a pattern does not request a certain calendar field,
692
* the interval pattern needs to include such field if such fields are
693
* different between 2 dates.
694
* For example, a pattern/skeleton is "hm", but the interval pattern
695
* includes year, month, and date when year, month, and date differs.
698
* @param status output param set to success/failure code on exit
701
void initializePattern(UErrorCode& status);
706
* Set fall back interval pattern given a calendar field,
707
* a skeleton, and a date time pattern generator.
708
* @param field the largest different calendar field
709
* @param skeleton a skeleton
710
* @param status output param set to success/failure code on exit
713
void setFallbackPattern(UCalendarDateFields field,
714
const UnicodeString& skeleton,
720
* get separated date and time skeleton from a combined skeleton.
722
* The difference between date skeleton and normalizedDateSkeleton are:
723
* 1. both 'y' and 'd' are appeared only once in normalizeDateSkeleton
724
* 2. 'E' and 'EE' are normalized into 'EEE'
725
* 3. 'MM' is normalized into 'M'
727
** the difference between time skeleton and normalizedTimeSkeleton are:
728
* 1. both 'H' and 'h' are normalized as 'h' in normalized time skeleton,
729
* 2. 'a' is omitted in normalized time skeleton.
730
* 3. there is only one appearance for 'h', 'm','v', 'z' in normalized time
734
* @param skeleton given combined skeleton.
735
* @param date Output parameter for date only skeleton.
736
* @param normalizedDate Output parameter for normalized date only
738
* @param time Output parameter for time only skeleton.
739
* @param normalizedTime Output parameter for normalized time only
744
static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
746
UnicodeString& normalizedDate,
748
UnicodeString& normalizedTime);
753
* Generate date or time interval pattern from resource,
754
* and set them into the interval pattern locale to this formatter.
756
* It needs to handle the following:
757
* 1. need to adjust field width.
758
* For example, the interval patterns saved in DateIntervalInfo
759
* includes "dMMMy", but not "dMMMMy".
760
* Need to get interval patterns for dMMMMy from dMMMy.
761
* Another example, the interval patterns saved in DateIntervalInfo
762
* includes "hmv", but not "hmz".
763
* Need to get interval patterns for "hmz' from 'hmv'
765
* 2. there might be no pattern for 'y' differ for skeleton "Md",
766
* in order to get interval patterns for 'y' differ,
767
* need to look for it from skeleton 'yMd'
769
* @param dateSkeleton normalized date skeleton
770
* @param timeSkeleton normalized time skeleton
771
* @return whether the resource is found for the skeleton.
772
* TRUE if interval pattern found for the skeleton,
776
UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
777
const UnicodeString& timeSkeleton);
783
* Generate interval pattern from existing resource
785
* It not only save the interval patterns,
786
* but also return the extended skeleton and its best match skeleton.
788
* @param field largest different calendar field
789
* @param skeleton skeleton
790
* @param bestSkeleton the best match skeleton which has interval pattern
791
* defined in resource
792
* @param differenceInfo the difference between skeleton and best skeleton
793
* 0 means the best matched skeleton is the same as input skeleton
794
* 1 means the fields are the same, but field width are different
795
* 2 means the only difference between fields are v/z,
796
* -1 means there are other fields difference
798
* @param extendedSkeleton extended skeleton
799
* @param extendedBestSkeleton extended best match skeleton
800
* @return whether the interval pattern is found
801
* through extending skeleton or not.
802
* TRUE if interval pattern is found by
803
* extending skeleton, FALSE otherwise.
806
UBool setIntervalPattern(UCalendarDateFields field,
807
const UnicodeString* skeleton,
808
const UnicodeString* bestSkeleton,
809
int8_t differenceInfo,
810
UnicodeString* extendedSkeleton = NULL,
811
UnicodeString* extendedBestSkeleton = NULL);
814
* Adjust field width in best match interval pattern to match
815
* the field width in input skeleton.
817
* TODO (xji) make a general solution
818
* The adjusting rule can be:
821
* 3. default adjust, which means adjust according to the following rules
822
* 3.1 always adjust string, such as MMM and MMMM
823
* 3.2 never adjust between string and numeric, such as MM and MMM
824
* 3.3 always adjust year
825
* 3.4 do not adjust 'd', 'h', or 'm' if h presents
826
* 3.5 do not adjust 'M' if it is numeric(?)
828
* Since date interval format is well-formed format,
829
* date and time skeletons are normalized previously,
830
* till this stage, the adjust here is only "adjust strings, such as MMM
831
* and MMMM, EEE and EEEE.
833
* @param inputSkeleton the input skeleton
834
* @param bestMatchSkeleton the best match skeleton
835
* @param bestMatchIntervalpattern the best match interval pattern
836
* @param differenceInfo the difference between 2 skeletons
837
* 1 means only field width differs
838
* 2 means v/z exchange
839
* @param adjustedIntervalPattern adjusted interval pattern
842
static void U_EXPORT2 adjustFieldWidth(
843
const UnicodeString& inputSkeleton,
844
const UnicodeString& bestMatchSkeleton,
845
const UnicodeString& bestMatchIntervalPattern,
846
int8_t differenceInfo,
847
UnicodeString& adjustedIntervalPattern);
850
* Concat a single date pattern with a time interval pattern,
851
* set it into the intervalPatterns, while field is time field.
852
* This is used to handle time interval patterns on skeleton with
853
* both time and date. Present the date followed by
854
* the range expression for the time.
855
* @param format date and time format
856
* @param formatLen format string length
857
* @param datePattern date pattern
858
* @param field time calendar field: AM_PM, HOUR, MINUTE
859
* @param status output param set to success/failure code on exit
862
void concatSingleDate2TimeInterval(const UChar* format,
864
const UnicodeString& datePattern,
865
UCalendarDateFields field,
869
* check whether a calendar field present in a skeleton.
870
* @param field calendar field need to check
871
* @param skeleton given skeleton on which to check the calendar field
872
* @return true if field present in a skeleton.
875
static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
876
const UnicodeString& skeleton);
880
* Split interval patterns into 2 part.
881
* @param intervalPattern interval pattern
882
* @return the index in interval pattern which split the pattern into 2 part
885
static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
889
* Break interval patterns as 2 part and save them into pattern info.
890
* @param field calendar field
891
* @param intervalPattern interval pattern
894
void setIntervalPattern(UCalendarDateFields field,
895
const UnicodeString& intervalPattern);
899
* Break interval patterns as 2 part and save them into pattern info.
900
* @param field calendar field
901
* @param intervalPattern interval pattern
902
* @param laterDateFirst whether later date appear first in interval pattern
905
void setIntervalPattern(UCalendarDateFields field,
906
const UnicodeString& intervalPattern,
907
UBool laterDateFirst);
911
* Set pattern information.
913
* @param field calendar field
914
* @param firstPart the first part in interval pattern
915
* @param secondPart the second part in interval pattern
916
* @param laterDateFirst whether the first date in intervalPattern
917
* is earlier date or later date
920
void setPatternInfo(UCalendarDateFields field,
921
const UnicodeString* firstPart,
922
const UnicodeString* secondpart,
923
UBool laterDateFirst);
926
// from calendar field to pattern letter
927
static const UChar fgCalendarFieldToPatternLetter[];
931
* The interval patterns for this locale.
933
DateIntervalInfo* fInfo;
936
* The DateFormat object used to format single pattern
938
SimpleDateFormat* fDateFormat;
941
* The 2 calendars with the from and to date.
942
* could re-use the calendar in fDateFormat,
943
* but keeping 2 calendars make it clear and clean.
945
Calendar* fFromCalendar;
946
Calendar* fToCalendar;
949
* Date time pattern generator
951
DateTimePatternGenerator* fDtpng;
954
* Following are interval information relavent (locale) to this formatter.
956
UnicodeString fSkeleton;
957
PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
961
DateIntervalFormat::operator!=(const Format& other) const {
962
return !operator==(other);
967
#endif /* #if !UCONFIG_NO_FORMATTING */
969
#endif // _DTITVFMT_H__