ObjFW  Check-in [c57f9fe4fb]

Overview
Comment:Add +[distantFuture] and +[distantPast] to OFDate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c57f9fe4fb8b9987413ead167b1e30d2a66563fbccc18cb67d9182f9e885df6a
User & Date: js on 2011-01-01 14:58:50
Other Links: manifest | tags
Context
2011-01-01
16:12
Multiple OFDate changes. check-in: c084907c2c user: js tags: trunk
14:58
Add +[distantFuture] and +[distantPast] to OFDate. check-in: c57f9fe4fb user: js tags: trunk
14:20
Don't include microseconds in -[OFDate description].
This way, it conforms to ISO 8601.
check-in: 65111e7409 user: js tags: trunk
Changes

Modified configure.ac from [39fb6de447] to [ce9d5beae9].

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
		#ifdef SIZE_T_MAX
		yes
		#endif
	], [
		AC_MSG_RESULT(yes)
		size_max="SIZE_T_MAX"], [
		AC_MSG_RESULT(no)
		size_max="((size_t)-1)"
	])
	AC_DEFINE_UNQUOTED(SIZE_MAX, $size_max, [Maximum value for size_t])
])

AC_CHECK_FUNC(asprintf, [
	have_asprintf="yes"
	AC_DEFINE(OF_HAVE_ASPRINTF, 1, [Whether we have asprintf])







|







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
		#ifdef SIZE_T_MAX
		yes
		#endif
	], [
		AC_MSG_RESULT(yes)
		size_max="SIZE_T_MAX"], [
		AC_MSG_RESULT(no)
		size_max="(~(size_t)0)"
	])
	AC_DEFINE_UNQUOTED(SIZE_MAX, $size_max, [Maximum value for size_t])
])

AC_CHECK_FUNC(asprintf, [
	have_asprintf="yes"
	AC_DEFINE(OF_HAVE_ASPRINTF, 1, [Whether we have asprintf])

Modified src/OFDate.h from [8a0f20777b] to [3a80b7e602].

47
48
49
50
51
52
53










54
55
56
57
58
59
60
 * \param sec The seconds since 1970-01-01 00:00:00
 * \param usec The microsecond part of the time
 * \return A new, autoreleased OFDate with the specified date and time
 */
+ dateWithTimeIntervalSince1970: (time_t)sec
		   microseconds: (suseconds_t)usec;











/**
 * Initializes an already allocated OFDate with the specified date and time.
 *
 * \param sec The seconds since 1970-01-01 00:00:00
 * \return An initialized OFDate with the specified date and time
 */
- initWithTimeIntervalSince1970: (time_t)sec;







>
>
>
>
>
>
>
>
>
>







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 * \param sec The seconds since 1970-01-01 00:00:00
 * \param usec The microsecond part of the time
 * \return A new, autoreleased OFDate with the specified date and time
 */
+ dateWithTimeIntervalSince1970: (time_t)sec
		   microseconds: (suseconds_t)usec;

/**
 * \return A date in the distant future
 */
+ distantFuture;

/**
 * \return A date in the distant past
 */
+ distantPast;

/**
 * Initializes an already allocated OFDate with the specified date and time.
 *
 * \param sec The seconds since 1970-01-01 00:00:00
 * \return An initialized OFDate with the specified date and time
 */
- initWithTimeIntervalSince1970: (time_t)sec;

Modified src/OFDate.m from [4afab9eb58] to [ba324e05e2].

1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"



#include <time.h>

#include <sys/time.h>

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













>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdint.h>
#include <limits.h>
#include <time.h>

#include <sys/time.h>

#import "OFDate.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
110
111
112
113
114
115
116




















117
118
119
120
121
122
123

+ dateWithTimeIntervalSince1970: (time_t)sec
		   microseconds: (suseconds_t)usec
{
	return [[[self alloc] initWithTimeIntervalSince1970: sec
					       microseconds: usec] autorelease];
}





















- init
{
	struct timeval t;

	if (gettimeofday(&t, NULL)) {
		Class c = isa;







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







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

+ dateWithTimeIntervalSince1970: (time_t)sec
		   microseconds: (suseconds_t)usec
{
	return [[[self alloc] initWithTimeIntervalSince1970: sec
					       microseconds: usec] autorelease];
}

+ distantFuture
{
	if (sizeof(time_t) == sizeof(int64_t))
		return [[[self alloc]
		    initWithTimeIntervalSince1970: INT64_MAX] autorelease];
	if (sizeof(time_t) == sizeof(int32_t))
		return [[[self alloc]
		    initWithTimeIntervalSince1970: INT32_MAX] autorelease];

	/* Neither 64 nor 32 bit. But it's guaranteed to be at least an int */
	return [[[self alloc]
	    initWithTimeIntervalSince1970: INT_MAX] autorelease];
}

+ distantPast
{
	/* We don't know if time_t is signed or unsigned. Use 0 to be safe */
	return [[[self alloc] initWithTimeIntervalSince1970: 0] autorelease];
}

- init
{
	struct timeval t;

	if (gettimeofday(&t, NULL)) {
		Class c = isa;