ObjFW  Check-in [5d102d382e]

Overview
Comment:Fix parsing of struct tm.

Only add an extra day for the current year if it is a leap year and it
is at least March.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5d102d382e7be14d8af354fc292adca83894e81ba0f93f6656f19c3ddfa08707
User & Date: js on 2011-11-02 11:20:00
Other Links: manifest | tags
Context
2011-11-14
18:33
Make OFDataArray's cArray a property. check-in: 57ef5e22ab user: js tags: trunk
2011-11-02
11:20
Fix parsing of struct tm. check-in: 5d102d382e user: js tags: trunk
2011-10-31
22:02
Add -[UTF16String] to OFString. check-in: a51b3cb390 user: js tags: trunk
Changes

Modified src/OFDate.m from [11883eeeee] to [7dd968f934].

131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
		@throw [OFOutOfRangeException exceptionWithClass: isa];	\
									\
	return tm->field;
# endif
#endif

static int month_to_day_of_year[12] = {

	31,
	31 + 28,
	31 + 28 + 31,
	31 + 28 + 31 + 30,
	31 + 28 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30,
	31 + 28 + 31 + 30 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31
};

@implementation OFDate
#if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \
    defined(OF_THREADS)
+ (void)initialize
{







>











<







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
		@throw [OFOutOfRangeException exceptionWithClass: isa];	\
									\
	return tm->field;
# endif
#endif

static int month_to_day_of_year[12] = {
	0,
	31,
	31 + 28,
	31 + 28 + 31,
	31 + 28 + 31 + 30,
	31 + 28 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30,
	31 + 28 + 31 + 30 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,

};

@implementation OFDate
#if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \
    defined(OF_THREADS)
+ (void)initialize
{
252
253
254
255
256
257
258
259
260
261
262
263





264
265
266
267
268
269
270
271
272
273
274
275
#ifdef STRUCT_TM_HAS_TM_GMTOFF
		if (tm.tm_gmtoff != 0)
			@throw [OFInvalidFormatException
			    exceptionWithClass: isa];
#endif

		/* Years */
		seconds = (time_t)(tm.tm_year - 70) * 31536000;
		/* Leap years */
		seconds += (((tm.tm_year + 1900) / 4) - 492) * 86400;
		seconds -= (((tm.tm_year + 1900) / 100) - 19) * 86400;
		seconds += (((tm.tm_year + 1900) / 400) - 4) * 86400;





		/* Months */
		if (tm.tm_mon < 0 || tm.tm_mon > 12)
			@throw [OFInvalidFormatException
			    exceptionWithClass: isa];
		seconds += month_to_day_of_year[tm.tm_mon - 1] * 86400;
		/* Days */
		seconds += (tm.tm_mday - 1) * 86400;
		/* Hours */
		seconds += tm.tm_hour * 3600;
		/* Minutes */
		seconds += tm.tm_min * 60;
		/* Seconds */







|
|
|
|
|
>
>
>
>
>




|







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#ifdef STRUCT_TM_HAS_TM_GMTOFF
		if (tm.tm_gmtoff != 0)
			@throw [OFInvalidFormatException
			    exceptionWithClass: isa];
#endif

		/* Years */
		seconds = (int64_t)(tm.tm_year - 70) * 31536000;
		/* Days of leap years, excluding the year to look at */
		seconds += (((tm.tm_year + 1899) / 4) - 492) * 86400;
		seconds -= (((tm.tm_year + 1899) / 100) - 19) * 86400;
		seconds += (((tm.tm_year + 1899) / 400) - 4) * 86400;
		/* Leap day */
		if (tm.tm_mon >= 2 && (((tm.tm_year + 1900) % 4 == 0 &&
		    (tm.tm_year + 1900) % 100 != 0) ||
		    (tm.tm_year + 1900) % 400 == 0))
			seconds += 86400;
		/* Months */
		if (tm.tm_mon < 0 || tm.tm_mon > 12)
			@throw [OFInvalidFormatException
			    exceptionWithClass: isa];
		seconds += month_to_day_of_year[tm.tm_mon] * 86400;
		/* Days */
		seconds += (tm.tm_mday - 1) * 86400;
		/* Hours */
		seconds += tm.tm_hour * 3600;
		/* Minutes */
		seconds += tm.tm_min * 60;
		/* Seconds */