2 * Copyright (c) 2012 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 Copyright (c) 2003-2011, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFDATEFORMATTER__)
29 #define __COREFOUNDATION_CFDATEFORMATTER__ 1
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFDate.h>
33 #include <CoreFoundation/CFLocale.h>
37 typedef struct __CFDateFormatter
*CFDateFormatterRef
;
39 // CFDateFormatters are not thread-safe. Do not use one from multiple threads!
42 CFStringRef
CFDateFormatterCreateDateFormatFromTemplate(CFAllocatorRef allocator
, CFStringRef tmplate
, CFOptionFlags options
, CFLocaleRef locale
) CF_AVAILABLE(10_6
, 4_0
);
43 // no options defined, pass 0 for now
46 CFTypeID
CFDateFormatterGetTypeID(void);
48 enum { // date and time format styles
49 kCFDateFormatterNoStyle
= 0,
50 kCFDateFormatterShortStyle
= 1,
51 kCFDateFormatterMediumStyle
= 2,
52 kCFDateFormatterLongStyle
= 3,
53 kCFDateFormatterFullStyle
= 4
55 typedef CFIndex CFDateFormatterStyle
;
57 // The exact formatted result for these date and time styles depends on the
58 // locale, but generally:
59 // Short is completely numeric, such as "12/13/52" or "3:30pm"
60 // Medium is longer, such as "Jan 12, 1952"
61 // Long is longer, such as "January 12, 1952" or "3:30:32pm"
62 // Full is pretty complete; e.g. "Tuesday, April 12, 1952 AD" or "3:30:42pm PST"
63 // The specifications though are left fuzzy, in part simply because a user's
64 // preference choices may affect the output, and also the results may change
65 // from one OS release to another. To produce an exactly formatted date you
66 // should not rely on styles and localization, but set the format string and
67 // use nothing but numbers.
70 CFDateFormatterRef
CFDateFormatterCreate(CFAllocatorRef allocator
, CFLocaleRef locale
, CFDateFormatterStyle dateStyle
, CFDateFormatterStyle timeStyle
);
71 // Returns a CFDateFormatter, localized to the given locale, which
72 // will format dates to the given date and time styles.
75 CFLocaleRef
CFDateFormatterGetLocale(CFDateFormatterRef formatter
);
78 CFDateFormatterStyle
CFDateFormatterGetDateStyle(CFDateFormatterRef formatter
);
81 CFDateFormatterStyle
CFDateFormatterGetTimeStyle(CFDateFormatterRef formatter
);
82 // Get the properties with which the date formatter was created.
85 CFStringRef
CFDateFormatterGetFormat(CFDateFormatterRef formatter
);
88 void CFDateFormatterSetFormat(CFDateFormatterRef formatter
, CFStringRef formatString
);
89 // Set the format description string of the date formatter. This
90 // overrides the style settings. The format of the format string
91 // is as defined by the ICU library. The date formatter starts with a
92 // default format string defined by the style arguments with
93 // which it was created.
97 CFStringRef
CFDateFormatterCreateStringWithDate(CFAllocatorRef allocator
, CFDateFormatterRef formatter
, CFDateRef date
);
100 CFStringRef
CFDateFormatterCreateStringWithAbsoluteTime(CFAllocatorRef allocator
, CFDateFormatterRef formatter
, CFAbsoluteTime at
);
101 // Create a string representation of the given date or CFAbsoluteTime
102 // using the current state of the date formatter.
106 CFDateRef
CFDateFormatterCreateDateFromString(CFAllocatorRef allocator
, CFDateFormatterRef formatter
, CFStringRef string
, CFRange
*rangep
);
109 Boolean
CFDateFormatterGetAbsoluteTimeFromString(CFDateFormatterRef formatter
, CFStringRef string
, CFRange
*rangep
, CFAbsoluteTime
*atp
);
110 // Parse a string representation of a date using the current state
111 // of the date formatter. The range parameter specifies the range
112 // of the string in which the parsing should occur in input, and on
113 // output indicates the extent that was used; this parameter can
114 // be NULL, in which case the whole string may be used. The
115 // return value indicates whether some date was computed and
116 // (if atp is not NULL) stored at the location specified by atp.
120 void CFDateFormatterSetProperty(CFDateFormatterRef formatter
, CFStringRef key
, CFTypeRef value
);
123 CFTypeRef
CFDateFormatterCopyProperty(CFDateFormatterRef formatter
, CFStringRef key
);
124 // Set and get various properties of the date formatter, the set of
125 // which may be expanded in the future.
127 CF_EXPORT
const CFStringRef kCFDateFormatterIsLenient
; // CFBoolean
128 CF_EXPORT
const CFStringRef kCFDateFormatterTimeZone
; // CFTimeZone
129 CF_EXPORT
const CFStringRef kCFDateFormatterCalendarName
; // CFString
130 CF_EXPORT
const CFStringRef kCFDateFormatterDefaultFormat
; // CFString
131 CF_EXPORT
const CFStringRef kCFDateFormatterTwoDigitStartDate
; // CFDate
132 CF_EXPORT
const CFStringRef kCFDateFormatterDefaultDate
; // CFDate
133 CF_EXPORT
const CFStringRef kCFDateFormatterCalendar
; // CFCalendar
134 CF_EXPORT
const CFStringRef kCFDateFormatterEraSymbols
; // CFArray of CFString
135 CF_EXPORT
const CFStringRef kCFDateFormatterMonthSymbols
; // CFArray of CFString
136 CF_EXPORT
const CFStringRef kCFDateFormatterShortMonthSymbols
; // CFArray of CFString
137 CF_EXPORT
const CFStringRef kCFDateFormatterWeekdaySymbols
; // CFArray of CFString
138 CF_EXPORT
const CFStringRef kCFDateFormatterShortWeekdaySymbols
; // CFArray of CFString
139 CF_EXPORT
const CFStringRef kCFDateFormatterAMSymbol
; // CFString
140 CF_EXPORT
const CFStringRef kCFDateFormatterPMSymbol
; // CFString
141 CF_EXPORT
const CFStringRef kCFDateFormatterLongEraSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
142 CF_EXPORT
const CFStringRef kCFDateFormatterVeryShortMonthSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
143 CF_EXPORT
const CFStringRef kCFDateFormatterStandaloneMonthSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
144 CF_EXPORT
const CFStringRef kCFDateFormatterShortStandaloneMonthSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
145 CF_EXPORT
const CFStringRef kCFDateFormatterVeryShortStandaloneMonthSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
146 CF_EXPORT
const CFStringRef kCFDateFormatterVeryShortWeekdaySymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
147 CF_EXPORT
const CFStringRef kCFDateFormatterStandaloneWeekdaySymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
148 CF_EXPORT
const CFStringRef kCFDateFormatterShortStandaloneWeekdaySymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
149 CF_EXPORT
const CFStringRef kCFDateFormatterVeryShortStandaloneWeekdaySymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
150 CF_EXPORT
const CFStringRef kCFDateFormatterQuarterSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
151 CF_EXPORT
const CFStringRef kCFDateFormatterShortQuarterSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
152 CF_EXPORT
const CFStringRef kCFDateFormatterStandaloneQuarterSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
153 CF_EXPORT
const CFStringRef kCFDateFormatterShortStandaloneQuarterSymbols
CF_AVAILABLE(10_5
, 2_0
); // CFArray of CFString
154 CF_EXPORT
const CFStringRef kCFDateFormatterGregorianStartDate
CF_AVAILABLE(10_5
, 2_0
); // CFDate
155 CF_EXPORT
const CFStringRef kCFDateFormatterDoesRelativeDateFormattingKey
CF_AVAILABLE(10_6
, 4_0
); // CFBoolean
157 // See CFLocale.h for these calendar constants:
158 // const CFStringRef kCFGregorianCalendar;
159 // const CFStringRef kCFBuddhistCalendar;
160 // const CFStringRef kCFJapaneseCalendar;
161 // const CFStringRef kCFIslamicCalendar;
162 // const CFStringRef kCFIslamicCivilCalendar;
163 // const CFStringRef kCFHebrewCalendar;
164 // const CFStringRef kCFChineseCalendar;
165 // const CFStringRef kCFRepublicOfChinaCalendar;
166 // const CFStringRef kCFPersianCalendar;
167 // const CFStringRef kCFIndianCalendar;
168 // const CFStringRef kCFISO8601Calendar; not yet implemented
172 #endif /* ! __COREFOUNDATION_CFDATEFORMATTER__ */