2 *****************************************************************************************
3 * Copyright (C) 2010 Apple Inc. All Rights Reserved.
4 *****************************************************************************************
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_FORMATTING
11 #include "unicode/udatintv.h"
12 #include "unicode/dtitvfmt.h"
13 #include "unicode/dtintrv.h"
14 #include "unicode/locid.h"
15 #include "unicode/unistr.h"
20 U_CAPI UDateIntervalFormat
* U_EXPORT2
21 udatintv_open(const char* locale
,
22 const UChar
* skeleton
,
23 int32_t skeletonLength
,
26 if (U_FAILURE(*status
)) {
29 UnicodeString
skel((UBool
)(skeletonLength
== -1), skeleton
, skeletonLength
);
30 return (UDateIntervalFormat
*)DateIntervalFormat::createInstance(skel
, Locale(locale
), *status
);
35 udatintv_close(UDateIntervalFormat
*datintv
)
37 delete (DateIntervalFormat
*)datintv
;
41 U_INTERNAL
int32_t U_EXPORT2
42 udatintv_format(const UDateIntervalFormat
* datintv
,
46 int32_t resultCapacity
,
47 UFieldPosition
* position
,
50 if (U_FAILURE(*status
)) {
54 if (!(result
==NULL
&& resultCapacity
==0)) {
55 // NULL destination for pure preflighting: empty dummy string
56 // otherwise, alias the destination buffer (copied from udat_format)
57 res
.setTo(result
, 0, resultCapacity
);
61 fp
.setField(position
->field
);
64 DateInterval interval
= DateInterval(fromDate
,toDate
);
65 ((const DateIntervalFormat
*)datintv
)->format( &interval
, res
, fp
, *status
);
66 if (U_FAILURE(*status
)) {
70 position
->beginIndex
= fp
.getBeginIndex();
71 position
->endIndex
= fp
.getEndIndex();
74 return res
.extract(result
, resultCapacity
, *status
);
78 #endif /* #if !UCONFIG_NO_FORMATTING */