objc2_core_foundation/generated/
CFDate.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftimeinterval?language=objc)
13pub type CFTimeInterval = c_double;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfabsolutetime?language=objc)
16pub type CFAbsoluteTime = CFTimeInterval;
17
18#[inline]
19pub extern "C-unwind" fn CFAbsoluteTimeGetCurrent() -> CFAbsoluteTime {
20    extern "C-unwind" {
21        fn CFAbsoluteTimeGetCurrent() -> CFAbsoluteTime;
22    }
23    unsafe { CFAbsoluteTimeGetCurrent() }
24}
25
26extern "C" {
27    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfabsolutetimeintervalsince1970?language=objc)
28    pub static kCFAbsoluteTimeIntervalSince1970: CFTimeInterval;
29}
30
31extern "C" {
32    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfabsolutetimeintervalsince1904?language=objc)
33    pub static kCFAbsoluteTimeIntervalSince1904: CFTimeInterval;
34}
35
36/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdate?language=objc)
37///
38/// This is toll-free bridged with `NSDate`.
39#[doc(alias = "CFDateRef")]
40#[repr(C)]
41pub struct CFDate {
42    inner: [u8; 0],
43    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
44}
45
46cf_type!(
47    unsafe impl CFDate {}
48);
49#[cfg(feature = "objc2")]
50cf_objc2_type!(
51    unsafe impl RefEncode<"__CFDate"> for CFDate {}
52);
53
54unsafe impl ConcreteType for CFDate {
55    #[doc(alias = "CFDateGetTypeID")]
56    #[inline]
57    fn type_id() -> CFTypeID {
58        extern "C-unwind" {
59            fn CFDateGetTypeID() -> CFTypeID;
60        }
61        unsafe { CFDateGetTypeID() }
62    }
63}
64
65impl CFDate {
66    #[doc(alias = "CFDateCreate")]
67    #[inline]
68    pub fn new(allocator: Option<&CFAllocator>, at: CFAbsoluteTime) -> Option<CFRetained<CFDate>> {
69        extern "C-unwind" {
70            fn CFDateCreate(
71                allocator: Option<&CFAllocator>,
72                at: CFAbsoluteTime,
73            ) -> Option<NonNull<CFDate>>;
74        }
75        let ret = unsafe { CFDateCreate(allocator, at) };
76        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
77    }
78
79    #[doc(alias = "CFDateGetAbsoluteTime")]
80    #[inline]
81    pub fn absolute_time(&self) -> CFAbsoluteTime {
82        extern "C-unwind" {
83            fn CFDateGetAbsoluteTime(the_date: &CFDate) -> CFAbsoluteTime;
84        }
85        unsafe { CFDateGetAbsoluteTime(self) }
86    }
87
88    #[doc(alias = "CFDateGetTimeIntervalSinceDate")]
89    #[inline]
90    pub fn time_interval_since_date(&self, other_date: Option<&CFDate>) -> CFTimeInterval {
91        extern "C-unwind" {
92            fn CFDateGetTimeIntervalSinceDate(
93                the_date: &CFDate,
94                other_date: Option<&CFDate>,
95            ) -> CFTimeInterval;
96        }
97        unsafe { CFDateGetTimeIntervalSinceDate(self, other_date) }
98    }
99
100    /// # Safety
101    ///
102    /// - `other_date` might not allow `None`.
103    /// - `context` must be a valid pointer.
104    #[doc(alias = "CFDateCompare")]
105    #[inline]
106    pub unsafe fn compare(
107        &self,
108        other_date: Option<&CFDate>,
109        context: *mut c_void,
110    ) -> CFComparisonResult {
111        extern "C-unwind" {
112            fn CFDateCompare(
113                the_date: &CFDate,
114                other_date: Option<&CFDate>,
115                context: *mut c_void,
116            ) -> CFComparisonResult;
117        }
118        unsafe { CFDateCompare(self, other_date, context) }
119    }
120}
121
122/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftimezone?language=objc)
123///
124/// This is toll-free bridged with `NSTimeZone`.
125#[doc(alias = "CFTimeZoneRef")]
126#[repr(C)]
127pub struct CFTimeZone {
128    inner: [u8; 0],
129    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
130}
131
132cf_type!(
133    unsafe impl CFTimeZone {}
134);
135#[cfg(feature = "objc2")]
136cf_objc2_type!(
137    unsafe impl RefEncode<"__CFTimeZone"> for CFTimeZone {}
138);
139
140/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfgregoriandate?language=objc)
141#[repr(C)]
142#[derive(Clone, Copy, Debug, PartialEq)]
143pub struct CFGregorianDate {
144    pub year: i32,
145    pub month: i8,
146    pub day: i8,
147    pub hour: i8,
148    pub minute: i8,
149    pub second: c_double,
150}
151
152#[cfg(feature = "objc2")]
153unsafe impl Encode for CFGregorianDate {
154    const ENCODING: Encoding = Encoding::Struct(
155        "?",
156        &[
157            <i32>::ENCODING,
158            <i8>::ENCODING,
159            <i8>::ENCODING,
160            <i8>::ENCODING,
161            <i8>::ENCODING,
162            <c_double>::ENCODING,
163        ],
164    );
165}
166
167#[cfg(feature = "objc2")]
168unsafe impl RefEncode for CFGregorianDate {
169    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
170}
171
172/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfgregorianunits?language=objc)
173#[repr(C)]
174#[derive(Clone, Copy, Debug, PartialEq)]
175pub struct CFGregorianUnits {
176    pub years: i32,
177    pub months: i32,
178    pub days: i32,
179    pub hours: i32,
180    pub minutes: i32,
181    pub seconds: c_double,
182}
183
184#[cfg(feature = "objc2")]
185unsafe impl Encode for CFGregorianUnits {
186    const ENCODING: Encoding = Encoding::Struct(
187        "?",
188        &[
189            <i32>::ENCODING,
190            <i32>::ENCODING,
191            <i32>::ENCODING,
192            <i32>::ENCODING,
193            <i32>::ENCODING,
194            <c_double>::ENCODING,
195        ],
196    );
197}
198
199#[cfg(feature = "objc2")]
200unsafe impl RefEncode for CFGregorianUnits {
201    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
202}
203
204/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfgregorianunitflags?language=objc)
205// NS_OPTIONS
206#[repr(transparent)]
207#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
208pub struct CFGregorianUnitFlags(pub CFOptionFlags);
209bitflags::bitflags! {
210    impl CFGregorianUnitFlags: CFOptionFlags {
211        #[doc(alias = "kCFGregorianUnitsYears")]
212#[deprecated = "Use CFCalendar or NSCalendar API instead"]
213        const UnitsYears = 1<<0;
214        #[doc(alias = "kCFGregorianUnitsMonths")]
215#[deprecated = "Use CFCalendar or NSCalendar API instead"]
216        const UnitsMonths = 1<<1;
217        #[doc(alias = "kCFGregorianUnitsDays")]
218#[deprecated = "Use CFCalendar or NSCalendar API instead"]
219        const UnitsDays = 1<<2;
220        #[doc(alias = "kCFGregorianUnitsHours")]
221#[deprecated = "Use CFCalendar or NSCalendar API instead"]
222        const UnitsHours = 1<<3;
223        #[doc(alias = "kCFGregorianUnitsMinutes")]
224#[deprecated = "Use CFCalendar or NSCalendar API instead"]
225        const UnitsMinutes = 1<<4;
226        #[doc(alias = "kCFGregorianUnitsSeconds")]
227#[deprecated = "Use CFCalendar or NSCalendar API instead"]
228        const UnitsSeconds = 1<<5;
229        #[doc(alias = "kCFGregorianAllUnits")]
230#[deprecated = "Use CFCalendar or NSCalendar API instead"]
231        const AllUnits = 0x00FFFFFF;
232    }
233}
234
235#[cfg(feature = "objc2")]
236unsafe impl Encode for CFGregorianUnitFlags {
237    const ENCODING: Encoding = CFOptionFlags::ENCODING;
238}
239
240#[cfg(feature = "objc2")]
241unsafe impl RefEncode for CFGregorianUnitFlags {
242    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
243}
244
245impl CFGregorianDate {
246    #[doc(alias = "CFGregorianDateIsValid")]
247    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
248    #[inline]
249    pub fn is_valid(self, unit_flags: CFOptionFlags) -> bool {
250        extern "C-unwind" {
251            fn CFGregorianDateIsValid(gdate: CFGregorianDate, unit_flags: CFOptionFlags)
252                -> Boolean;
253        }
254        let ret = unsafe { CFGregorianDateIsValid(self, unit_flags) };
255        ret != 0
256    }
257
258    /// # Safety
259    ///
260    /// `tz` might not allow `None`.
261    #[doc(alias = "CFGregorianDateGetAbsoluteTime")]
262    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
263    #[inline]
264    pub unsafe fn absolute_time(self, tz: Option<&CFTimeZone>) -> CFAbsoluteTime {
265        extern "C-unwind" {
266            fn CFGregorianDateGetAbsoluteTime(
267                gdate: CFGregorianDate,
268                tz: Option<&CFTimeZone>,
269            ) -> CFAbsoluteTime;
270        }
271        unsafe { CFGregorianDateGetAbsoluteTime(self, tz) }
272    }
273}
274
275extern "C-unwind" {
276    /// # Safety
277    ///
278    /// `tz` might not allow `None`.
279    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
280    pub fn CFAbsoluteTimeGetGregorianDate(
281        at: CFAbsoluteTime,
282        tz: Option<&CFTimeZone>,
283    ) -> CFGregorianDate;
284}
285
286extern "C-unwind" {
287    /// # Safety
288    ///
289    /// `tz` might not allow `None`.
290    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
291    pub fn CFAbsoluteTimeAddGregorianUnits(
292        at: CFAbsoluteTime,
293        tz: Option<&CFTimeZone>,
294        units: CFGregorianUnits,
295    ) -> CFAbsoluteTime;
296}
297
298extern "C-unwind" {
299    /// # Safety
300    ///
301    /// `tz` might not allow `None`.
302    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
303    pub fn CFAbsoluteTimeGetDifferenceAsGregorianUnits(
304        at1: CFAbsoluteTime,
305        at2: CFAbsoluteTime,
306        tz: Option<&CFTimeZone>,
307        unit_flags: CFOptionFlags,
308    ) -> CFGregorianUnits;
309}
310
311extern "C-unwind" {
312    /// # Safety
313    ///
314    /// `tz` might not allow `None`.
315    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
316    pub fn CFAbsoluteTimeGetDayOfWeek(at: CFAbsoluteTime, tz: Option<&CFTimeZone>) -> i32;
317}
318
319extern "C-unwind" {
320    /// # Safety
321    ///
322    /// `tz` might not allow `None`.
323    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
324    pub fn CFAbsoluteTimeGetDayOfYear(at: CFAbsoluteTime, tz: Option<&CFTimeZone>) -> i32;
325}
326
327extern "C-unwind" {
328    /// # Safety
329    ///
330    /// `tz` might not allow `None`.
331    #[deprecated = "Use CFCalendar or NSCalendar API instead"]
332    pub fn CFAbsoluteTimeGetWeekOfYear(at: CFAbsoluteTime, tz: Option<&CFTimeZone>) -> i32;
333}
334
335#[deprecated = "renamed to `CFDate::new`"]
336#[inline]
337pub extern "C-unwind" fn CFDateCreate(
338    allocator: Option<&CFAllocator>,
339    at: CFAbsoluteTime,
340) -> Option<CFRetained<CFDate>> {
341    extern "C-unwind" {
342        fn CFDateCreate(
343            allocator: Option<&CFAllocator>,
344            at: CFAbsoluteTime,
345        ) -> Option<NonNull<CFDate>>;
346    }
347    let ret = unsafe { CFDateCreate(allocator, at) };
348    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
349}
350
351#[deprecated = "renamed to `CFDate::absolute_time`"]
352#[inline]
353pub extern "C-unwind" fn CFDateGetAbsoluteTime(the_date: &CFDate) -> CFAbsoluteTime {
354    extern "C-unwind" {
355        fn CFDateGetAbsoluteTime(the_date: &CFDate) -> CFAbsoluteTime;
356    }
357    unsafe { CFDateGetAbsoluteTime(the_date) }
358}
359
360#[deprecated = "renamed to `CFDate::time_interval_since_date`"]
361#[inline]
362pub extern "C-unwind" fn CFDateGetTimeIntervalSinceDate(
363    the_date: &CFDate,
364    other_date: Option<&CFDate>,
365) -> CFTimeInterval {
366    extern "C-unwind" {
367        fn CFDateGetTimeIntervalSinceDate(
368            the_date: &CFDate,
369            other_date: Option<&CFDate>,
370        ) -> CFTimeInterval;
371    }
372    unsafe { CFDateGetTimeIntervalSinceDate(the_date, other_date) }
373}
374
375extern "C-unwind" {
376    #[deprecated = "renamed to `CFDate::compare`"]
377    pub fn CFDateCompare(
378        the_date: &CFDate,
379        other_date: Option<&CFDate>,
380        context: *mut c_void,
381    ) -> CFComparisonResult;
382}
383
384#[deprecated = "renamed to `CFGregorianDate::is_valid`"]
385#[inline]
386pub extern "C-unwind" fn CFGregorianDateIsValid(
387    gdate: CFGregorianDate,
388    unit_flags: CFOptionFlags,
389) -> bool {
390    extern "C-unwind" {
391        fn CFGregorianDateIsValid(gdate: CFGregorianDate, unit_flags: CFOptionFlags) -> Boolean;
392    }
393    let ret = unsafe { CFGregorianDateIsValid(gdate, unit_flags) };
394    ret != 0
395}
396
397extern "C-unwind" {
398    #[deprecated = "renamed to `CFGregorianDate::absolute_time`"]
399    pub fn CFGregorianDateGetAbsoluteTime(
400        gdate: CFGregorianDate,
401        tz: Option<&CFTimeZone>,
402    ) -> CFAbsoluteTime;
403}