ObjFW
OFDate.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFSerialization.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
22 @class OFString;
23 @class OFConstantString;
24 
31 {
32  of_time_interval_t _seconds;
33 }
34 
40 + (instancetype)date;
41 
49 + (instancetype)dateWithTimeIntervalSince1970: (of_time_interval_t)seconds;
50 
57 + (instancetype)dateWithTimeIntervalSinceNow: (of_time_interval_t)seconds;
58 
76 + (instancetype)dateWithDateString: (OFString *)string
77  format: (OFString *)format;
78 
93 + (instancetype)dateWithLocalDateString: (OFString *)string
94  format: (OFString *)format;
95 
103 + (instancetype)distantFuture;
104 
112 + (instancetype)distantPast;
113 
121 - initWithTimeIntervalSince1970: (of_time_interval_t)seconds;
122 
130 - initWithTimeIntervalSinceNow: (of_time_interval_t)seconds;
131 
149 - initWithDateString: (OFString *)string
150  format: (OFString *)format;
151 
167 - initWithLocalDateString: (OFString *)string
168  format: (OFString *)format;
169 
175 - (uint32_t)microsecond;
176 
182 - (uint8_t)second;
183 
189 - (uint8_t)minute;
190 
196 - (uint8_t)localMinute;
197 
203 - (uint8_t)hour;
204 
210 - (uint8_t)localHour;
211 
217 - (uint8_t)dayOfMonth;
218 
224 - (uint8_t)localDayOfMonth;
225 
231 - (uint8_t)monthOfYear;
232 
238 - (uint8_t)localMonthOfYear;
239 
245 - (uint16_t)year;
246 
252 - (uint16_t)localYear;
253 
259 - (uint8_t)dayOfWeek;
260 
266 - (uint8_t)localDayOfWeek;
267 
273 - (uint16_t)dayOfYear;
274 
280 - (uint16_t)localDayOfYear;
281 
290 - (OFString *)dateStringWithFormat: (OFConstantString *)format;
291 
300 - (OFString *)localDateStringWithFormat: (OFConstantString *)format;
301 
310 - (OFDate *)earlierDate: (nullable OFDate *)otherDate;
311 
320 - (OFDate *)laterDate: (nullable OFDate *)otherDate;
321 
328 
335 - (of_time_interval_t)timeIntervalSinceDate: (OFDate *)otherDate;
336 
343 
350 - (OFDate *)dateByAddingTimeInterval: (of_time_interval_t)seconds;
351 @end
352 
353 OF_ASSUME_NONNULL_END
uint8_t hour()
Returns the hour of the date.
Definition: OFDate.m:462
uint8_t dayOfMonth()
Returns the day of the month.
Definition: OFDate.m:472
uint16_t year()
Returns the year of the date.
Definition: OFDate.m:492
A class for handling strings.
Definition: OFString.h:114
uint16_t dayOfYear()
Returns the day of the year of the date.
Definition: OFDate.m:512
uint8_t localDayOfMonth()
Returns the day of the month of the date in local time.
Definition: OFDate.m:477
of_time_interval_t timeIntervalSinceNow()
Returns the seconds the receiver is in the future.
Definition: OFDate.m:674
of_time_interval_t timeIntervalSince1970()
Returns the seconds since 1970-01-01T00:00:00Z.
Definition: OFDate.m:664
uint16_t localDayOfYear()
Returns the day of the year of the date in local time.
Definition: OFDate.m:517
instancetype date()
Creates a new OFDate with the current date and time.
Definition: OFDate.m:191
A protocol for the creation of copies.
Definition: OFObject.h:914
instancetype distantPast()
Returns a date in the distant past.
Definition: OFDate.m:228
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:91
A protocol for comparing objects.
uint8_t dayOfWeek()
Returns the day of the week of the date.
Definition: OFDate.m:502
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:37
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
A protocol for serializing objects.
Definition: OFSerialization.h:30
instancetype distantFuture()
Returns a date in the distant future.
Definition: OFDate.m:222
uint8_t localMonthOfYear()
Returns the month of the year of the date in local time.
Definition: OFDate.m:487
uint8_t localHour()
Returns the hour of the date in local time.
Definition: OFDate.m:467
uint8_t minute()
Returns the minute of the date.
Definition: OFDate.m:452
uint8_t localDayOfWeek()
Returns the day of the week of the date in local time.
Definition: OFDate.m:507
uint32_t microsecond()
Returns the microsecond of the date.
Definition: OFDate.m:442
uint8_t localMinute()
Returns the minute of the date in local time.
Definition: OFDate.m:457
uint16_t localYear()
Returns the year of the date in local time.
Definition: OFDate.m:497
uint8_t second()
Returns the second of the date.
Definition: OFDate.m:447
uint8_t monthOfYear()
Returns the month of the year of the date.
Definition: OFDate.m:482