Exemplo n.º 1
0
    boost::posix_time::ptime TimeMap::timeFromEclipse( const DeckRecord& dateRecord ) {
        static const std::string errorMsg("The datarecord must consist of the for values "
                                          "\"DAY(int), MONTH(string), YEAR(int), TIME(string)\".\n");
        if (dateRecord.size() != 4) {
            throw std::invalid_argument( errorMsg);
        }

        const auto& dayItem = dateRecord.getItem( 0 );
        const auto& monthItem = dateRecord.getItem( 1 );
        const auto& yearItem = dateRecord.getItem( 2 );
        const auto& timeItem = dateRecord.getItem( 3 );

        try {
            int day = dayItem.get< int >(0);
            const std::string& month = monthItem.get< std::string >(0);
            int year = yearItem.get< int >(0);
            std::string eclipseTimeString = timeItem.get< std::string >(0);

            return TimeMap::timeFromEclipse(day, month, year, eclipseTimeString);
        } catch (...) {
            throw std::invalid_argument( errorMsg );
        }
    }