ObjFW
OFDate.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFMessagePackRepresentation.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
25 @class OFString;
26 @class OFConstantString;
27 
35 #ifdef OF_HAVE_CLASS_PROPERTIES
36 @property (class, readonly, nonatomic) OFDate *distantFuture;
37 @property (class, readonly, nonatomic) OFDate *distantPast;
38 #endif
39 
43 @property (readonly, nonatomic) unsigned long microsecond;
44 
48 @property (readonly, nonatomic) unsigned char second;
49 
53 @property (readonly, nonatomic) unsigned char minute;
54 
58 @property (readonly, nonatomic) unsigned char localMinute;
59 
63 @property (readonly, nonatomic) unsigned char hour;
64 
68 @property (readonly, nonatomic) unsigned char localHour;
69 
73 @property (readonly, nonatomic) unsigned char dayOfMonth;
74 
78 @property (readonly, nonatomic) unsigned char localDayOfMonth;
79 
83 @property (readonly, nonatomic) unsigned char monthOfYear;
84 
88 @property (readonly, nonatomic) unsigned char localMonthOfYear;
89 
93 @property (readonly, nonatomic) unsigned short year;
94 
98 @property (readonly, nonatomic) unsigned short localYear;
99 
103 @property (readonly, nonatomic) unsigned char dayOfWeek;
104 
108 @property (readonly, nonatomic) unsigned char localDayOfWeek;
109 
113 @property (readonly, nonatomic) unsigned short dayOfYear;
114 
118 @property (readonly, nonatomic) unsigned short localDayOfYear;
119 
123 @property (readonly, nonatomic) OFTimeInterval timeIntervalSince1970;
124 
128 @property (readonly, nonatomic) OFTimeInterval timeIntervalSinceNow;
129 
135 + (instancetype)date;
136 
144 + (instancetype)dateWithTimeIntervalSince1970: (OFTimeInterval)seconds;
145 
152 + (instancetype)dateWithTimeIntervalSinceNow: (OFTimeInterval)seconds;
153 
172 + (instancetype)dateWithDateString: (OFString *)string
173  format: (OFString *)format;
174 
190 + (instancetype)dateWithLocalDateString: (OFString *)string
191  format: (OFString *)format;
192 
200 + (instancetype)distantFuture;
201 
209 + (instancetype)distantPast;
210 
218 - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds
219  OF_DESIGNATED_INITIALIZER;
220 
228 - (instancetype)initWithTimeIntervalSinceNow: (OFTimeInterval)seconds;
229 
248 - (instancetype)initWithDateString: (OFString *)string
249  format: (OFString *)format;
250 
267 - (instancetype)initWithLocalDateString: (OFString *)string
268  format: (OFString *)format;
269 
276 - (OFComparisonResult)compare: (OFDate *)date;
277 
291 - (OFString *)dateStringWithFormat: (OFConstantString *)format;
292 
306 - (OFString *)localDateStringWithFormat: (OFConstantString *)format;
307 
316 - (OFDate *)earlierDate: (nullable OFDate *)otherDate;
317 
326 - (OFDate *)laterDate: (nullable OFDate *)otherDate;
327 
334 - (OFTimeInterval)timeIntervalSinceDate: (OFDate *)otherDate;
335 
342 - (OFDate *)dateByAddingTimeInterval: (OFTimeInterval)seconds;
343 @end
344 
345 OF_ASSUME_NONNULL_END
unsigned short year
The year of the date.
Definition: OFDate.h:93
unsigned char localDayOfWeek
The day of the week of the date in local time.
Definition: OFDate.h:108
A protocol for comparing objects.
Definition: OFObject.h:1388
A class for storing, accessing and comparing dates.
Definition: OFDate.h:33
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:41
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
unsigned char minute
The minute of the date.
Definition: OFDate.h:53
unsigned char dayOfWeek
The day of the week of the date.
Definition: OFDate.h:103
unsigned char localMinute
The minute of the date in local time.
Definition: OFDate.h:58
unsigned short localYear
The year of the date in local time.
Definition: OFDate.h:98
unsigned char hour
The hour of the date.
Definition: OFDate.h:63
unsigned char localHour
The hour of the date in local time.
Definition: OFDate.h:68
unsigned char monthOfYear
The month of the year of the date.
Definition: OFDate.h:83
unsigned char localMonthOfYear
The month of the year of the date in local time.
Definition: OFDate.h:88
A class for handling strings.
Definition: OFString.h:142
OFComparisonResult
A result of a comparison.
Definition: OFObject.h:58
instancetype distantFuture()
Returns a date in the distant future.
Definition: OFDate.m:369
unsigned short localDayOfYear
The day of the year of the date in local time.
Definition: OFDate.h:118
double OFTimeInterval
A time interval in seconds.
Definition: OFObject.h:154
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:33
unsigned short dayOfYear
The day of the year of the date.
Definition: OFDate.h:113
instancetype distantPast()
Returns a date in the distant past.
Definition: OFDate.m:376
unsigned long microsecond
The microsecond of the date.
Definition: OFDate.h:43
unsigned char second
The second of the date.
Definition: OFDate.h:48
instancetype date()
Creates a new OFDate with the current date and time.
Definition: OFDate.m:338
A protocol for the creation of copies.
Definition: OFObject.h:1350
OFTimeInterval timeIntervalSinceNow
The seconds the date is in the future.
Definition: OFDate.h:128
unsigned char localDayOfMonth
The day of the month of the date in local time.
Definition: OFDate.h:78
unsigned char dayOfMonth
The day of the month of the date.
Definition: OFDate.h:73
OFTimeInterval timeIntervalSince1970
The seconds since 1970-01-01T00:00:00Z.
Definition: OFDate.h:123