/*************************************************************************** * Copyright (C) 2008 by Daniel Tamney * * danskunk@rogers.com * * * * 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. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include using namespace std; long timestamp(string date) { string strday, strmonth, stryear; long day, month, year, leapdays, timestamp; long monthdaysl[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; long monthdays[] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; bool leapyear; strday = date[0]; strday += date[1]; day = atol(strday.c_str()); strmonth = date[3]; strmonth += date[4]; month = atol(strmonth.c_str()); stryear = date[6]; stryear += date[7]; year = atol(stryear.c_str()); year += 2000; leapdays = (year - 1968) / 4 - (year - 1900) / 100 + (year - 1600) / 400; leapyear = (year % 4) && !(year % 100) || (year % 400); if (leapyear) { leapdays -= 1; timestamp = ((year - 1970) * 365 + monthdaysl[month] + day + leapdays) * 24 * 60 * 60 - 5 * 60 * 60; } else { timestamp = ((year - 1970) * 365 + monthdays[month] + day + leapdays) * 24 * 60 * 60 + 5 * 60 * 60; } return timestamp; } int main(int argc, char *argv[]) { cout << "Datestamp is: "; cout << timestamp(argv[1]); cout << "\n"; }