ICU 62.1 62.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
33
34
35
223public:
224
239 const UnicodeString& skeleton,
241
277 const UnicodeString& skeleton,
278 const Locale& locale,
280
297 const UnicodeString& skeleton,
300
342 const UnicodeString& skeleton,
343 const Locale& locale,
346
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
402 UnicodeString& appendTo,
404 UErrorCode& status) const ;
405
406
407
424 UnicodeString& appendTo,
426 UErrorCode& status) const ;
427
428
454 UnicodeString& appendTo,
456 UErrorCode& status) const ;
457
484 virtual void parseObject(const UnicodeString& source,
486 ParsePosition& parse_pos) const;
487
488
496
497
506
507
519 const DateFormat* getDateFormat(void) const;
520
526 virtual const TimeZone& getTimeZone(void) const;
527
535
541 virtual void setTimeZone(const TimeZone& zone);
542
555
567 virtual UClassID getDynamicClassID(void) const;
568
569protected:
570
576
582
583private:
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
623
644
645
658 static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
660 const UnicodeString* skeleton,
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}
688
689
712 UnicodeString& fallbackFormat(Calendar& fromCalendar,
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,
769
770
771
796 static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
801
802
803
827 UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
829
830
831
832
856 UBool setIntervalPattern(UCalendarDateFields field,
857 const UnicodeString* skeleton,
859 int8_t differenceInfo,
862
891 static void U_EXPORT2 adjustFieldWidth(
895 int8_t differenceInfo,
897
909 void concatSingleDate2TimeInterval(UnicodeString& format,
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,
939
940
947 void setIntervalPattern(UCalendarDateFields field,
949 UBool laterDateFirst);
950
951
961 void setPatternInfo(UCalendarDateFields field,
962 const UnicodeString* firstPart,
963 const UnicodeString* secondPart,
964 UBool laterDateFirst);
965
993 UnicodeString& appendTo,
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
1036inline UBool
1037DateIntervalFormat::operator!=(const Format& other) const {
1038 return !operator==(other);
1039}
1040
1042
1043#endif /* #if !UCONFIG_NO_FORMATTING */
1044
1045#endif // _DTITVFMT_H__
1046//eof
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition calendar.h:202
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:150
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition dtitvfmt.h:222
virtual Format * clone(void) const
Clone this Format object polymorphically.
virtual void setTimeZone(const TimeZone &zone)
Sets the time zone for the calendar used by this DateIntervalFormat object.
UnicodeString & format(Calendar &fromCalendar, Calendar &toCalendar, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format 2 Calendars to produce a string.
const DateFormat * getDateFormat(void) const
Gets the date formatter.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const
Date interval parsing is not supported.
virtual ~DateIntervalFormat()
Destructor.
const DateIntervalInfo * getDateIntervalInfo(void) const
Gets the date time interval patterns.
virtual const TimeZone & getTimeZone(void) const
Returns a reference to the TimeZone used by this DateIntervalFormat's calendar.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton DateIntervalInfo, and default locale.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual void adoptTimeZone(TimeZone *zoneToAdopt)
Sets the time zone for the calendar used by this DateIntervalFormat object.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and the default locale.
static UClassID getStaticClassID(void)
Return the class ID for this class.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, const DateIntervalInfo &dtitvinf, UErrorCode &status)
Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.
DateIntervalFormat(const DateIntervalFormat &)
Copy constructor.
DateIntervalFormat & operator=(const DateIntervalFormat &)
Assignment operator.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format an object to produce a string.
static DateIntervalFormat * createInstance(const UnicodeString &skeleton, const Locale &locale, UErrorCode &status)
Construct a DateIntervalFormat from skeleton and a given locale.
UnicodeString & format(const DateInterval *dtInterval, UnicodeString &appendTo, FieldPosition &fieldPosition, UErrorCode &status) const
Format a DateInterval to produce a string.
void setDateIntervalInfo(const DateIntervalInfo &newIntervalPatterns, UErrorCode &status)
Set the date time interval patterns.
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns.
Definition dtitvinf.h:153
This class represents a date interval.
Definition dtintrv.h:34
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:108
Base class for all formats.
Definition format.h:96
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition format.h:121
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:49
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition smpdtfmt.h:723
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:131
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
C++ API: Date Interval data type.
C++ API: Date/Time interval patterns for formatting date/time interval.
C++ API: Date/Time Pattern Generator.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: Format and parse dates in a language-independent manner.
C API: Calendar.
UCalendarDateFields
Possible fields in a UCalendar.
Definition ucal.h:185
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition utypes.h:188
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137