core_foundation_sys/
calendar.rs

1// Copyright 2023 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use std::os::raw::{c_char, c_void};
11
12use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFRange, CFTypeID};
13use crate::date::{CFAbsoluteTime, CFTimeInterval};
14use crate::locale::{CFCalendarIdentifier, CFLocaleRef};
15use crate::timezone::CFTimeZoneRef;
16
17#[repr(C)]
18pub struct __CFCalendar(c_void);
19pub type CFCalendarRef = *mut __CFCalendar;
20
21pub type CFCalendarUnit = CFOptionFlags;
22pub const kCFCalendarUnitEra: CFCalendarUnit = 1 << 1;
23pub const kCFCalendarUnitYear: CFCalendarUnit = 1 << 2;
24pub const kCFCalendarUnitMonth: CFCalendarUnit = 1 << 3;
25pub const kCFCalendarUnitDay: CFCalendarUnit = 1 << 4;
26pub const kCFCalendarUnitHour: CFCalendarUnit = 1 << 5;
27pub const kCFCalendarUnitMinute: CFCalendarUnit = 1 << 6;
28pub const kCFCalendarUnitSecond: CFCalendarUnit = 1 << 7;
29pub const kCFCalendarUnitWeek: CFCalendarUnit = 1 << 8; // deprecated since macos 10.10
30pub const kCFCalendarUnitWeekday: CFCalendarUnit = 1 << 9;
31pub const kCFCalendarUnitWeekdayOrdinal: CFCalendarUnit = 1 << 10;
32pub const kCFCalendarUnitQuarter: CFCalendarUnit = 1 << 11;
33pub const kCFCalendarUnitWeekOfMonth: CFCalendarUnit = 1 << 12;
34pub const kCFCalendarUnitWeekOfYear: CFCalendarUnit = 1 << 13;
35pub const kCFCalendarUnitYearForWeekOfYear: CFCalendarUnit = 1 << 14;
36
37pub const kCFCalendarComponentsWrap: CFOptionFlags = 1 << 0;
38
39extern "C" {
40    /*
41     * CFCalendar.h
42     */
43
44    /* Creating a Calendar */
45    pub fn CFCalendarCopyCurrent() -> CFCalendarRef;
46    pub fn CFCalendarCreateWithIdentifier(
47        allocator: CFAllocatorRef,
48        identifier: CFCalendarIdentifier,
49    ) -> CFCalendarRef;
50
51    /* Calendrical Calculations */
52    pub fn CFCalendarAddComponents(
53        identifier: CFCalendarIdentifier,
54        /* inout */ at: *mut CFAbsoluteTime,
55        options: CFOptionFlags,
56        componentDesc: *const char,
57        ...
58    ) -> Boolean;
59    pub fn CFCalendarComposeAbsoluteTime(
60        identifier: CFCalendarIdentifier,
61        /* out */ at: *mut CFAbsoluteTime,
62        componentDesc: *const c_char,
63        ...
64    ) -> Boolean;
65    pub fn CFCalendarDecomposeAbsoluteTime(
66        identifier: CFCalendarIdentifier,
67        at: CFAbsoluteTime,
68        componentDesc: *const c_char,
69        ...
70    ) -> Boolean;
71    pub fn CFCalendarGetComponentDifference(
72        identifier: CFCalendarIdentifier,
73        startingAT: CFAbsoluteTime,
74        resultAT: CFAbsoluteTime,
75        options: CFOptionFlags,
76        componentDesc: *const c_char,
77        ...
78    ) -> Boolean;
79
80    /* Getting Ranges of Units */
81    pub fn CFCalendarGetRangeOfUnit(
82        identifier: CFCalendarIdentifier,
83        smallerUnit: CFCalendarUnit,
84        biggerUnit: CFCalendarUnit,
85        at: CFAbsoluteTime,
86    ) -> CFRange;
87    pub fn CFCalendarGetOrdinalityOfUnit(
88        identifier: CFCalendarIdentifier,
89        smallerUnit: CFCalendarUnit,
90        biggerUnit: CFCalendarUnit,
91        at: CFAbsoluteTime,
92    ) -> CFIndex;
93    pub fn CFCalendarGetTimeRangeOfUnit(
94        identifier: CFCalendarIdentifier,
95        unit: CFCalendarUnit,
96        at: CFAbsoluteTime,
97        startp: *mut CFAbsoluteTime,
98        tip: *mut CFTimeInterval,
99    ) -> Boolean;
100    pub fn CFCalendarGetMaximumRangeOfUnit(
101        identifier: CFCalendarIdentifier,
102        unit: CFCalendarUnit,
103    ) -> CFRange;
104    pub fn CFCalendarGetMinimumRangeOfUnit(
105        identifier: CFCalendarIdentifier,
106        unit: CFCalendarUnit,
107    ) -> CFRange;
108
109    /* Getting and Setting the Time Zone */
110    pub fn CFCalendarCopyTimeZone(identifier: CFCalendarIdentifier) -> CFTimeZoneRef;
111    pub fn CFCalendarSetTimeZone(identifier: CFCalendarIdentifier, tz: CFTimeZoneRef);
112
113    /* Getting the Identifier */
114    pub fn CFCalendarGetIdentifier(identifier: CFCalendarIdentifier) -> CFCalendarIdentifier;
115
116    /* Getting and Setting the Locale */
117    pub fn CFCalendarCopyLocale(identifier: CFCalendarIdentifier) -> CFLocaleRef;
118    pub fn CFCalendarSetLocale(identifier: CFCalendarIdentifier, locale: CFLocaleRef);
119
120    /* Getting and Setting Day Information */
121    pub fn CFCalendarGetFirstWeekday(identifier: CFCalendarIdentifier) -> CFIndex;
122    pub fn CFCalendarSetFirstWeekday(identifier: CFCalendarIdentifier, wkdy: CFIndex);
123    pub fn CFCalendarGetMinimumDaysInFirstWeek(identifier: CFCalendarIdentifier) -> CFIndex;
124    pub fn CFCalendarSetMinimumDaysInFirstWeek(identifier: CFCalendarIdentifier, mwd: CFIndex);
125
126    /* Getting the Type ID */
127    pub fn CFCalendarGetTypeID() -> CFTypeID;
128}