From e8fc210ab0d52155fbe9d2c9fc0477f5c0a7e997 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 18 Jul 2009 00:49:04 -0400 Subject: [PATCH] Bug Fix - #206 - Fixed bug that prevented "task list start.after:1/1/2009" from working. Big, nasty bug. --- src/Att.cpp | 4 +- src/Date.cpp | 21 ++++++++- src/Date.h | 1 + src/tests/bug.before.t | 97 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 4 deletions(-) create mode 100755 src/tests/bug.before.t diff --git a/src/Att.cpp b/src/Att.cpp index 701140551..6aa09a556 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -557,7 +557,7 @@ bool Att::match (const Att& other) const } else if (which == "date") { - Date literal ((time_t)::atoi (mValue.c_str ())); + Date literal (mValue.c_str (), context.config.get ("dateformat", "m/d/Y")); Date variable ((time_t)::atoi (other.mValue.c_str ())); if (other.mValue == "" || ! (variable < literal)) return false; @@ -587,7 +587,7 @@ bool Att::match (const Att& other) const } else if (which == "date") { - Date literal ((time_t)::atoi (mValue.c_str ())); + Date literal (mValue.c_str (), context.config.get ("dateformat", "m/d/Y")); Date variable ((time_t)::atoi (other.mValue.c_str ())); if (! (variable > literal)) return false; diff --git a/src/Date.cpp b/src/Date.cpp index 6ac654976..1d7692ced 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -65,6 +65,10 @@ Date::Date (const std::string& mdy, const std::string& format /* = "m/d/Y" */) int day = 0; int year = 0; + // Perhaps it is an epoch date, in string form? + if (isEpoch (mdy)) + return; + // Before parsing according to "format", perhaps this is a relative date? if (isRelativeDate (mdy)) return; @@ -83,8 +87,8 @@ Date::Date (const std::string& mdy, const std::string& format /* = "m/d/Y" */) throw std::string ("\"") + mdy + "\" is not a valid date."; } - if (i + 1 < mdy.length () && - (mdy[i + 0] == '0' || mdy[i + 0] == '1') && + if (i + 1 < mdy.length () && + (mdy[i + 0] == '0' || mdy[i + 0] == '1') && ::isdigit (mdy[i + 1])) { month = ::atoi (mdy.substr (i, 2).c_str ()); @@ -543,6 +547,19 @@ time_t Date::operator- (const Date& rhs) return mT - rhs.mT; } +//////////////////////////////////////////////////////////////////////////////// +bool Date::isEpoch (const std::string& input) +{ + if (digitsOnly (input) && + input.length () > 8) + { + mT = (time_t) ::atoi (input.c_str ()); + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // If the input string looks like a relative date, determine that date, set mT // and return true. diff --git a/src/Date.h b/src/Date.h index 2f4bed1a8..212df458f 100644 --- a/src/Date.h +++ b/src/Date.h @@ -81,6 +81,7 @@ public: time_t operator- (const Date&); private: + bool isEpoch (const std::string&); bool isRelativeDate (const std::string&); protected: diff --git a/src/tests/bug.before.t b/src/tests/bug.before.t new file mode 100755 index 000000000..a6928ce2b --- /dev/null +++ b/src/tests/bug.before.t @@ -0,0 +1,97 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, Paul Beckingham. +## All rights reserved. +## +## 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., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 20; + +# Create the rc file. +if (open my $fh, '>', 'before.rc') +{ + print $fh "data.location=.\n", + "confirmation=no\n", + "dateformat=m/d/Y\n"; + close $fh; + ok (-r 'before.rc', 'Created before.rc'); +} + +# Create some exampel data directly. +if (open my $fh, '>', 'pending.data') +{ + # 1230000000 = 12/22/2008 + # 1240000000 = 4/17/2009 + print $fh <