/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2010 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstddatetime
 * Version: 1.03
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstddatetime library
 * 
 * mzstddatetime library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstddatetime library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#include "mzDateTime.h"

WINAPI CDateTime::CDateTime() {
    this->setRealClassName(L"CDateTime");
}

WINAPI CDateTime::~CDateTime() {
}

CString CDateTime::date(WCHAR* format) {
    SYSTEMTIME st;
    GetLocalTime(&st);
    
    CString retval = format;
    if (retval.strpos(L"ms") != -1) {
        retval.replace(L"ms", CString(st.wMilliseconds, FALSE, 2));
    }
    if (retval.strpos(L"H") != -1) {
        retval.replace(L"H", CString(st.wHour, FALSE, 2));
    }
    if (retval.strpos(L"i") != -1) {
        retval.replace(L"i", CString(st.wMinute, FALSE, 2));
    }
    if (retval.strpos(L"s") != -1) {
        retval.replace(L"s", CString(st.wSecond, FALSE, 2));
    }
    if (retval.strpos(L"Y") != -1) {
        retval.replace(L"Y", CString(st.wYear, FALSE, 4));
    }
    if (retval.strpos(L"m") != -1) {
        retval.replace(L"m", CString(st.wMonth, FALSE, 2));
    }
    if (retval.strpos(L"d") != -1) {
        retval.replace(L"d", CString(st.wDay, FALSE, 2));
    }

    return retval;
}
