Subversion Repositories Kolibri OS

Rev

Rev 1906 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1906 Rev 3065
Line 105... Line 105...
105
	  tim_p->tm_hour += 24;
105
	  tim_p->tm_hour += 24;
106
	  --tim_p->tm_mday;
106
	  --tim_p->tm_mday;
107
        }
107
        }
108
    }
108
    }
Line 109... Line 109...
109
 
109
 
110
  if (tim_p->tm_mon > 11)
110
  if (tim_p->tm_mon < 0 || tim_p->tm_mon > 11)
111
    {
111
    {
112
      res = div (tim_p->tm_mon, 12);
112
      res = div (tim_p->tm_mon, 12);
113
      tim_p->tm_year += res.quot;
113
      tim_p->tm_year += res.quot;
114
      if ((tim_p->tm_mon = res.rem) < 0)
114
      if ((tim_p->tm_mon = res.rem) < 0)
Line 157... Line 157...
157
_DEFUN(mktime, (tim_p),
157
_DEFUN(mktime, (tim_p),
158
     struct tm *tim_p)
158
     struct tm *tim_p)
159
{
159
{
160
  time_t tim = 0;
160
  time_t tim = 0;
161
  long days = 0;
161
  long days = 0;
162
  int year, isdst, tm_isdst;
162
  int year, isdst=0;
163
  __tzinfo_type *tz = __gettzinfo ();
163
  __tzinfo_type *tz = __gettzinfo ();
Line 164... Line 164...
164
 
164
 
165
  /* validate structure */
165
  /* validate structure */
Line 176... Line 176...
176
    days++;
176
    days++;
Line 177... Line 177...
177
 
177
 
178
  /* compute day of the year */
178
  /* compute day of the year */
Line 179... Line -...
179
  tim_p->tm_yday = days;
-
 
180
 
179
  tim_p->tm_yday = days;
181
  if (tim_p->tm_year > 10000
-
 
182
      || tim_p->tm_year < -10000)
180
 
183
    {
-
 
Line 184... Line 181...
184
      return (time_t) -1;
181
  if (tim_p->tm_year > 10000 || tim_p->tm_year < -10000)
185
    }
182
      return (time_t) -1;
186
 
183
 
187
  /* compute days in other years */
184
  /* compute days in other years */
188
  if (tim_p->tm_year > 70)
185
  if ((year = tim_p->tm_year) > 70)
189
    {
186
    {
190
      for (year = 70; year < tim_p->tm_year; year++)
187
      for (year = 70; year < tim_p->tm_year; year++)
191
	days += _DAYS_IN_YEAR (year);
188
	days += _DAYS_IN_YEAR (year);
192
    }
189
    }
193
  else if (tim_p->tm_year < 70)
190
  else if (year < 70)
194
    {
191
    {
195
      for (year = 69; year > tim_p->tm_year; year--)
192
      for (year = 69; year > tim_p->tm_year; year--)
Line 196... Line -...
196
	days -= _DAYS_IN_YEAR (year);
-
 
197
      days -= _DAYS_IN_YEAR (year);
-
 
198
    }
-
 
199
 
-
 
200
  /* compute day of the week */
193
	days -= _DAYS_IN_YEAR (year);
201
  if ((tim_p->tm_wday = (days + 4) % 7) < 0)
194
      days -= _DAYS_IN_YEAR (year);
Line 202... Line -...
202
    tim_p->tm_wday += 7;
-
 
203
 
-
 
204
  /* compute total seconds */
195
    }
Line 205... Line 196...
205
  tim += (days * _SEC_IN_DAY);
196
 
206
 
197
  /* compute total seconds */
-
 
198
  tim += (days * _SEC_IN_DAY);
207
  /* Convert user positive into 1 */
199
 
-
 
200
  TZ_LOCK;
-
 
201
 
-
 
202
  if (_daylight)
-
 
203
    {
208
  tm_isdst = tim_p->tm_isdst > 0  ?  1 : tim_p->tm_isdst;
204
      int tm_isdst;
209
  isdst = tm_isdst;
205
      int y = tim_p->tm_year + YEAR_BASE;
210
 
206
  /* Convert user positive into 1 */
211
  if (_daylight)
207
  tm_isdst = tim_p->tm_isdst > 0  ?  1 : tim_p->tm_isdst;
212
    {
208
  isdst = tm_isdst;
Line 242... Line 238...
242
		  int diff = (int) (tz->__tzrule[0].offset
238
		  int diff = (int) (tz->__tzrule[0].offset
243
				    - tz->__tzrule[1].offset);
239
				    - tz->__tzrule[1].offset);
244
		  if (!isdst)
240
		  if (!isdst)
245
		    diff = -diff;
241
		    diff = -diff;
246
		  tim_p->tm_sec += diff;
242
		  tim_p->tm_sec += diff;
247
		  validate_structure (tim_p);
-
 
248
		  tim += diff;  /* we also need to correct our current time calculation */
243
		  tim += diff;  /* we also need to correct our current time calculation */
-
 
244
		  int mday = tim_p->tm_mday;
-
 
245
		  validate_structure (tim_p);
-
 
246
		  mday = tim_p->tm_mday - mday;
-
 
247
		  /* roll over occurred */
-
 
248
		  if (mday) {
-
 
249
		    /* compensate for month roll overs */
-
 
250
		    if (mday > 1)
-
 
251
			  mday = -1;
-
 
252
		    else if (mday < -1)
-
 
253
			  mday = 1;
-
 
254
		    /* update days for wday calculation */
-
 
255
		    days += mday;
-
 
256
		    /* handle yday */
-
 
257
		    if ((tim_p->tm_yday += mday) < 0) {
-
 
258
			  --year;
-
 
259
			  tim_p->tm_yday = _DAYS_IN_YEAR(year) - 1;
-
 
260
		    } else {
-
 
261
			  mday = _DAYS_IN_YEAR(year);
-
 
262
			  if (tim_p->tm_yday > (mday - 1))
-
 
263
				tim_p->tm_yday -= mday;
-
 
264
		    }
-
 
265
		  }
249
		}
266
		}
250
	    }
267
	    }
251
	}
268
	}
252
    }
269
    }
Line 255... Line 272...
255
  if (isdst == 1)
272
  if (isdst == 1)
256
    tim += (time_t) tz->__tzrule[1].offset;
273
    tim += (time_t) tz->__tzrule[1].offset;
257
  else /* otherwise assume std time */
274
  else /* otherwise assume std time */
258
    tim += (time_t) tz->__tzrule[0].offset;
275
    tim += (time_t) tz->__tzrule[0].offset;
Line -... Line 276...
-
 
276
 
-
 
277
  TZ_UNLOCK;
259
 
278
 
260
  /* reset isdst flag to what we have calculated */
279
  /* reset isdst flag to what we have calculated */
Line -... Line 280...
-
 
280
  tim_p->tm_isdst = isdst;
-
 
281
 
-
 
282
  /* compute day of the week */
-
 
283
  if ((tim_p->tm_wday = (days + 4) % 7) < 0)
261
  tim_p->tm_isdst = isdst;
284
    tim_p->tm_wday += 7;
262
 
285