Ejemplo n.º 1
0
/* Parses the syntax hh H mm M ss S.  */
static time_t
parse_HMS (cch_t * pz)
{
  time_t res = 0;
  cch_t * ps = strchr (pz, 'H');
  if (ps != NULL)
    {
      res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
      pz++;
    }

  ps = strchr (pz, 'M');
  if (ps != NULL)
    {
      res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN);
      pz++;
    }

  ps = strchr (pz, 'S');
  if (ps != NULL)
    {
      res = parse_scaled_value (res, &pz, ps, 1);
      pz++;
    }

  while (isspace ((unsigned char)*pz))
    pz++;
  if (*pz != NUL)
    {
      errno = EINVAL;
      return BAD_TIME;
    }

  return res;
}
Ejemplo n.º 2
0
/* Parses the syntax HHMMSS.  */
static time_t
parse_hourminutesecond (cch_t * in_pz)
{
  time_t res = 0;
  char   buf[4];
  cch_t * pz;

  if (strlen (in_pz) != 6)
    {
      errno = EINVAL;
      return BAD_TIME;
    }

  memcpy (buf, in_pz, 2);
  buf[2] = NUL;
  pz = buf;
  res = parse_scaled_value (0, &pz, buf + 2, SEC_PER_HR);

  memcpy (buf, in_pz + 2, 2);
  buf[2] = NUL;
  pz =   buf;
  res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MIN);

  memcpy (buf, in_pz + 4, 2);
  buf[2] = NUL;
  pz =   buf;
  return parse_scaled_value (res, &pz, buf + 2, 1);
}
Ejemplo n.º 3
0
/* Parses the syntax YYYYMMDD.  */
static time_t
parse_yearmonthday (cch_t * in_pz)
{
  time_t res = 0;
  char   buf[8];
  cch_t * pz;

  if (strlen (in_pz) != 8)
    {
      errno = EINVAL;
      return BAD_TIME;
    }

  memcpy (buf, in_pz, 4);
  buf[4] = NUL;
  pz = buf;
  res = parse_scaled_value (0, &pz, buf + 4, SEC_PER_YEAR);

  memcpy (buf, in_pz + 4, 2);
  buf[2] = NUL;
  pz =   buf;
  res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MONTH);

  memcpy (buf, in_pz + 6, 2);
  buf[2] = NUL;
  pz =   buf;
  return parse_scaled_value (res, &pz, buf + 2, SEC_PER_DAY);
}
Ejemplo n.º 4
0
static time_t
parse_year_month_day (cch_t * pz, cch_t * ps)
{
    time_t res = 0;

    res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);

    ps = strchr (++pz, '-');
    if (ps == NULL)
    {
        errno = EINVAL;
        return BAD_TIME;
    }
    res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);

    pz++;
    ps = pz + strlen (pz);
    return parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
}
Ejemplo n.º 5
0
/* Parses the syntax yy Y mm M ww W dd D.  */
static time_t
parse_YMWD (cch_t * pz)
{
  time_t res = 0;
  cch_t * ps = strchr (pz, 'Y');
  if (ps != NULL)
    {
      res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
      pz++;
    }

  ps = strchr (pz, 'M');
  if (ps != NULL)
    {
      res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);
      pz++;
    }

  ps = strchr (pz, 'W');
  if (ps != NULL)
    {
      res = parse_scaled_value (res, &pz, ps, SEC_PER_WEEK);
      pz++;
    }

  ps = strchr (pz, 'D');
  if (ps != NULL)
    {
      res = parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
      pz++;
    }

  while (isspace ((unsigned char)*pz))
    pz++;
  if (*pz != NUL)
    {
      errno = EINVAL;
      return BAD_TIME;
    }

  return res;
}
Ejemplo n.º 6
0
static time_t
parse_hour_minute_second (cch_t * pz, cch_t * ps)
{
    time_t res = 0;

    res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);

    ps = strchr (++pz, ':');
    if (ps == NULL)
    {
        errno = EINVAL;
        return BAD_TIME;
    }

    res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN);

    pz++;
    ps = pz + strlen (pz);
    return parse_scaled_value (res, &pz, ps, 1);
}