better durations support (months)

This commit is contained in:
DavidBadura 2015-05-15 11:38:38 +00:00
parent b31a76ef9a
commit 624435017b
3 changed files with 148 additions and 18 deletions

View File

@ -12,7 +12,7 @@ composer require 'davidbadura/taskwarrior'
## Requirements ## Requirements
Task Warrior changes its behavior by patch level updates and it is very difficult to support all versions. Taskwarrior changes its behavior by patch level updates and it is very difficult to support all versions.
That's why I've decided just to support only one version: **2.4.3** That's why I've decided just to support only one version: **2.4.3**
## Usage ## Usage

View File

@ -16,6 +16,8 @@ class Recurring
const WEEKDAYS = 'weekdays'; const WEEKDAYS = 'weekdays';
const WEEKLY = 'weekly'; const WEEKLY = 'weekly';
const BIWEEKLY = 'biweekly'; const BIWEEKLY = 'biweekly';
const MONTHLY = 'monthly';
const BIMONTHLY = 'bimonthly';
const QUARTERLY = 'quarterly'; const QUARTERLY = 'quarterly';
const SEMIANNUAL = 'semiannual'; const SEMIANNUAL = 'semiannual';
const ANNUAL = 'annual'; const ANNUAL = 'annual';
@ -70,19 +72,48 @@ class Recurring
return true; return true;
} }
if (preg_match('/^[0-9]+d$/', $recur)) { // seconds
if (preg_match('/^[0-9]*\s?se?c?o?n?d?s?$/', $recur)) {
return true; return true;
} }
if (preg_match('/^[0-9]+w$/', $recur)) { // minutes
if (preg_match('/^[0-9]*\s?mi?n?u?t?e?s?$/', $recur)) {
return true; return true;
} }
if (preg_match('/^[0-9]+q$/', $recur)) { // hours
if (preg_match('/^[0-9]*\s?ho?u?r?s?$/', $recur)) {
return true; return true;
} }
if (preg_match('/^[0-9]+y$/', $recur)) { // days
if (preg_match('/^[0-9]*\s?da?y?s?$/', $recur)) {
return true;
}
// weeks
if (preg_match('/^[0-9]*\s?we?e?k?s?$/', $recur)) {
return true;
}
// months
if (preg_match('/^[0-9]*\s?mo?n?t?h?s?$/', $recur)) {
return true;
}
// quarters
if (preg_match('/^[0-9]*\s?qu?a?r?t?e?r?(s|ly)?/', $recur)) {
return true;
}
// years
if (preg_match('/^[0-9]*\s?ye?a?r?s?$/', $recur)) {
return true;
}
// fortnight | sennight
if (preg_match('/^[0-9]*\s?(fortnight|sennight)$/', $recur)) {
return true; return true;
} }

View File

@ -10,29 +10,129 @@ use DavidBadura\Taskwarrior\Recurring;
class RecurringTest extends \PHPUnit_Framework_TestCase class RecurringTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @see http://taskwarrior.org/docs/durations.html
* @return array * @return array
*/ */
public function validData() public function validData()
{ {
return [ return [
['5 seconds'],
['5 second'],
['5 secs'],
['5 sec'],
['5 s'],
['5seconds'],
['5second'],
['5secs'],
['5sec'],
['5s'],
['second'],
['sec'],
['5 minutes'],
['5 minute'],
['5 mins'],
['5 min'],
['5minutes'],
['5minute'],
['5mins'],
['5min'],
['minute'],
['min'],
['3 hours'],
['3 hour'],
['3 hrs'],
['3 hr'],
['3 h'],
['3hours'],
['3hour'],
['3hrs'],
['3hr'],
['3h'],
['hour'],
['hr'],
['2 days'],
['2 day'],
['2 d'],
['2days'],
['2day'],
['2d'],
['daily'], ['daily'],
['weekdays'], ['day'],
['3 weeks'],
['3 week'],
['3 wks'],
['3 wk'],
['3 w'],
['3weeks'],
['3week'],
['3wks'],
['3wk'],
['3w'],
['weekly'], ['weekly'],
['week'],
['wk'],
['weekdays'],
['2 fortnight'],
['2 sennight'],
['2fortnight'],
['2sennight'],
['biweekly'], ['biweekly'],
['fortnight'],
['sennight'],
['5 months'],
['5 month'],
['5 mnths'],
['5 mths'],
['5 mth'],
['5 mo'],
['5 m'],
['5months'],
['5month'],
['5mnths'],
['5mths'],
['5mth'],
['5mo'],
['5m'],
['monthly'],
['month'],
['mth'],
['mo'],
['bimonthly'],
['1 quarterly'],
['1 quarters'],
['1 quarter'],
['1 qrtrs'],
['1 qrtr'],
['1 qtr'],
['1 q'],
['1quarterly'],
['1quarters'],
['1quarter'],
['1qrtrs'],
['1qrtr'],
['1qtr'],
['1q'],
['quarterly'], ['quarterly'],
['quarter'],
['qrtr'],
['qtr'],
['semiannual'], ['semiannual'],
['1 years'],
['1 year'],
['1 yrs'],
['1 yr'],
['1 y'],
['1years'],
['1year'],
['1yrs'],
['1yr'],
['1y'],
['annual'], ['annual'],
['yearly'], ['yearly'],
['year'],
['yr'],
['biannual'], ['biannual'],
['biyearly'], ['biyearly']
['2d'],
['12d'],
['2w'],
['12w'],
['2q'],
['12q'],
['2y'],
['12y']
]; ];
} }
@ -56,8 +156,7 @@ class RecurringTest extends \PHPUnit_Framework_TestCase
['foo'], ['foo'],
['weekday'], ['weekday'],
['2x'], ['2x'],
['a2w'], ['a2w']
['d']
]; ];
} }
@ -69,6 +168,6 @@ class RecurringTest extends \PHPUnit_Framework_TestCase
{ {
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\RecurringParseException'); $this->setExpectedException('DavidBadura\Taskwarrior\Exception\RecurringParseException');
$obj = new Recurring($recur); new Recurring($recur);
} }
} }