X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbms%2FDate.cpp;fp=source%2Fdbms%2FDate.cpp;h=0000000000000000000000000000000000000000;hb=851ff2962362fd5bad874e8ed91445b296eaca24;hp=5c9afafae940695fe66e192e2f2eaf2702f948c7;hpb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;p=anna.git diff --git a/source/dbms/Date.cpp b/source/dbms/Date.cpp deleted file mode 100644 index 5c9afaf..0000000 --- a/source/dbms/Date.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// ANNA - Anna is Not Nothingness Anymore // -// // -// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // -// // -// See project site at http://redmine.teslayout.com/projects/anna-suite // -// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // - - -#include - -#include -#include - -#include - -using namespace std; -using namespace anna; -using namespace anna::dbms; - -Date::Date(const bool isNulleable, const char* format) : - Data(Type::Date, MaxDateSize, isNulleable) { - Data::setBuffer(a_buffer); - a_buffer [0] = 0; - a_format = (format == NULL) ? NULL : strdup(format); - anna_memset(&a_value, 0, sizeof(a_value)); -} - -Date::Date(const Data::Type::_v type, const bool isNulleable, const char* format) : - Data(type, MaxDateSize, isNulleable) { - Data::setBuffer(a_buffer); - a_buffer [0] = 0; - a_format = (format == NULL) ? NULL : strdup(format); - anna_memset(&a_value, 0, sizeof(a_value)); -} - -Date::Date(const Date& other) : - Data(other) { - Data::setBuffer(a_buffer); - a_buffer [0] = 0; - a_format = (other.a_format == NULL) ? NULL : strdup(other.a_format); - anna_memcpy(&a_value, &other.a_value, sizeof(a_value)); -} - -Date::~Date() { - if(a_format != NULL) - free(a_format); -} - -const char* dbms::Date::getCStringValue() const -throw() { - const char* format; - - if((format = a_format) == NULL) - format = "%d/%m/%Y %H:%M:%S"; - - return (strftime(const_cast (this)->a_buffer, MaxDateSize, format, &a_value) == 0) ? NULL : a_buffer; -} - -Date& Date::operator = (const Date & other) -throw(RuntimeException) { - if(this != &other) { - if(other.isNull() == true) { - setNull(true); - anna_memset(&a_value, 0, sizeof(a_value)); - } else { - setNull(false); - anna_memcpy(&a_value, &other.a_value, sizeof(a_value)); - } - } - - return *this; -} - -void Date::setValue(const char* str) -throw(RuntimeException) { - if(a_format == NULL) { - string msg(asString()); - msg += " | anna::dbms::Data::setValue (const char*) requires format especification"; - throw RuntimeException(msg, ANNA_FILE_LOCATION); - } - - tm aux; - char* r = strptime(str, a_format, &aux); - - if(r == NULL) { - string msg(asString()); - msg += " | String: "; - msg += str; - msg += " | Can't be interpreted as valid date"; - throw RuntimeException(msg, ANNA_FILE_LOCATION); - } - - Data::setNull(false); - anna_memcpy(&a_value, &aux, sizeof(a_value)); -} - -void Date::setValue(const Second &second) -throw(RuntimeException) { - tm* aux = localtime((time_t*) & second); - - if(aux == NULL) { - string msg(asString()); - msg += functions::asText(" | Second: ", (int) second); - msg += " | Can't be interpreted as valid date"; - throw RuntimeException(msg, ANNA_FILE_LOCATION); - } - - Data::setNull(false); - anna_memcpy(&a_value, aux, sizeof(a_value)); -} - -void dbms::Date::set(const char* what, int& variable, const int value, const int min, const int max) -throw(RuntimeException) { - if(value < min) { - string msg(what); - msg += functions::asText(" must be greater than or equal to ", min); - throw RuntimeException(msg, ANNA_FILE_LOCATION); - } - - if(value > max && max != -1) { - string msg(what); - msg += functions::asText(" must be less than or equal to ", max); - throw RuntimeException(msg, ANNA_FILE_LOCATION); - } - - Data::setNull(false); - variable = value; -} - -string dbms::Date::asString() const -throw() { - const char* cstring; - string result("dbms::Date { "); - result += dbms::Data::asString(); - result += " | Format: "; - result += (a_format == NULL) ? "" : a_format; - result += " | Value: "; - - if(Data::isNull() == false) { - if((cstring = getCStringValue()) == NULL) - result += ""; - else - result += cstring; - } else - result += ""; - - return result += " }"; -} -