1/* 2 * Copyright (c) 2014 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 35CF_EXTERN_C_BEGIN 36 37typedef struct __CFDateFormatter *CFDateFormatterRef; 38 39// CFDateFormatters are not thread-safe. Do not use one from multiple threads! 40 41CF_EXPORT 42CFStringRef CFDateFormatterCreateDateFormatFromTemplate(CFAllocatorRef allocator, CFStringRef tmplate, CFOptionFlags options, CFLocaleRef locale) CF_AVAILABLE(10_6, 4_0); 43 // no options defined, pass 0 for now 44 45CF_EXPORT 46CFTypeID CFDateFormatterGetTypeID(void); 47 48typedef 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 68CF_EXPORT 69CFDateFormatterRef 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 73CF_EXPORT 74CFLocaleRef CFDateFormatterGetLocale(CFDateFormatterRef formatter); 75 76CF_EXPORT 77CFDateFormatterStyle CFDateFormatterGetDateStyle(CFDateFormatterRef formatter); 78 79CF_EXPORT 80CFDateFormatterStyle CFDateFormatterGetTimeStyle(CFDateFormatterRef formatter); 81 // Get the properties with which the date formatter was created. 82 83CF_EXPORT 84CFStringRef CFDateFormatterGetFormat(CFDateFormatterRef formatter); 85 86CF_EXPORT 87void 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 95CF_EXPORT 96CFStringRef CFDateFormatterCreateStringWithDate(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFDateRef date); 97 98CF_EXPORT 99CFStringRef 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 104CF_EXPORT 105CFDateRef CFDateFormatterCreateDateFromString(CFAllocatorRef allocator, CFDateFormatterRef formatter, CFStringRef string, CFRange *rangep); 106 107CF_EXPORT 108Boolean 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 118CF_EXPORT 119void CFDateFormatterSetProperty(CFDateFormatterRef formatter, CFStringRef key, CFTypeRef value); 120 121CF_EXPORT 122CFTypeRef 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 126CF_EXPORT const CFStringRef kCFDateFormatterIsLenient; // CFBoolean 127CF_EXPORT const CFStringRef kCFDateFormatterTimeZone; // CFTimeZone 128CF_EXPORT const CFStringRef kCFDateFormatterCalendarName; // CFString 129CF_EXPORT const CFStringRef kCFDateFormatterDefaultFormat; // CFString 130CF_EXPORT const CFStringRef kCFDateFormatterTwoDigitStartDate; // CFDate 131CF_EXPORT const CFStringRef kCFDateFormatterDefaultDate; // CFDate 132CF_EXPORT const CFStringRef kCFDateFormatterCalendar; // CFCalendar 133CF_EXPORT const CFStringRef kCFDateFormatterEraSymbols; // CFArray of CFString 134CF_EXPORT const CFStringRef kCFDateFormatterMonthSymbols; // CFArray of CFString 135CF_EXPORT const CFStringRef kCFDateFormatterShortMonthSymbols; // CFArray of CFString 136CF_EXPORT const CFStringRef kCFDateFormatterWeekdaySymbols; // CFArray of CFString 137CF_EXPORT const CFStringRef kCFDateFormatterShortWeekdaySymbols; // CFArray of CFString 138CF_EXPORT const CFStringRef kCFDateFormatterAMSymbol; // CFString 139CF_EXPORT const CFStringRef kCFDateFormatterPMSymbol; // CFString 140CF_EXPORT const CFStringRef kCFDateFormatterLongEraSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 141CF_EXPORT const CFStringRef kCFDateFormatterVeryShortMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 142CF_EXPORT const CFStringRef kCFDateFormatterStandaloneMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 143CF_EXPORT const CFStringRef kCFDateFormatterShortStandaloneMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 144CF_EXPORT const CFStringRef kCFDateFormatterVeryShortStandaloneMonthSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 145CF_EXPORT const CFStringRef kCFDateFormatterVeryShortWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 146CF_EXPORT const CFStringRef kCFDateFormatterStandaloneWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 147CF_EXPORT const CFStringRef kCFDateFormatterShortStandaloneWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 148CF_EXPORT const CFStringRef kCFDateFormatterVeryShortStandaloneWeekdaySymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 149CF_EXPORT const CFStringRef kCFDateFormatterQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 150CF_EXPORT const CFStringRef kCFDateFormatterShortQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 151CF_EXPORT const CFStringRef kCFDateFormatterStandaloneQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 152CF_EXPORT const CFStringRef kCFDateFormatterShortStandaloneQuarterSymbols CF_AVAILABLE(10_5, 2_0); // CFArray of CFString 153CF_EXPORT const CFStringRef kCFDateFormatterGregorianStartDate CF_AVAILABLE(10_5, 2_0); // CFDate 154CF_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 169CF_EXTERN_C_END 170 171#endif /* ! __COREFOUNDATION_CFDATEFORMATTER__ */ 172 173