32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# import "OFThread.h"
static OFMutex *mutex;
#endif
#ifdef HAVE_GMTIME_R
# define GMTIME_RET(field) \
time_t sec_ = sec; \
struct tm tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if (gmtime_r(&sec_, &tm) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm.field;
# define LOCALTIME_RET(field) \
time_t sec_ = sec; \
struct tm tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if (localtime_r(&sec_, &tm) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm.field;
#else
# ifdef OF_THREADS
# define GMTIME_RET(field) \
time_t sec_ = sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
[mutex lock]; \
\
@try { \
if ((tm = gmtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm->field; \
} @finally { \
[mutex unlock]; \
}
# define LOCALTIME_RET(field) \
time_t sec_ = sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
[mutex lock]; \
\
@try { \
if ((tm = localtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm->field; \
} @finally { \
[mutex unlock]; \
}
# else
# define GMTIME_RET(field) \
time_t sec_ = sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if ((tm = gmtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm->field;
# define LOCALTIME_RET(field) \
time_t sec_ = sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if ((tm = localtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
|
|
|
|
|
|
|
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# import "OFThread.h"
static OFMutex *mutex;
#endif
#ifdef HAVE_GMTIME_R
# define GMTIME_RET(field) \
time_t sec_ = (time_t)sec; \
struct tm tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if (gmtime_r(&sec_, &tm) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm.field;
# define LOCALTIME_RET(field) \
time_t sec_ = (time_t)sec; \
struct tm tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if (localtime_r(&sec_, &tm) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm.field;
#else
# ifdef OF_THREADS
# define GMTIME_RET(field) \
time_t sec_ = (time_t)sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
[mutex lock]; \
\
@try { \
if ((tm = gmtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm->field; \
} @finally { \
[mutex unlock]; \
}
# define LOCALTIME_RET(field) \
time_t sec_ = (time_t)sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
[mutex lock]; \
\
@try { \
if ((tm = localtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm->field; \
} @finally { \
[mutex unlock]; \
}
# else
# define GMTIME_RET(field) \
time_t sec_ = (time_t)sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if ((tm = gmtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
return tm->field;
# define LOCALTIME_RET(field) \
time_t sec_ = (time_t)sec; \
struct tm *tm; \
\
if (sec != sec_) \
@throw [OFOutOfRangeException newWithClass: isa]; \
\
if ((tm = localtime(&sec_)) == NULL) \
@throw [OFOutOfRangeException newWithClass: isa]; \
|
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
if (gettimeofday(&t, NULL)) {
Class c = isa;
[self release];
@throw [OFInitializationFailedException newWithClass: c];
}
return [self initWithTimeIntervalSince1970: t.tv_sec
microseconds: t.tv_usec];
}
- initWithTimeIntervalSince1970: (int64_t)sec_
{
return [self initWithTimeIntervalSince1970: sec_
microseconds: 0];
}
|
|
|
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
if (gettimeofday(&t, NULL)) {
Class c = isa;
[self release];
@throw [OFInitializationFailedException newWithClass: c];
}
return [self initWithTimeIntervalSince1970: t.tv_sec
microseconds: (uint32_t)t.tv_usec];
}
- initWithTimeIntervalSince1970: (int64_t)sec_
{
return [self initWithTimeIntervalSince1970: sec_
microseconds: 0];
}
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
{
LOCALTIME_RET(tm_yday + 1)
}
- (OFString*)dateStringWithFormat: (OFString*)fmt
{
OFString *ret;
time_t sec_ = sec;
struct tm tm;
char *buf;
if (sec != sec_)
@throw [OFOutOfRangeException newWithClass: isa];
#ifdef HAVE_GMTIME_R
|
|
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
{
LOCALTIME_RET(tm_yday + 1)
}
- (OFString*)dateStringWithFormat: (OFString*)fmt
{
OFString *ret;
time_t sec_ = (time_t)sec;
struct tm tm;
char *buf;
if (sec != sec_)
@throw [OFOutOfRangeException newWithClass: isa];
#ifdef HAVE_GMTIME_R
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
return ret;
}
- (OFString*)localDateStringWithFormat: (OFString*)fmt
{
OFString *ret;
time_t sec_ = sec;
struct tm tm;
char *buf;
if (sec != sec_)
@throw [OFOutOfRangeException newWithClass: isa];
#ifdef HAVE_LOCALTIME_R
|
|
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
return ret;
}
- (OFString*)localDateStringWithFormat: (OFString*)fmt
{
OFString *ret;
time_t sec_ = (time_t)sec;
struct tm tm;
char *buf;
if (sec != sec_)
@throw [OFOutOfRangeException newWithClass: isa];
#ifdef HAVE_LOCALTIME_R
|