ObjFW  Diff

Differences From Artifact [52c00039c4]:

To Artifact [0a3ac06fbe]:


13
14
15
16
17
18
19

20
21
22
23
24
25
26

#include <time.h>

#include <sys/time.h>

#import "OFDate.h"
#import "OFString.h"

#import "OFExceptions.h"

#if !defined(HAVE_GMTIME_R) && defined(OF_THREADS)
# import "OFThread.h"

static OFMutex *mutex;
#endif







>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include <time.h>

#include <sys/time.h>

#import "OFDate.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"

#if !defined(HAVE_GMTIME_R) && defined(OF_THREADS)
# import "OFThread.h"

static OFMutex *mutex;
#endif
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
		return OF_ORDERED_DESCENDING;

	return OF_ORDERED_SAME;
}

- (OFString*)description
{
	char str[20];	/* YYYY-MM-DD hh:mm:ss */


#ifdef HAVE_GMTIME_R
	struct tm tm;

	if (gmtime_r(&sec, &tm) == NULL)
		@throw [OFOutOfRangeException newWithClass: isa];

	strftime(str, 20, "%Y-%m-%dT%H:%M:%S", &tm);
#else
	struct tm *tm;

# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		if ((tm = gmtime(&sec)) == NULL)
			@throw [OFOutOfRangeException newWithClass: isa];

		strftime(str, 20, "%Y-%m-%dT%H:%M:%S", tm);
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
# endif
#endif

	if (usec == 0)
		return [OFString stringWithFormat: @"%sZ", str];

	return [OFString stringWithFormat: @"%s.%06dZ", str, usec];
}

- (int)seconds
{
	GMTIME_RET(tm_sec)
}








|
>

<
|

|
<
|
<
|
<
|
<
<
|
<
<
<
<

<
<
|
<
<
<
<
|
<
<

|







149
150
151
152
153
154
155
156
157
158

159
160
161

162

163

164


165




166


167




168


169
170
171
172
173
174
175
176
177
		return OF_ORDERED_DESCENDING;

	return OF_ORDERED_SAME;
}

- (OFString*)description
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *tmp, *ret;


	tmp = [self stringWithFormat: @"%Y-%m-%dT%H:%M:%S"];

	if (usec == 0)

		ret = [OFString stringWithFormat: @"%sZ", [tmp cString]];

	else

		ret = [OFString stringWithFormat: @"%s.%06dZ", [tmp cString],


						  usec];







	[ret retain];




	[pool release];



	return [ret autorelease];
}

- (int)seconds
{
	GMTIME_RET(tm_sec)
}

226
227
228
229
230
231
232







































233
	GMTIME_RET(tm_wday)
}

- (int)dayOfYear
{
	GMTIME_RET(tm_yday + 1)
}







































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	GMTIME_RET(tm_wday)
}

- (int)dayOfYear
{
	GMTIME_RET(tm_yday + 1)
}

- (OFString*)stringWithFormat: (OFString*)fmt
{
	struct tm tm;
	char *buf;

#ifdef HAVE_GMTIME_R
	if (gmtime_r(&sec, &tm) == NULL)
		@throw [OFOutOfRangeException newWithClass: isa];
#else
# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		struct tm *tmp;

		if ((tmp = gmtime(&sec)) == NULL)
			@throw [OFOutOfRangeException newWithClass: isa];

		tm = *tmp;
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
# endif
#endif

	buf = [self allocMemoryWithSize: of_pagesize];

	@try {
		if (!strftime(buf, of_pagesize, [fmt cString], &tm))
			@throw [OFOutOfRangeException newWithClass: isa];

		return [OFString stringWithCString: buf];
	} @finally {
		[self freeMemory: buf];
	}
}
@end