Skip to content
Browse files

accept today-n for date strings

  • Loading branch information...
1 parent 399c9e3 commit 63f2143e06b9aafaa17f7d42b9e56281bf8eb563 @ianxm committed Mar 24, 2012
Showing with 30 additions and 7 deletions.
  1. +1 −0 README.markdown
  2. +29 −7 src/tracker/Main.hx
View
1 README.markdown
@@ -351,3 +351,4 @@ DATE:
YYYY-MM-DD specify a date
today specify day is today (default)
yesterday specify day is yesterday
+ today-N specify day is N days before today
View
36 src/tracker/Main.hx
@@ -18,6 +18,7 @@
package tracker;
using Lambda;
+using StringTools;
import neko.Lib;
import neko.Sys;
import neko.FileSystem;
@@ -121,13 +122,6 @@ class Main
case "-d": // date range
{
arg = args.shift();
- var dateFix = function(ii) {
- return switch(ii){
- case "today": Utils.today();
- case "yesterday": { var day = Utils.today(); day.day-=1; day; }
- default: Utils.dayFromString(ii);
- }
- }
if( arg.indexOf("..")!=-1 )
range = arg.split("..").map(dateFix).array();
else
@@ -206,6 +200,33 @@ class Main
}
}
+ // parse date strings
+ // accept yyyy-mm-dd or yesterday or today[-N]
+ private function dateFix(dateStr :String)
+ {
+ return if( dateStr.startsWith("yest") )
+ {
+ var day = Utils.today();
+ day.day -= 1;
+ day;
+ }
+ else if( dateStr.startsWith("tod") )
+ {
+ var day = Utils.today();
+ var fields = dateStr.split("-");
+ try {
+ if( fields.length == 2 )
+ day.day -= Std.parseInt(fields[1]);
+ } catch( e:String ) {
+ throw "offset from today must be an integer";
+ }
+ day;
+ }
+ else
+ Utils.dayFromString(dateStr);
+ }
+
+
// set defaults after args have been processed
private function setDefaults()
{
@@ -328,6 +349,7 @@ DATE:
YYYY-MM-DD specify a date
today specify day is today (default)
yesterday specify day is yesterday
+ today-N specify day is N days before today
examples:
> tracker init

0 comments on commit 63f2143

Please sign in to comment.
Something went wrong with that request. Please try again.