Example #1
0
void convert(Date& date, const std::string& s)
{
    if (s.size() < 10 || s.at(4) != '-' || s.at(7) != '-')
    {
        throw ConversionError("Illegal date format");
    }

    const char* d = s.data();
    date = Date(getNumber4(d), getNumber2(d + 5), getNumber2(d + 8));
}
Example #2
0
int getNumber2(int x, P map){
	int ret;
	if(x == 0){
		ret = toi(fst(map));
	}
	else{
		ret = getNumber2(x - 1, snd(map));
	}
	return ret;
}
Example #3
0
  Date Date::fromIso(const std::string& s)
  {
    Date ret;
    const char* d = s.data();
    try
    {
      if (s.size() < 10
        || d[4] != '-'
        || d[7] != '-')
        throw TypeError();
      ret.set(getNumber4(d), getNumber2(d + 5), getNumber2(d + 8));
    }
    catch (const TypeError&)
    {
      throw TypeError("failed to convert string \"" + s + "\" into date");
    }

    return ret;
  }
Example #4
0
int getNumber(int y, int x, P map){
	int ret;
	if(y == 0){
		ret = getNumber2(x, fst(map));
	}
	else
	{
		ret = getNumber(y - 1, x, snd(map));
	}
	return ret;
}
Example #5
0
  Time Time::fromIso(const std::string& s)
  {
    Time ret;
    const char* d = s.data();
    try
    {
      if (s.size() == 12
        && d[2] == ':'
        && d[5] == ':'
        && d[8] == '.')
      {
        ret.set(getNumber2(d), getNumber2(d + 3), getNumber2(d + 6),
                getNumber3(d + 9));
      }
      else if (s.size() == 8
        && d[2] == ':'
        && d[5] == ':')
      {
        ret.set(getNumber2(d), getNumber2(d + 3), getNumber2(d + 6));
      }
      else
        throw TypeError();
    }
    catch (const TypeError&)
    {
      throw TypeError("failed to convert string \"" + s + "\" into time");
    }

    return ret;
  }