ICU 63.1 63.1

dtitvfmt.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************************
4 * Copyright (C) 2008-2016, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 *******************************************************************************
7 *
8 * File DTITVFMT.H
9 *
10 *******************************************************************************
11 */
12
13 #ifndef __DTITVFMT_H__
14 #define __DTITVFMT_H__
15
16
17 #include "unicode/utypes.h"
18
24 #if !UCONFIG_NO_FORMATTING
25
26 #include "unicode/ucal.h"
27 #include "unicode/smpdtfmt.h"
28 #include "unicode/dtintrv.h"
29 #include "unicode/dtitvinf.h"
30 #include "unicode/dtptngen.h"
31
32 U_NAMESPACE_BEGIN
33
34
35
222 class U_I18N_API DateIntervalFormat : public Format {
223 public:
224
238 static DateIntervalFormat* U_EXPORT2 createInstance(
239 const UnicodeString& skeleton,
240 UErrorCode& status);
241
276 static DateIntervalFormat* U_EXPORT2 createInstance(
277 const UnicodeString& skeleton,
278 const Locale& locale,
279 UErrorCode& status);
280
296 static DateIntervalFormat* U_EXPORT2 createInstance(
297 const UnicodeString& skeleton,
298 const DateIntervalInfo& dtitvinf,
299 UErrorCode& status);
300
341 static DateIntervalFormat* U_EXPORT2 createInstance(
342 const UnicodeString& skeleton,
343 const Locale& locale,
344 const DateIntervalInfo& dtitvinf,
345 UErrorCode& status);
346
351 virtual ~DateIntervalFormat();
352
359 virtual Format* clone(void) const;
360
368 virtual UBool operator==(const Format& other) const;
369
377 UBool operator!=(const Format& other) const;
378
379
380 using Format::format;
381
401 virtual UnicodeString& format(const Formattable& obj,
402 UnicodeString& appendTo,
403 FieldPosition& fieldPosition,
404 UErrorCode& status) const ;
405
406
407
423 UnicodeString& format(const DateInterval* dtInterval,
424 UnicodeString& appendTo,
425 FieldPosition& fieldPosition,
426 UErrorCode& status) const ;
427
428
452 UnicodeString& format(Calendar& fromCalendar,
453 Calendar& toCalendar,
454 UnicodeString& appendTo,
455 FieldPosition& fieldPosition,
456 UErrorCode& status) const ;
457
484 virtual void parseObject(const UnicodeString& source,
485 Formattable& result,
486 ParsePosition& parse_pos) const;
487
488
495 const DateIntervalInfo* getDateIntervalInfo(void) const;
496
497
504 void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
505 UErrorCode& status);
506
507
519 const DateFormat* getDateFormat(void) const;
520
526 virtual const TimeZone& getTimeZone(void) const;
527
534 virtual void adoptTimeZone(TimeZone* zoneToAdopt);
535
541 virtual void setTimeZone(const TimeZone& zone);
542
554 static UClassID U_EXPORT2 getStaticClassID(void);
555
567 virtual UClassID getDynamicClassID(void) const;
568
569 protected:
570
575 DateIntervalFormat(const DateIntervalFormat&);
576
581 DateIntervalFormat& operator=(const DateIntervalFormat&);
582
583 private:
584
585 /*
586 * This is for ICU internal use only. Please do not use.
587 * Save the interval pattern information.
588 * Interval pattern consists of 2 single date patterns and the separator.
589 * For example, interval pattern "MMM d - MMM d, yyyy" consists
590 * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
591 * and a separator "-".
592 * The pattern is divided into 2 parts. For above example,
593 * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
594 * Also, the first date appears in an interval pattern could be
595 * the earlier date or the later date.
596 * And such information is saved in the interval pattern as well.
597 */
598 struct PatternInfo {
599 UnicodeString firstPart;
600 UnicodeString secondPart;
614 UBool laterDateFirst;
615 };
616
617
622 DateIntervalFormat();
623
642 DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
643 const UnicodeString* skeleton, UErrorCode& status);
644
645
658 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
659 DateIntervalInfo* dtitvinf,
660 const UnicodeString* skeleton,
661 UErrorCode& status);
662
683 static void
684 adjustPosition(UnicodeString& combiningPattern, // has {0} and {1} in it
685 UnicodeString& pat0, FieldPosition& pos0, // pattern and pos corresponding to {0}
686 UnicodeString& pat1, FieldPosition& pos1, // pattern and pos corresponding to {1}
687 FieldPosition& posResult);
688
689
712 UnicodeString& fallbackFormat(Calendar& fromCalendar,
713 Calendar& toCalendar,
714 UBool fromToOnSameDay,
715 UnicodeString& appendTo,
716 FieldPosition& pos,
717 UErrorCode& status) const;
718
719
720
755 void initializePattern(UErrorCode& status);
756
757
758
766 void setFallbackPattern(UCalendarDateFields field,
767 const UnicodeString& skeleton,
768 UErrorCode& status);
769
770
771
796 static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
797 UnicodeString& date,
798 UnicodeString& normalizedDate,
799 UnicodeString& time,
800 UnicodeString& normalizedTime);
801
802
803
827 UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
828 const UnicodeString& timeSkeleton);
829
830
831
832
856 UBool setIntervalPattern(UCalendarDateFields field,
857 const UnicodeString* skeleton,
858 const UnicodeString* bestSkeleton,
859 int8_t differenceInfo,
860 UnicodeString* extendedSkeleton = NULL,
861 UnicodeString* extendedBestSkeleton = NULL);
862
891 static void U_EXPORT2 adjustFieldWidth(
892 const UnicodeString& inputSkeleton,
893 const UnicodeString& bestMatchSkeleton,
894 const UnicodeString& bestMatchIntervalPattern,
895 int8_t differenceInfo,
896 UnicodeString& adjustedIntervalPattern);
897
909 void concatSingleDate2TimeInterval(UnicodeString& format,
910 const UnicodeString& datePattern,
911 UCalendarDateFields field,
912 UErrorCode& status);
913
920 static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
921 const UnicodeString& skeleton);
922
923
929 static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
930
931
937 void setIntervalPattern(UCalendarDateFields field,
938 const UnicodeString& intervalPattern);
939
940
947 void setIntervalPattern(UCalendarDateFields field,
948 const UnicodeString& intervalPattern,
949 UBool laterDateFirst);
950
951
961 void setPatternInfo(UCalendarDateFields field,
962 const UnicodeString* firstPart,
963 const UnicodeString* secondPart,
964 UBool laterDateFirst);
965
991 UnicodeString& formatImpl(Calendar& fromCalendar,
992 Calendar& toCalendar,
993 UnicodeString& appendTo,
994 FieldPosition& fieldPosition,
995 UErrorCode& status) const ;
996
997
998 // from calendar field to pattern letter
999 static const char16_t fgCalendarFieldToPatternLetter[];
1000
1001
1005 DateIntervalInfo* fInfo;
1006
1010 SimpleDateFormat* fDateFormat;
1011
1017 Calendar* fFromCalendar;
1018 Calendar* fToCalendar;
1019
1020 Locale fLocale;
1021
1025 UnicodeString fSkeleton;
1026 PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
1027
1031 UnicodeString* fDatePattern;
1032 UnicodeString* fTimePattern;
1033 UnicodeString* fDateTimeFormat;
1034 };
1035
1036 inline UBool
1037 DateIntervalFormat::operator!=(const Format& other) const {
1038 return !operator==(other);
1039 }
1040
1041 U_NAMESPACE_END
1042
1043 #endif /* #if !UCONFIG_NO_FORMATTING */
1044
1045 #endif // _DTITVFMT_H__
1046 //eof
icu::Format
Base class for all formats.
Definition: format.h:96
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:198
icu::DateIntervalFormat
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:222
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:121
ucal.h
C API: Calendar.
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
dtptngen.h
C++ API: Date/Time Pattern Generator.
icu::DateIntervalInfo
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns...
Definition: dtitvinf.h:153
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:185
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
icu::DateInterval
This class represents a date interval.
Definition: dtintrv.h:34
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
smpdtfmt.h
C++ API: Format and parse dates in a language-independent manner.
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
dtintrv.h
C++ API: Date Interval data type.
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:723
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:154
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
dtitvinf.h
C++ API: Date/Time interval patterns for formatting date/time interval.
icu::Format::operator=
Format & operator=(const Format &)
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192