]> git.saurik.com Git - apple/cf.git/blob - CFDateFormatter.h
CF-855.11.tar.gz
[apple/cf.git] / CFDateFormatter.h
1 /*
2 * Copyright (c) 2013 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-2013, 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_EXTERN_C_BEGIN
36
37 typedef struct __CFDateFormatter *CFDateFormatterRef;
38
39 // CFDateFormatters are not thread-safe. Do not use one from multiple threads!
40
41 CF_EXPORT
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
44
45 CF_EXPORT
46 CFTypeID CFDateFormatterGetTypeID(void);
47
48 typedef CF_ENUM(CFIndex, CFDateFormatterStyle) { // date and time format styles
49 kCFDateFormatterNoStyle = 0,
50 kCFDateFormatterShortStyle = 1,
51 kCFDateFormatterMediumStyle = 2,
52 kCFDateFormatterLongStyle = 3,
53 kCFDateFormatterFullStyle = 4
54 };
55
56 // The exact formatted result for these date and time styles depends on the
57 // locale, but generally:
58 // Short is completely numeric, such as "12/13/52" or "3:30pm"
59 // Medium is longer, such as "Jan 12, 1952"
60 // Long is longer, such as "January 12, 1952" or "3:30:32pm"
61 // Full is pretty complete; e.g. "Tuesday, April 12, 1952 AD" or "3:30:42pm PST"
62 // The specifications though are left fuzzy, in part simply because a user's
63 // preference choices may affect the output, and also the results may change
64 // from one OS release to another. To produce an exactly formatted date you
65 // should not rely on styles and localization, but set the format string and
66 // use nothing but numbers.
67
68 CF_EXPORT
69 CFDateFormatterRef CFDateFormatterCreate(CFAllocatorRef allocator, CFLocaleRef locale, CFDateFormatterStyle dateStyle, CFDateFormatterStyle timeStyle);
70 // Returns a CFDateFormatter, localized to the given locale, which
71 // will format dates to the given date and time styles.
72
73 CF_EXPORT
74 CFLocaleRef CFDateFormatterGetLocale(CFDateFormatterRef formatter);
75
76 CF_EXPORT
77 CFDateFormatterStyle CFDateFormatterGetDateStyle(CFDateFormatterRef formatter);
78
79 CF_EXPORT
80 CFDateFormatterStyle CFDateFormatterGetTimeStyle(CFDateFormatterRef formatter);
81 // Get the properties with which the date formatter was created.
82
83 CF_EXPORT
84 CFStringRef CFDateFormatterGetFormat(CFDateFormatterRef formatter);
85
86 CF_EXPORT
87 void CFDateFormatterSetFormat(CFDateFormatterRef formatter, CFStringRef formatString);
88 // Set the format description string of the date formatter. This
89 // overrides the style settings. The format of the format string
90 // is as defined by the ICU library. The date formatter starts with a
91 // default format string defined by the style arguments with
92 // which it was created.
93
94
95 CF_EXPORT
96 CFStringRef CFDateFormatterCreateStringWithDate(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFDateRef date);
97
98 CF_EXPORT
99 CFStringRef CFDateFormatterCreateStringWithAbsoluteTime(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFAbsoluteTime at);
100 // Create a string representation of the given date or CFAbsoluteTime
101 // using the current state of the date formatter.
102
103
104 CF_EXPORT
105 CFDateRef CFDateFormatterCreateDateFromString(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFStringRef string, CFRange *rangep);
106
107 CF_EXPORT
108 Boolean CFDateFormatterGetAbsoluteTimeFromString(CFDateFormatterRef formatter, CFStringRef string, CFRange *rangep, CFAbsoluteTime *atp);
109 // Parse a string representation of a date using the current state
110 // of the date formatter. The range parameter specifies the range
111 // of the string in which the parsing should occur in input, and on
112 // output indicates the extent that was used; this parameter can
113 // be NULL, in which case the whole string may be used. The
114 // return value indicates whether some date was computed and
115 // (if atp is not NULL) stored at the location specified by atp.
116
117
118 CF_EXPORT
119 void CFDateFormatterSetProperty(CFDateFormatterRef formatter, CFStringRef key, CFTypeRef value);
120
121 CF_EXPORT
122 CFTypeRef CFDateFormatterCopyProperty(CFDateFormatterRef formatter, CFStringRef key);
123 // Set and get various properties of the date formatter, the set of
124 // which may be expanded in the future.
125
126 CF_EXPORT const CFStringRef kCFDateFormatterIsLenient; // CFBoolean
127 CF_EXPORT const CFStringRef kCFDateFormatterTimeZone; // CFTimeZone
128 CF_EXPORT const CFStringRef kCFDateFormatterCalendarName; // CFString
129 CF_EXPORT const CFStringRef kCFDateFormatterDefaultFormat; // CFString
130 CF_EXPORT const CFStringRef kCFDateFormatterTwoDigitStartDate; // CFDate
131 CF_EXPORT const CFStringRef kCFDateFormatterDefaultDate; // CFDate
132 CF_EXPORT const CFStringRef kCFDateFormatterCalendar; // CFCalendar
133 CF_EXPORT const CFStringRef kCFDateFormatterEraSymbols; // CFArray of CFString
134 CF_EXPORT const CFStringRef kCFDateFormatterMonthSymbols; // CFArray of CFString
135 CF_EXPORT const CFStringRef kCFDateFormatterShortMonthSymbols; // CFArray of CFString
136 CF_EXPORT const CFStringRef kCFDateFormatterWeekdaySymbols; // CFArray of CFString
137 CF_EXPORT const CFStringRef kCFDateFormatterShortWeekdaySymbols; // CFArray of CFString
138 CF_EXPORT const CFStringRef kCFDateFormatterAMSymbol; // CFString
139 CF_EXPORT const CFStringRef kCFDateFormatterPMSymbol; // CFString
140 CF_EXPORT const CFStringRef kCFDateFormatterLongEraSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
141 CF_EXPORT const CFStringRef kCFDateFormatterVeryShortMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
142 CF_EXPORT const CFStringRef kCFDateFormatterStandaloneMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
143 CF_EXPORT const CFStringRef kCFDateFormatterShortStandaloneMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
144 CF_EXPORT const CFStringRef kCFDateFormatterVeryShortStandaloneMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
145 CF_EXPORT const CFStringRef kCFDateFormatterVeryShortWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
146 CF_EXPORT const CFStringRef kCFDateFormatterStandaloneWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
147 CF_EXPORT const CFStringRef kCFDateFormatterShortStandaloneWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
148 CF_EXPORT const CFStringRef kCFDateFormatterVeryShortStandaloneWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
149 CF_EXPORT const CFStringRef kCFDateFormatterQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
150 CF_EXPORT const CFStringRef kCFDateFormatterShortQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
151 CF_EXPORT const CFStringRef kCFDateFormatterStandaloneQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
152 CF_EXPORT const CFStringRef kCFDateFormatterShortStandaloneQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString
153 CF_EXPORT const CFStringRef kCFDateFormatterGregorianStartDate CF_AVAILABLE(10_5, 2_0); // CFDate
154 CF_EXPORT const CFStringRef kCFDateFormatterDoesRelativeDateFormattingKey CF_AVAILABLE(10_6, 4_0); // CFBoolean
155
156 // See CFLocale.h for these calendar constants:
157 // const CFStringRef kCFGregorianCalendar;
158 // const CFStringRef kCFBuddhistCalendar;
159 // const CFStringRef kCFJapaneseCalendar;
160 // const CFStringRef kCFIslamicCalendar;
161 // const CFStringRef kCFIslamicCivilCalendar;
162 // const CFStringRef kCFHebrewCalendar;
163 // const CFStringRef kCFChineseCalendar;
164 // const CFStringRef kCFRepublicOfChinaCalendar;
165 // const CFStringRef kCFPersianCalendar;
166 // const CFStringRef kCFIndianCalendar;
167 // const CFStringRef kCFISO8601Calendar;
168
169 CF_EXTERN_C_END
170
171 #endif /* ! __COREFOUNDATION_CFDATEFORMATTER__ */
172