Ejemplo n.º 1
0
FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result)
{
  time_t epoch;
  time_t jdn;
  int    year;
  int    month;
  int    day;
  int    hour;
  int    min;
  int    sec;

  /* Get the seconds since the EPOCH */

  epoch = *timer;
  sdbg("timer=%d\n", (int)epoch);

  /* Convert to days, hours, minutes, and seconds since the EPOCH */

  jdn    = epoch / SEC_PER_DAY;
  epoch -= SEC_PER_DAY * jdn;

  hour   = epoch / SEC_PER_HOUR;
  epoch -= SEC_PER_HOUR * hour;

  min    = epoch / SEC_PER_MIN;
  epoch -= SEC_PER_MIN * min;

  sec    = epoch;

  sdbg("hour=%d min=%d sec=%d\n",
       (int)hour, (int)min, (int)sec);

  /* Convert the days since the EPOCH to calendar day */

  clock_utc2calendar(jdn, &year, &month, &day);

  sdbg("jdn=%d year=%d month=%d day=%d\n",
       (int)jdn, (int)year, (int)month, (int)day);

  /* Then return the struct tm contents */

  result->tm_year  = (int)year - 1900; /* Relative to 1900 */
  result->tm_mon   = (int)month - 1;   /* zero-based */
  result->tm_mday  = (int)day;         /* one-based */
  result->tm_hour  = (int)hour;
  result->tm_min   = (int)min;
  result->tm_sec   = (int)sec;

#if defined(CONFIG_TIME_EXTENDED)
  result->tm_wday  = clock_dayoftheweek(day, month, year);
  result->tm_yday  = day + clock_daysbeforemonth(result->tm_mon, clock_isleapyear(year));
  result->tm_isdst = 0;
#endif

  return result;
}
Ejemplo n.º 2
0
FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result)
{
  time_t epoch;
  time_t jdn;
  int    year;
  int    month;
  int    day;
  int    hour;
  int    min;
  int    sec;

  /* Get the seconds since the EPOCH */

  epoch = *timer;
  sdbg("timer=%d\n", (int)epoch);

  /* Convert to days, hours, minutes, and seconds since the EPOCH */

  jdn    = epoch / SEC_PER_DAY;
  epoch -= SEC_PER_DAY * jdn;

  hour   = epoch / SEC_PER_HOUR;
  epoch -= SEC_PER_HOUR * hour;

  min    = epoch / SEC_PER_MIN;
  epoch -= SEC_PER_MIN * min;

  sec    = epoch;

  sdbg("hour=%d min=%d sec=%d\n",
       (int)hour, (int)min, (int)sec);

  /* Convert the days since the EPOCH to calendar day */

  clock_utc2calendar(jdn, &year, &month, &day);

  sdbg("jdn=%d year=%d month=%d day=%d\n",
       (int)jdn, (int)year, (int)month, (int)day);

  /* Then return the struct tm contents */

  result->tm_year = (int)year - 1900; /* Relative to 1900 */
  result->tm_mon  = (int)month - 1;   /* zero-based */
  result->tm_mday = (int)day;         /* one-based */
  result->tm_hour = (int)hour;
  result->tm_min  = (int)min;
  result->tm_sec  = (int)sec;

  return result;
}