Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
better durations support (months)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed May 15, 2015
1 parent b31a76e commit 6244350
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ composer require 'davidbadura/taskwarrior'

## 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**

## Usage
Expand Down
39 changes: 35 additions & 4 deletions src/Recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Recurring
const WEEKDAYS = 'weekdays';
const WEEKLY = 'weekly';
const BIWEEKLY = 'biweekly';
const MONTHLY = 'monthly';
const BIMONTHLY = 'bimonthly';
const QUARTERLY = 'quarterly';
const SEMIANNUAL = 'semiannual';
const ANNUAL = 'annual';
Expand Down Expand Up @@ -70,19 +72,48 @@ public static function isValid($recur)
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;
}

if (preg_match('/^[0-9]+w$/', $recur)) {
// minutes
if (preg_match('/^[0-9]*\s?mi?n?u?t?e?s?$/', $recur)) {
return true;
}

if (preg_match('/^[0-9]+q$/', $recur)) {
// hours
if (preg_match('/^[0-9]*\s?ho?u?r?s?$/', $recur)) {
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;
}

Expand Down
125 changes: 112 additions & 13 deletions tests/RecurringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,129 @@
class RecurringTest extends \PHPUnit_Framework_TestCase
{
/**
* @see http://taskwarrior.org/docs/durations.html
* @return array
*/
public function validData()
{
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'],
['weekdays'],
['day'],
['3 weeks'],
['3 week'],
['3 wks'],
['3 wk'],
['3 w'],
['3weeks'],
['3week'],
['3wks'],
['3wk'],
['3w'],
['weekly'],
['week'],
['wk'],
['weekdays'],
['2 fortnight'],
['2 sennight'],
['2fortnight'],
['2sennight'],
['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'],
['quarter'],
['qrtr'],
['qtr'],
['semiannual'],
['1 years'],
['1 year'],
['1 yrs'],
['1 yr'],
['1 y'],
['1years'],
['1year'],
['1yrs'],
['1yr'],
['1y'],
['annual'],
['yearly'],
['year'],
['yr'],
['biannual'],
['biyearly'],
['2d'],
['12d'],
['2w'],
['12w'],
['2q'],
['12q'],
['2y'],
['12y']
['biyearly']
];
}

Expand All @@ -56,8 +156,7 @@ public function invalidData()
['foo'],
['weekday'],
['2x'],
['a2w'],
['d']
['a2w']
];
}

Expand All @@ -69,6 +168,6 @@ public function testInvalid($recur)
{
$this->setExpectedException('DavidBadura\Taskwarrior\Exception\RecurringParseException');

$obj = new Recurring($recur);
new Recurring($recur);
}
}

0 comments on commit 6244350

Please sign in to comment.