Files
Work/sql/sqldate.hpp
2024-08-07 09:16:27 -04:00

114 lines
2.1 KiB
C++

#ifndef _SQL_SQLDATE_HPP_
#define _SQL_SQLDATE_HPP_
#ifndef _SQL_SQLSTRING_HPP_
#include <sql/sqlstring.hpp>
#endif
#ifndef _COMMON_SDATE_HPP_
#include <common/sdate.hpp>
#endif
#ifndef _COMMON_STDIO_HPP_
#include <common/stdio.hpp>
#endif
#ifndef _COMMON_SYSTEMTIME_HPP_
#include <common/systime.hpp>
#endif
class SQLDate : public SDate
{
public:
SQLDate(void);
SQLDate(const SQLDate &someDate);
SQLDate(const SDate &someDate);
SQLDate(const String &sqlDateString);
SQLDate(const SystemTime &systemTime);
virtual ~SQLDate();
SQLDate &operator=(const SQLDate &someDate);
SQLDate &operator=(const SDate &someDate);
SQLDate &operator=(const String &sqlDateString);
SQLDate &operator=(const SystemTime &systemTime);
SQLString toString()const;
void fromString(const SQLString &sqlDateString);
private:
};
inline
SQLDate::SQLDate(void)
{
}
inline
SQLDate::SQLDate(const SQLDate &someDate)
{
*this=someDate;
}
inline
SQLDate::SQLDate(const SDate &someDate)
{
*this=someDate;
}
inline
SQLDate::SQLDate(const SystemTime &systemTime)
{
*this=systemTime;
}
inline
SQLDate::SQLDate(const String &sqlDateString)
{
fromString(sqlDateString);
}
inline
SQLDate::~SQLDate()
{
}
inline
SQLDate &SQLDate::operator=(const SQLDate &someDate)
{
*this=(SDate&)someDate;
return *this;
}
inline
SQLDate &SQLDate::operator=(const SDate &someDate)
{
(SDate&)*this=someDate;
return *this;
}
inline
SQLDate &SQLDate::operator=(const SystemTime &systemTime)
{
day(systemTime.day());
month(systemTime.month());
year(systemTime.year());
return *this;
}
inline
SQLDate &SQLDate::operator=(const String &sqlDateString)
{
fromString(sqlDateString);
return *this;
}
inline
SQLString SQLDate::toString()const
{
SQLString sqlDateString;
::sprintf(sqlDateString,"%04d-%02d-%02d 00:00:00.0",year()?year():1900,month()?month():1,day()?day():1);
return sqlDateString;
}
inline
void SQLDate::fromString(const SQLString &sqlDateString)
{
if(sqlDateString.isNull())return;
year(::atoi(sqlDateString.betweenString(0,'-')));
month(::atoi(sqlDateString.betweenString('-','-')));
day(::atoi(sqlDateString.betweenString('-',' ').betweenString('-',0)));
}
#endif