#pragma once
#include <iostream>
#include <string>

//
class DateTime
{
public:
    DateTime(int year, int month, int day, int hour, int minute, int second)
    {
        SetDateTime(year, month, day, hour, minute, second);
    }

    DateTime()
    {
        SetDateTime(0, 0, 0, 0, 0, 0);
    }

    ~DateTime() {}

    // Set date and time
    void SetDateTime(int year, int month, int day, int hour, int minute, int second)
    {
        m_year = year;
        m_month = month;
        m_day = day;
        m_hour = hour;
        m_minute = minute;
        m_second = second;
    }

    //copy constructor
    DateTime(const DateTime& other)
    {
        m_year = other.m_year;
        m_month = other.m_month;
        m_day = other.m_day;
        m_hour = other.m_hour;
        m_minute = other.m_minute;
        m_second = other.m_second;
    }

    DateTime& operator=(const DateTime& other)
    {
        m_year = other.m_year;
        m_month = other.m_month;
        m_day = other.m_day;
        m_hour = other.m_hour;
        m_minute = other.m_minute;
        m_second = other.m_second;
        return *this;
    }

    // Get date and time
    std::string GetDateTime()
    {
        return std::to_string(m_year) + "-" + std::to_string(m_month) + "-" + std::to_string(m_day) + " " + std::to_string(m_hour) + ":" + std::to_string(m_minute) + ":" + std::to_string(m_second);
    }

    // 比较两个对象
    int CompareTo(DateTime other)
    {
        if (m_year != other.m_year)
        {
            return m_year < other.m_year ? -1 : 1;
        }
        if (m_month != other.m_month)
        {
            return m_month < other.m_month ? -1 : 1;
        }
        if (m_day != other.m_day)
        {
            return m_day < other.m_day ? -1 : 1;
        }
        if (m_hour != other.m_hour)
        {
            return m_hour < other.m_hour ? -1 : 1;
        }
        if (m_minute != other.m_minute)
        {
            return m_minute < other.m_minute ? -1 : 1;
        }
        if (m_second != other.m_second)
        {
            return m_second < other.m_second ? -1 : 1;
        }
        return 0;
    }

    // < Operator overwrite
    bool operator<(const DateTime& other)
    {
        return CompareTo(other) < 0;
    }

    // > Operator overwrite
    bool operator>(const DateTime& other)
    {
        return CompareTo(other) > 0;
    }

    // == Operator overwrite
    bool operator==(const DateTime& other)
    {
        return CompareTo(other) == 0;
    }

    // 访问私有成员
    int& year() { return m_year; }
    int& month() { return m_month; }
    int& day() { return m_day; }
    int& hour() { return m_hour; }
    int& minute() { return m_minute; }
    int& second() { return m_second; }

private:
    int m_year;
    int m_month;
    int m_day;
    int m_hour;
    int m_minute;
    int m_second;
};