OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [newlib/] [newlib/] [newlib/] [libc/] [time/] [mktime.c] - Diff between revs 39 and 56

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 39 Rev 56
Line 58... Line 58...
#define _DAYS_IN_MONTH(x) ((x == 1) ? days_in_feb : DAYS_IN_MONTH[x])
#define _DAYS_IN_MONTH(x) ((x == 1) ? days_in_feb : DAYS_IN_MONTH[x])
 
 
static _CONST int _DAYS_BEFORE_MONTH[12] =
static _CONST int _DAYS_BEFORE_MONTH[12] =
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
 
 
#define _DAYS_IN_YEAR(year) (((year) % 4) ? 365 : 366)
#define _ISLEAP(y) (((y) % 4) == 0 && (((y) % 100) != 0 || (((y)+1900) % 400) == 0))
 
#define _DAYS_IN_YEAR(year) (_ISLEAP(year) ? 366 : 365)
 
 
static void
static void
validate_structure (tim_p)
validate_structure (tim_p)
     struct tm *tim_p;
     struct tm *tim_p;
{
{
Line 73... Line 74...
  if (tim_p->tm_sec < 0 || tim_p->tm_sec > 59)
  if (tim_p->tm_sec < 0 || tim_p->tm_sec > 59)
    {
    {
      res = div (tim_p->tm_sec, 60);
      res = div (tim_p->tm_sec, 60);
      tim_p->tm_min += res.quot;
      tim_p->tm_min += res.quot;
      if ((tim_p->tm_sec = res.rem) < 0)
      if ((tim_p->tm_sec = res.rem) < 0)
 
        {
        tim_p->tm_sec += 60;
        tim_p->tm_sec += 60;
 
          --tim_p->tm_min;
 
        }
    }
    }
 
 
  if (tim_p->tm_min < 0 || tim_p->tm_min > 59)
  if (tim_p->tm_min < 0 || tim_p->tm_min > 59)
    {
    {
      res = div (tim_p->tm_min, 60);
      res = div (tim_p->tm_min, 60);
      tim_p->tm_hour += res.quot;
      tim_p->tm_hour += res.quot;
      if ((tim_p->tm_min = res.rem) < 0)
      if ((tim_p->tm_min = res.rem) < 0)
 
        {
        tim_p->tm_min += 60;
        tim_p->tm_min += 60;
 
          --tim_p->tm_hour;
 
        }
    }
    }
 
 
  if (tim_p->tm_hour < 0 || tim_p->tm_hour > 23)
  if (tim_p->tm_hour < 0 || tim_p->tm_hour > 23)
    {
    {
      res = div (tim_p->tm_hour, 24);
      res = div (tim_p->tm_hour, 24);
      tim_p->tm_mday += res.quot;
      tim_p->tm_mday += res.quot;
      if ((tim_p->tm_hour = res.rem) < 0)
      if ((tim_p->tm_hour = res.rem) < 0)
 
        {
        tim_p->tm_hour += 24;
        tim_p->tm_hour += 24;
 
          --tim_p->tm_mday;
 
        }
    }
    }
 
 
  if (tim_p->tm_mon > 11)
  if (tim_p->tm_mon > 11)
    {
    {
      res = div (tim_p->tm_mon, 12);
      res = div (tim_p->tm_mon, 12);
      tim_p->tm_year += res.quot;
      tim_p->tm_year += res.quot;
      if ((tim_p->tm_mon = res.rem) < 0)
      if ((tim_p->tm_mon = res.rem) < 0)
 
        {
        tim_p->tm_mon += 12;
        tim_p->tm_mon += 12;
 
          --tim_p->tm_year;
 
        }
    }
    }
 
 
  if (_DAYS_IN_YEAR (tim_p->tm_year) == 366)
  if (_DAYS_IN_YEAR (tim_p->tm_year) == 366)
    days_in_feb = 29;
    days_in_feb = 29;
 
 
  if (tim_p->tm_mday < 0)
  if (tim_p->tm_mday <= 0)
    {
    {
      while (tim_p->tm_mday < 0)
      while (tim_p->tm_mday <= 0)
        {
        {
          tim_p->tm_mday += _DAYS_IN_MONTH (tim_p->tm_mon);
 
          if (--tim_p->tm_mon == -1)
          if (--tim_p->tm_mon == -1)
            {
            {
              tim_p->tm_year--;
              tim_p->tm_year--;
              tim_p->tm_mon = 12;
              tim_p->tm_mon = 11;
              days_in_feb =
              days_in_feb =
                ((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ?
                ((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ?
                 29 : 28);
                 29 : 28);
            }
            }
 
          tim_p->tm_mday += _DAYS_IN_MONTH (tim_p->tm_mon);
        }
        }
    }
    }
  else
  else
    {
    {
      while (tim_p->tm_mday > _DAYS_IN_MONTH (tim_p->tm_mon))
      while (tim_p->tm_mday > _DAYS_IN_MONTH (tim_p->tm_mon))

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.