1 /* NSCalendar.h
2 
3    Copyright (C) 2010 Free Software Foundation, Inc.
4 
5    Written by: Stefan Bidigaray
6    Date: December, 2010
7 
8    This library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 2 of the License, or (at your option) any later version.
12 
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17 
18    You should have received a copy of the GNU Lesser General Public
19    License along with this library; see the file COPYING.LIB.
20    If not, see <http://www.gnu.org/licenses/> or write to the
21    Free Software Foundation, 51 Franklin Street, Fifth Floor,
22    Boston, MA 02110-1301, USA.
23 */
24 
25 #ifndef __NSCalendar_h_GNUSTEP_BASE_INCLUDE
26 #define __NSCalendar_h_GNUSTEP_BASE_INCLUDE
27 
28 #import <GNUstepBase/GSVersionMacros.h>
29 
30 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
31 
32 #include <Foundation/NSObject.h>
33 #include <Foundation/NSGeometry.h>
34 
35 @class NSDate;
36 @class NSCalendar;
37 @class NSLocale;
38 @class NSString;
39 @class NSTimeZone;
40 
41 #if	defined(__cplusplus)
42 extern "C" {
43 #endif
44 
45 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
46 GS_EXPORT NSString *const NSCalendarIdentifierGregorian;
47 GS_EXPORT NSString *const NSCalendarIdentifierBuddhist;
48 GS_EXPORT NSString *const NSCalendarIdentifierChinese;
49 GS_EXPORT NSString *const NSCalendarIdentifierCoptic;
50 GS_EXPORT NSString *const NSCalendarIdentifierEthiopicAmeteMihret;
51 GS_EXPORT NSString *const NSCalendarIdentifierEthiopicAmeteAlem;
52 GS_EXPORT NSString *const NSCalendarIdentifierHebrew;
53 GS_EXPORT NSString *const NSCalendarIdentifierISO8601;
54 GS_EXPORT NSString *const NSCalendarIdentifierIndian;
55 GS_EXPORT NSString *const NSCalendarIdentifierIslamic;
56 GS_EXPORT NSString *const NSCalendarIdentifierIslamicCivil;
57 GS_EXPORT NSString *const NSCalendarIdentifierJapanese;
58 GS_EXPORT NSString *const NSCalendarIdentifierPersian;
59 GS_EXPORT NSString *const NSCalendarIdentifierRepublicOfChina;
60 #endif
61 #if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
62 GS_EXPORT NSString *const NSCalendarIdentifierIslamicTabular;
63 GS_EXPORT NSString *const NSCalendarIdentifierIslamicUmmAlQura;
64 #endif
65 
66 // NSCalendarOptions enum
67 // These values are currently NOT supported in this NSCalendar implementation.
68 #if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
69 typedef NSUInteger NSCalendarOptions;
70 enum
71 {
72   NSCalendarWrapComponents = (1UL << 0),
73 
74   NSCalendarMatchStrictly = (1ULL << 1),
75   NSCalendarSearchBackwards = (1ULL << 2),
76 
77   NSCalendarMatchPreviousTimePreservingSmallerUnits = (1ULL << 8),
78   NSCalendarMatchNextTimePreservingSmallerUnits = (1ULL << 9),
79   NSCalendarMatchNextTime = (1ULL << 10),
80 
81   NSCalendarMatchFirst = (1ULL << 12),
82   NSCalendarMatchLast = (1ULL << 13)
83 };
84 #endif
85 
86 typedef NSUInteger NSCalendarUnit;
87 
88 /* Old-style NSCalendarUnit declarations, deprecated */
89 enum
90 {
91   NSEraCalendarUnit = (1UL << 1),
92   NSYearCalendarUnit = (1UL << 2),
93   NSMonthCalendarUnit = (1UL << 3),
94   NSDayCalendarUnit = (1UL << 4),
95   NSHourCalendarUnit = (1UL << 5),
96   NSMinuteCalendarUnit = (1UL << 6),
97   NSSecondCalendarUnit = (1UL << 7),
98   NSWeekCalendarUnit = (1UL << 8),
99   NSWeekdayCalendarUnit = (1UL << 9),
100   NSWeekdayOrdinalCalendarUnit = (1UL << 10),
101 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
102   NSQuarterCalendarUnit = (1UL << 11),
103 #endif
104 #if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
105   NSWeekOfMonthCalendarUnit = (1UL << 12),
106   NSWeekOfYearCalendarUnit = (1UL << 13),
107   NSYearForWeekOfYearCalendarUnit = (1UL << 14),
108 #endif
109 };
110 
111 /* New-style NSCalendarUnit declarations */
112 enum
113 {
114 #if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
115   NSCalendarUnitEra = (1UL << 1),
116   NSCalendarUnitYear = (1UL << 2),
117   NSCalendarUnitMonth = (1UL << 3),
118   NSCalendarUnitDay = (1UL << 4),
119   NSCalendarUnitHour = (1UL << 5),
120   NSCalendarUnitMinute = (1UL << 6),
121   NSCalendarUnitSecond = (1UL << 7),
122   NSCalendarUnitWeekday = (1UL << 9),
123   NSCalendarUnitWeekdayOrdinal = (1UL << 10),
124 #endif
125 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
126   NSCalendarUnitQuarter = (1UL << 11),
127 #endif
128 #if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
129   NSCalendarUnitWeekOfMonth = (1UL << 12),
130   NSCalendarUnitWeekOfYear = (1UL << 13),
131   NSCalendarUnitYearForWeekOfYear = (1UL << 14),
132   NSCalendarUnitNanosecond = (1 << 15), // FIXME: unimplemented
133   NSCalendarUnitCalendar = (1 << 20), // FIXME: unimplemented
134   NSCalendarUnitTimeZone = (1 << 21) // FIXME: unimplemented
135 #endif
136 };
137 
138 enum
139 {
140   NSWrapCalendarComponents = (1UL << 0)
141 };
142 
143 enum
144 {
145   NSDateComponentUndefined = NSIntegerMax,
146   NSUndefinedDateComponent = NSDateComponentUndefined
147 };
148 
149 
150 
151 @interface NSDateComponents : NSObject <NSCopying>
152 {
153 @private
154   void  *_NSDateComponentsInternal;
155 /* FIXME ... remove dummy fields at next binary incompatible release
156  */
157   void  *_dummy1;
158   void  *_dummy2;
159   void  *_dummy3;
160   void  *_dummy4;
161   void  *_dummy5;
162   void  *_dummy6;
163   void  *_dummy7;
164   void  *_dummy8;
165   void  *_dummy9;
166   void  *_dummy10;
167   void  *_dummy11;
168   void  *_dummy12;
169 }
170 
171 - (NSInteger) day;
172 - (NSInteger) era;
173 - (NSInteger) hour;
174 - (NSInteger) minute;
175 - (NSInteger) month;
176 - (NSInteger) second;
177 - (NSInteger) week;
178 - (NSInteger) weekday;
179 - (NSInteger) weekdayOrdinal;
180 - (NSInteger) year;
181 
182 - (void) setDay: (NSInteger) v;
183 - (void) setEra: (NSInteger) v;
184 - (void) setHour: (NSInteger) v;
185 - (void) setMinute: (NSInteger) v;
186 - (void) setMonth: (NSInteger) v;
187 - (void) setSecond: (NSInteger) v;
188 - (void) setWeek: (NSInteger) v;
189 - (void) setWeekday: (NSInteger) v;
190 - (void) setWeekdayOrdinal: (NSInteger) v;
191 - (void) setYear: (NSInteger) v;
192 
193 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
194 - (NSInteger) quarter;
195 - (void) setQuarter: (NSInteger) v;
196 #endif
197 
198 #if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
199 - (NSCalendar *) calendar;
200 - (NSTimeZone *) timeZone;
201 - (void) setCalendar: (NSCalendar *) cal;
202 - (void) setTimeZone: (NSTimeZone *) tz;
203 
204 /**
205  * <p>
206  * Computes a date by using the components set in this NSDateComponents
207  * instance.
208  * </p>
209  * <p>
210  * A calendar (and optionally a time zone) must be set prior to
211  * calling this method.
212  * </p>
213  */
214 - (NSDate *) date;
215 
216 /** Returns the number of the week in this month. */
217 - (NSInteger) weekOfMonth;
218 /**
219  * Returns the number of the week in this year.
220  * Identical to calling <code>week</code>. */
221 - (NSInteger) weekOfYear;
222 /**
223  * The year corresponding to the current week.
224  * This value may differ from year around the end of the year.
225  *
226  * For example, for 2012-12-31, the year number is 2012, but
227  * yearForWeekOfYear is 2013, since it's already week 1 in 2013.
228  */
229 - (NSInteger) yearForWeekOfYear;
230 
231 /** Sets the number of the week in this month. */
232 - (void) setWeekOfMonth: (NSInteger) v;
233 
234 /**
235  * Sets the number of the week in this year.
236  * Identical to calling <code>-setWeek</code>. */
237 - (void) setWeekOfYear: (NSInteger) v;
238 
239 /**
240  * Sets the year number for the current week.
241  * See the explanation at <code>-yearForWeekOfYear</code>.
242  */
243 - (void) setYearForWeekOfYear: (NSInteger) v;
244 
245 #endif
246 @end
247 
248 
249 
250 @interface NSCalendar : NSObject <NSCoding, NSCopying>
251 {
252 @private
253   void  *_NSCalendarInternal;
254 /* FIXME ... remove dummy fields at next binary incompatible release
255  */
256   void  *_dummy1;
257   void  *_dummy2;
258   void  *_dummy3;
259 }
260 
261 + (id) currentCalendar;
262 + (id) calendarWithIdentifier: (NSString *) string;
263 
264 - (id) initWithCalendarIdentifier: (NSString *) string;
265 - (NSString *) calendarIdentifier;
266 
267 - (NSDateComponents *) components: (NSUInteger) unitFlags
268                          fromDate: (NSDate *) date;
269 /**
270  * Compute the different between the specified components in the two dates.
271  * Values are summed up as long as now higher-granularity unit is specified.
272  * That means if you want to extract the year and the day from two dates
273  * which are 13 months + 1 day apart, you will get 1 as the result for the year
274  * but the rest of the difference in days. (29 <= x <= 32, depending on the
275  * month).
276  *
277  * Please note that the NSWrapCalendarComponents option that should affect the
278  * calculations is not presently supported.
279  */
280 - (NSDateComponents *) components: (NSUInteger) unitFlags
281                          fromDate: (NSDate *) startingDate
282                            toDate: (NSDate *) resultDate
283                           options: (NSUInteger) opts;
284 - (NSDate *) dateByAddingComponents: (NSDateComponents *) comps
285                              toDate: (NSDate *) date
286                             options: (NSUInteger) opts;
287 - (NSDate *) dateFromComponents: (NSDateComponents *) comps;
288 
289 - (NSLocale *) locale;
290 - (void)setLocale: (NSLocale *) locale;
291 - (NSUInteger) firstWeekday;
292 - (void) setFirstWeekday: (NSUInteger) weekday;
293 - (NSUInteger) minimumDaysInFirstWeek;
294 - (void) setMinimumDaysInFirstWeek: (NSUInteger) mdw;
295 - (NSTimeZone *) timeZone;
296 - (void) setTimeZone: (NSTimeZone *) tz;
297 
298 - (NSRange) maximumRangeOfUnit: (NSCalendarUnit) unit;
299 - (NSRange) minimumRangeofUnit: (NSCalendarUnit) unit;
300 - (NSUInteger) ordinalityOfUnit: (NSCalendarUnit) smaller
301                          inUnit: (NSCalendarUnit) larger
302                         forDate: (NSDate *) date;
303 - (NSRange) rangeOfUnit: (NSCalendarUnit) smaller
304                  inUnit: (NSCalendarUnit) larger
305                 forDate: (NSDate *) date;
306 
307 #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
308 + (id) autoupdatingCurrentCalendar;
309 
310 - (BOOL) rangeOfUnit: (NSCalendarUnit) unit
311            startDate: (NSDate **) datep
312             interval: (NSTimeInterval *)tip
313              forDate: (NSDate *)date;
314 #endif
315 @end
316 
317 #if	defined(__cplusplus)
318 }
319 #endif
320 
321 #endif /* OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) */
322 
323 #endif /* __NSCalendar_h_GNUSTEP_BASE_INCLUDE */
324