samg-timetrap 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -3
- data/bin/t +9 -1
- data/lib/timetrap/cli.rb +54 -37
- data/lib/timetrap/helpers.rb +1 -0
- data/lib/timetrap/models.rb +4 -0
- data/spec/timetrap_spec.rb +72 -30
- metadata +1 -1
data/README.md
CHANGED
@@ -101,9 +101,9 @@ Commands
|
|
101
101
|
|
102
102
|
**display**
|
103
103
|
Display a given timesheet. If no timesheet is specified, show the current
|
104
|
-
timesheet.
|
105
|
-
|
106
|
-
``alter``.
|
104
|
+
timesheet. If ``all`` is passed as timesheet display all timesheets. Accepts
|
105
|
+
an optional ``--ids`` flag which will include the entries' ids in the output.
|
106
|
+
This is useful when editing an non running entry with ``alter``.
|
107
107
|
|
108
108
|
usage: ``t display [--ids] [--start DATE] [--end DATE] [TIMESHEET]``
|
109
109
|
|
data/bin/t
CHANGED
@@ -1,3 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
begin
|
3
|
+
require 'timetrap'
|
4
|
+
rescue LoadError
|
5
|
+
if File.symlink? __FILE__
|
6
|
+
require File.dirname(File.readlink(__FILE__)) + '/../lib/timetrap'
|
7
|
+
else
|
8
|
+
require File.dirname(__FILE__) + '/../lib/timetrap'
|
9
|
+
end
|
10
|
+
end
|
3
11
|
Timetrap::CLI.invoke
|
data/lib/timetrap/cli.rb
CHANGED
@@ -18,8 +18,9 @@ where COMMAND is one of:
|
|
18
18
|
-e, --end <time:qs> Change the end time to <time>
|
19
19
|
* backend - open an sqlite shell to the database
|
20
20
|
usage: t backend
|
21
|
-
* display - display the current timesheet
|
22
|
-
|
21
|
+
* display - display the current timesheet or a specific. Pass `all' as
|
22
|
+
timesheet to display all sheets.
|
23
|
+
usage: t display [--ids] [--start DATE] [--end DATE] [TIMESHEET | all ]
|
23
24
|
-v, --ids Print database ids (for use with alter)
|
24
25
|
-s, --start <date:qs> Include entries that start on this date or later
|
25
26
|
-e, --end <date:qs> Include entries that start on this date or earlier
|
@@ -121,42 +122,58 @@ where COMMAND is one of:
|
|
121
122
|
end
|
122
123
|
|
123
124
|
def display
|
124
|
-
sheet = sheet_name_from_string(unused_args)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
from_current_day = []
|
131
|
-
ee = Timetrap::Entry.filter(:sheet => sheet).order(:start)
|
132
|
-
ee = ee.filter(:start >= Date.parse(args['-s'])) if args['-s']
|
133
|
-
ee = ee.filter(:start <= Date.parse(args['-e']) + 1) if args['-e']
|
134
|
-
ee.each_with_index do |e, i|
|
135
|
-
|
136
|
-
|
137
|
-
from_current_day << e
|
138
|
-
e_end = e.end || Time.now
|
139
|
-
say "%-4s%16s%11s -%9s%10s %s" % [
|
140
|
-
(args['-v'] ? e.id : ''),
|
141
|
-
format_date_if_new(e.start, last_start),
|
142
|
-
format_time(e.start),
|
143
|
-
format_time(e.end),
|
144
|
-
format_duration(e.start, e_end),
|
145
|
-
e.note
|
146
|
-
]
|
147
|
-
|
148
|
-
nxt = ee.map[i+1]
|
149
|
-
if nxt == nil or !same_day?(e.start, nxt.start)
|
150
|
-
say "%52s" % format_total(from_current_day)
|
151
|
-
from_current_day = []
|
152
|
-
else
|
153
|
-
end
|
154
|
-
last_start = e.start
|
125
|
+
sheets = if (sheet = sheet_name_from_string(unused_args)) == 'all'
|
126
|
+
Timetrap::Entry.sheets
|
127
|
+
elsif sheet =~ /.+/
|
128
|
+
[sheet]
|
129
|
+
else
|
130
|
+
[Timetrap.current_sheet]
|
155
131
|
end
|
156
|
-
|
132
|
+
entries = []
|
133
|
+
sheets.each do |sheet|
|
134
|
+
say "Timesheet: #{sheet}"
|
135
|
+
id_heading = args['-v'] ? 'Id' : ' '
|
136
|
+
say "#{id_heading} Day Start End Duration Notes"
|
137
|
+
last_start = nil
|
138
|
+
from_current_day = []
|
139
|
+
ee = Timetrap::Entry.filter(:sheet => sheet).order(:start)
|
140
|
+
ee = ee.filter(:start >= Date.parse(args['-s'])) if args['-s']
|
141
|
+
ee = ee.filter(:start <= Date.parse(args['-e']) + 1) if args['-e']
|
142
|
+
entries += ee.all
|
143
|
+
ee.each_with_index do |e, i|
|
144
|
+
|
145
|
+
|
146
|
+
from_current_day << e
|
147
|
+
e_end = e.end || Time.now
|
148
|
+
say "%-4s%16s%11s -%9s%10s %s" % [
|
149
|
+
(args['-v'] ? e.id : ''),
|
150
|
+
format_date_if_new(e.start, last_start),
|
151
|
+
format_time(e.start),
|
152
|
+
format_time(e.end),
|
153
|
+
format_duration(e.start, e_end),
|
154
|
+
e.note
|
155
|
+
]
|
156
|
+
|
157
|
+
nxt = ee.map[i+1]
|
158
|
+
if nxt == nil or !same_day?(e.start, nxt.start)
|
159
|
+
say "%52s" % format_total(from_current_day)
|
160
|
+
from_current_day = []
|
161
|
+
else
|
162
|
+
end
|
163
|
+
last_start = e.start
|
164
|
+
end
|
165
|
+
say <<-OUT
|
157
166
|
---------------------------------------------------------
|
158
|
-
|
159
|
-
|
167
|
+
OUT
|
168
|
+
say " Total%43s" % format_total(ee)
|
169
|
+
say "\n" unless sheet == sheets.last
|
170
|
+
end
|
171
|
+
if sheets.size > 1
|
172
|
+
say <<-OUT
|
173
|
+
-------------------------------------------------------------
|
174
|
+
OUT
|
175
|
+
say "Grand Total%41s" % format_total(entries)
|
176
|
+
end
|
160
177
|
end
|
161
178
|
|
162
179
|
# TODO: Consolidate display and format
|
@@ -180,7 +197,7 @@ where COMMAND is one of:
|
|
180
197
|
end
|
181
198
|
|
182
199
|
def list
|
183
|
-
sheets = Entry.
|
200
|
+
sheets = Entry.sheets.map do |sheet|
|
184
201
|
sheet_atts = {:total => 0, :running => 0, :today => 0}
|
185
202
|
DB[:entries].filter(:sheet => sheet).inject(sheet_atts) do |m, e|
|
186
203
|
e_end = e[:end] || Time.now
|
data/lib/timetrap/helpers.rb
CHANGED
data/lib/timetrap/models.rb
CHANGED
data/spec/timetrap_spec.rb
CHANGED
@@ -109,6 +109,28 @@ Id Day Start End Duration Notes
|
|
109
109
|
---------------------------------------------------------
|
110
110
|
Total 8:00:00
|
111
111
|
OUTPUT
|
112
|
+
|
113
|
+
@desired_output_for_all = <<-OUTPUT
|
114
|
+
Timesheet: SpecSheet
|
115
|
+
Day Start End Duration Notes
|
116
|
+
Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
|
117
|
+
16:00:00 - 18:00:00 2:00:00 entry 2
|
118
|
+
4:00:00
|
119
|
+
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
|
120
|
+
18:00:00 - 2:00:00 entry 4
|
121
|
+
4:00:00
|
122
|
+
---------------------------------------------------------
|
123
|
+
Total 8:00:00
|
124
|
+
|
125
|
+
Timesheet: another
|
126
|
+
Day Start End Duration Notes
|
127
|
+
Sun Oct 05, 2008 18:00:00 - 2:00:00 entry 4
|
128
|
+
2:00:00
|
129
|
+
---------------------------------------------------------
|
130
|
+
Total 2:00:00
|
131
|
+
-------------------------------------------------------------
|
132
|
+
Grand Total 10:00:00
|
133
|
+
OUTPUT
|
112
134
|
end
|
113
135
|
|
114
136
|
it "should display the current timesheet" do
|
@@ -133,6 +155,12 @@ Id Day Start End Duration Notes
|
|
133
155
|
invoke 'display S --ids'
|
134
156
|
$stdout.string.should == @desired_output_with_ids
|
135
157
|
end
|
158
|
+
|
159
|
+
it "should display all timesheets" do
|
160
|
+
Timetrap.current_sheet = 'another'
|
161
|
+
invoke 'display all'
|
162
|
+
$stdout.string.should == @desired_output_for_all
|
163
|
+
end
|
136
164
|
end
|
137
165
|
|
138
166
|
describe "format" do
|
@@ -419,44 +447,58 @@ current sheet: 0:01:00 (a timesheet that is running)
|
|
419
447
|
end
|
420
448
|
|
421
449
|
describe Timetrap::Entry do
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
describe 'attributes' do
|
428
|
-
it "should have a note" do
|
429
|
-
@entry.note = "world takeover"
|
430
|
-
@entry.note.should == "world takeover"
|
450
|
+
describe "with an instance" do
|
451
|
+
before do
|
452
|
+
@time = Time.now
|
453
|
+
@entry = Timetrap::Entry.new
|
431
454
|
end
|
432
455
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
456
|
+
describe 'attributes' do
|
457
|
+
it "should have a note" do
|
458
|
+
@entry.note = "world takeover"
|
459
|
+
@entry.note.should == "world takeover"
|
460
|
+
end
|
437
461
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
462
|
+
it "should have a start" do
|
463
|
+
@entry.start = @time
|
464
|
+
@entry.start.should == @time
|
465
|
+
end
|
442
466
|
|
443
|
-
|
444
|
-
|
445
|
-
|
467
|
+
it "should have a end" do
|
468
|
+
@entry.end = @time
|
469
|
+
@entry.end.should == @time
|
470
|
+
end
|
471
|
+
|
472
|
+
it "should have a sheet" do
|
473
|
+
@entry.sheet= 'name'
|
474
|
+
@entry.sheet.should == 'name'
|
475
|
+
end
|
446
476
|
end
|
447
|
-
end
|
448
477
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
478
|
+
describe "parsing natural language times" do
|
479
|
+
it "should set start time using english" do
|
480
|
+
@entry.start = "yesterday 10am"
|
481
|
+
@entry.start.should_not be_nil
|
482
|
+
@entry.start.should == Chronic.parse("yesterday 10am")
|
483
|
+
end
|
484
|
+
|
485
|
+
it "should set end time using english" do
|
486
|
+
@entry.end = "tomorrow 1pm"
|
487
|
+
@entry.end.should_not be_nil
|
488
|
+
@entry.end.should == Chronic.parse("tomorrow 1pm")
|
489
|
+
end
|
454
490
|
end
|
491
|
+
end
|
455
492
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
493
|
+
describe '::sheets' do
|
494
|
+
it "should output a list of all the available sheets" do
|
495
|
+
Timetrap::Entry.create( :sheet => 'another',
|
496
|
+
:note => 'entry 4', :start => '2008-10-05 18:00:00'
|
497
|
+
)
|
498
|
+
Timetrap::Entry.create( :sheet => 'SpecSheet',
|
499
|
+
:note => 'entry 2', :start => '2008-10-03 16:00:00', :end => '2008-10-03 18:00:00'
|
500
|
+
)
|
501
|
+
Timetrap::Entry.sheets.should == %w(another SpecSheet).sort
|
460
502
|
end
|
461
503
|
end
|
462
504
|
end
|