ObjFW
OFDate.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFMessagePackRepresentation.h"
18 #import "OFSerialization.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
22 @class OFString;
23 @class OFConstantString;
24 
30 #ifndef OF_DATE_M
31 OF_SUBCLASSING_RESTRICTED
32 #endif
35 {
36  of_time_interval_t _seconds;
37 }
38 
39 #ifdef OF_HAVE_CLASS_PROPERTIES
40 @property (class, readonly, nonatomic) OFDate *distantFuture;
41 @property (class, readonly, nonatomic) OFDate *distantPast;
42 #endif
43 
47 @property (readonly, nonatomic) unsigned long microsecond;
48 
52 @property (readonly, nonatomic) unsigned char second;
53 
57 @property (readonly, nonatomic) unsigned char minute;
58 
62 @property (readonly, nonatomic) unsigned char localMinute;
63 
67 @property (readonly, nonatomic) unsigned char hour;
68 
72 @property (readonly, nonatomic) unsigned char localHour;
73 
77 @property (readonly, nonatomic) unsigned char dayOfMonth;
78 
82 @property (readonly, nonatomic) unsigned char localDayOfMonth;
83 
87 @property (readonly, nonatomic) unsigned char monthOfYear;
88 
92 @property (readonly, nonatomic) unsigned char localMonthOfYear;
93 
97 @property (readonly, nonatomic) unsigned short year;
98 
102 @property (readonly, nonatomic) unsigned short localYear;
103 
107 @property (readonly, nonatomic) unsigned char dayOfWeek;
108 
112 @property (readonly, nonatomic) unsigned char localDayOfWeek;
113 
117 @property (readonly, nonatomic) unsigned short dayOfYear;
118 
122 @property (readonly, nonatomic) unsigned short localDayOfYear;
123 
127 @property (readonly, nonatomic) of_time_interval_t timeIntervalSince1970;
128 
132 @property (readonly, nonatomic) of_time_interval_t timeIntervalSinceNow;
133 
139 + (instancetype)date;
140 
148 + (instancetype)dateWithTimeIntervalSince1970: (of_time_interval_t)seconds;
149 
156 + (instancetype)dateWithTimeIntervalSinceNow: (of_time_interval_t)seconds;
157 
175 + (instancetype)dateWithDateString: (OFString *)string
176  format: (OFString *)format;
177 
192 + (instancetype)dateWithLocalDateString: (OFString *)string
193  format: (OFString *)format;
194 
202 + (instancetype)distantFuture;
203 
211 + (instancetype)distantPast;
212 
220 - (instancetype)initWithTimeIntervalSince1970: (of_time_interval_t)seconds
221  OF_DESIGNATED_INITIALIZER;
222 
230 - (instancetype)initWithTimeIntervalSinceNow: (of_time_interval_t)seconds;
231 
249 - (instancetype)initWithDateString: (OFString *)string
250  format: (OFString *)format;
251 
267 - (instancetype)initWithLocalDateString: (OFString *)string
268  format: (OFString *)format;
269 
278 - (OFString *)dateStringWithFormat: (OFConstantString *)format;
279 
288 - (OFString *)localDateStringWithFormat: (OFConstantString *)format;
289 
298 - (OFDate *)earlierDate: (nullable OFDate *)otherDate;
299 
308 - (OFDate *)laterDate: (nullable OFDate *)otherDate;
309 
316 - (of_time_interval_t)timeIntervalSinceDate: (OFDate *)otherDate;
317 
324 - (OFDate *)dateByAddingTimeInterval: (of_time_interval_t)seconds;
325 @end
326 
327 OF_ASSUME_NONNULL_END
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:138
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class for storing, accessing and comparing dates.
Definition: OFDate.h:36
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class for handling strings.
Definition: OFString.h:132
A protocol for comparing objects.
Definition: OFObject.h:1224
A protocol for the creation of copies.
Definition: OFObject.h:1187
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:29
A protocol for serializing objects.
Definition: OFSerialization.h:29