/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : date.c Component : date Fonctionality : contains methods for object Date ******************************************************************/ #include "date.h" #include #include Date::Date () { set (); } Date::~Date () { } void Date::set () { currentTimeT = time (0); currentTime = localtime (¤tTimeT); year = currentTime->tm_year ; month = currentTime->tm_mon+1 ; day = currentTime->tm_mday ; hour = currentTime->tm_hour ; min = currentTime->tm_min ; sec = currentTime->tm_sec ; } char* Date::getDate () { if (month > 9) { if (day > 9) { sprintf (dateC, "%d/%d/19%d", day, month, year); } else { sprintf (dateC, "0%d/%d/19%d", day, month, year); } } else { if (day > 9) { sprintf (dateC, "%d/0%d/19%d", day, month, year); } else { sprintf (dateC, "0%d/0%d/19%d", day, month, year); } } return dateC; } char* Date::getTime () { if (min > 9) { if (sec > 9) { sprintf (timeC, "%d:%d:%d", hour, min, sec); } else { sprintf (timeC, "%d:%d:0%d", hour, min, sec); } } else { if (sec > 9) { sprintf (timeC, "%d:0%d:%d", hour, min, sec); } else { sprintf (timeC, "%d:0%d:0%d", hour, min, sec); } } return timeC; } tm* Date::get () { return currentTime; } int Date::compare (Date aDate) { if (year < aDate.year) { return -1; } else if (year > aDate.year) { return 1; } else if (month < aDate.month) { return -1; } else if (month > aDate.month) { return 1; } else if (day < aDate.day) { return -1; } else if (day > aDate.day) { return 1; } else if (hour < aDate.hour) { return -1; } else if (hour > aDate.hour) { return 1; } else if (min < aDate.min) { return -1; } else if (min > aDate.min) { return 1; } else if (sec < aDate.sec) { return -1; } else if (sec > aDate.sec) { return 1; } else return 0; } void Date::addMin (int minVar) { min += minVar; if (min > 60) { hour += (int)(min/60); min = min%60; } } void Date::addSec (int secVar) { sec += secVar; if (sec > 60) { min += (int)(sec/60); sec = sec%60; } } void Date::setWithDate (Date aDate) { year = aDate.year ; month = aDate.month ; day = aDate.day ; hour = aDate.hour ; min = aDate.min ; sec = aDate.sec ; }