src/ai/api/ai_date.cpp
author truebrain
Wed, 23 Apr 2008 12:05:32 +0000
branchnoai
changeset 10308 0c81dfce3e9b
parent 9833 89a64246458f
permissions -rw-r--r--
(svn r12849) [NoAI] -Fix: when .hpp.sq doesn't exists, don't run diff (tnx to Yexo)
9825
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     1
/* $Id$ */
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     2
9833
89a64246458f (svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents: 9825
diff changeset
     3
/** @file ai_date.cpp Implementation of AIDate. */
9825
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     4
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     5
#include "ai_date.hpp"
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     6
#include "../../date_func.h"
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     7
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     8
/* static */ int32 AIDate::GetCurrentDate()
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
     9
{
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    10
	return ::_date;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    11
}
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    12
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    13
/* static */ int32 AIDate::GetYear(int32 date)
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    14
{
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    15
	if (date < 0) return -1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    16
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    17
	::YearMonthDay ymd;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    18
	::ConvertDateToYMD(date, &ymd);
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    19
	return ymd.year;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    20
}
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    21
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    22
/* static */ int32 AIDate::GetMonth(int32 date)
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    23
{
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    24
	if (date < 0) return -1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    25
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    26
	::YearMonthDay ymd;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    27
	::ConvertDateToYMD(date, &ymd);
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    28
	return ymd.month + 1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    29
}
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    30
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    31
/* static */ int32 AIDate::GetDayOfMonth(int32 date)
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    32
{
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    33
	if (date < 0) return -1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    34
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    35
	::YearMonthDay ymd;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    36
	::ConvertDateToYMD(date, &ymd);
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    37
	return ymd.day;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    38
}
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    39
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    40
/* static */ int32 AIDate::GetDate(int32 year, int32 month, int32 day_of_month)
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    41
{
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    42
	if (month < 1 || month > 12) return -1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    43
	if (day_of_month < 1 || day_of_month > 31) return -1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    44
	if (year < 1 || year > MAX_YEAR) return -1;
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    45
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    46
	return ::ConvertYMDToDate(year, month - 1, day_of_month);
cc77111ebd85 (svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
rubidium
parents:
diff changeset
    47
}