]> git.saurik.com Git - apple/cf.git/blob - CFDateFormatter.h
CF-1152.14.tar.gz
[apple/cf.git] / CFDateFormatter.h
1 /*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* CFDateFormatter.h
25 Copyright (c) 2003-2014, Apple Inc. All rights reserved.
26 */
27
28 #if !defined(__COREFOUNDATION_CFDATEFORMATTER__)
29 #define __COREFOUNDATION_CFDATEFORMATTER__ 1
30
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFDate.h>
33 #include <CoreFoundation/CFLocale.h>
34
35 CF_IMPLICIT_BRIDGING_ENABLED
36 CF_EXTERN_C_BEGIN
37
38 typedef struct __CFDateFormatter *CFDateFormatterRef;
39
40 // CFDateFormatters are not thread-safe. Do not use one from multiple threads!
41
42 CF_EXPORT
43 CFStringRef CFDateFormatterCreateDateFormatFromTemplate(CFAllocatorRef allocator, CFStringRef tmplate, CFOptionFlags options, CFLocaleRef locale) CF_AVAILABLE(10_6, 4_0);
44 // no options defined, pass 0 for now
45
46 CF_EXPORT
47 CFTypeID CFDateFormatterGetTypeID(void);
48
49 typedef CF_ENUM(CFIndex, CFDateFormatterStyle) { // date and time format styles
50 kCFDateFormatterNoStyle = 0,
51 kCFDateFormatterShortStyle = 1,
52 kCFDateFormatterMediumStyle = 2,
53 kCFDateFormatterLongStyle = 3,
54 kCFDateFormatterFullStyle = 4
55 };
56
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.
68
69 CF_EXPORT
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.
73
74 CF_EXPORT
75 CFLocaleRef CFDateFormatterGetLocale(CFDateFormatterRef formatter);
76
77 CF_EXPORT
78 CFDateFormatterStyle CFDateFormatterGetDateStyle(CFDateFormatterRef formatter);
79
80 CF_EXPORT
81 CFDateFormatterStyle CFDateFormatterGetTimeStyle(CFDateFormatterRef formatter);
82 // Get the properties with which the date formatter was created.
83
84 CF_EXPORT
85 CFStringRef CFDateFormatterGetFormat(CFDateFormatterRef formatter);
86
87 CF_EXPORT
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.
94
95
96 CF_EXPORT
97 CFStringRef CFDateFormatterCreateStringWithDate(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFDateRef date);
98
99 CF_EXPORT
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.
103
104
105 CF_EXPORT
106 CFDateRef CFDateFormatterCreateDateFromString(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFStringRef string, CFRange *rangep);
107
108 CF_EXPORT
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.
117
118
119 CF_EXPORT
120 void CFDateFormatterSetProperty(CFDateFormatterRef formatter, CFStringRef key, CFTypeRef value);
121
122 CF_EXPORT
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.
126
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
156
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;
169
170 CF_EXTERN_C_END
171 CF_IMPLICIT_BRIDGING_DISABLED
172
173 #endif /* ! __COREFOUNDATION_CFDATEFORMATTER__ */
174