samg-timetrap 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -11
- data/VERSION.yml +2 -2
- data/lib/timetrap/cli.rb +27 -27
- data/lib/timetrap/formatters/ical.rb +1 -0
- data/lib/timetrap/helpers.rb +14 -0
- data/spec/timetrap_spec.rb +39 -9
- metadata +2 -2
data/README.md
CHANGED
@@ -57,7 +57,7 @@ ago"`` creates a new period in the current timesheet, and annotates it with the
|
|
57
57
|
description "document timetrap". The optional ``--at`` flag can be passed to start
|
58
58
|
the entry at a time other than the present. The ``--at`` flag is able to parse
|
59
59
|
natural language times (via Chronic: http://chronic.rubyforge.org/) and will
|
60
|
-
understand 'friday 13:00', 'mon 2:35', '4pm', etc. (also true of the ``
|
60
|
+
understand 'friday 13:00', 'mon 2:35', '4pm', etc. (also true of the ``edit``
|
61
61
|
command's ``--start`` and ``--end`` flags.) Note that this command would be in
|
62
62
|
error if the ``writing`` timesheet was already active. Finally, ``t out``
|
63
63
|
records the current time as the end time for the most recent period in the
|
@@ -74,7 +74,7 @@ To display the current timesheet, invoke the ``t display`` command::
|
|
74
74
|
22:37:38 - 23:38:43 1:01:05 work on kill
|
75
75
|
2:18:52
|
76
76
|
Tue Apr 14, 2009 00:41:16 - 01:40:19 0:59:03 gem packaging
|
77
|
-
10:20:00 - 10:48:10 0:28:10 enhance
|
77
|
+
10:20:00 - 10:48:10 0:28:10 enhance edit
|
78
78
|
1:27:13
|
79
79
|
---------------------------------------------------------
|
80
80
|
Total 3:46:05
|
@@ -87,13 +87,9 @@ last row, the total time tracked in the timesheet is shown.
|
|
87
87
|
|
88
88
|
Commands
|
89
89
|
--------
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
start or end times. Defaults to the current time although an ``--id`` flag can
|
94
|
-
be passed with the entry's id (see display.)
|
95
|
-
|
96
|
-
usage: ``t alter [--id ID] [--start TIME] [--end TIME] [NOTES]``
|
90
|
+
**archives**
|
91
|
+
Archives the selected entries (by moving them to a sheet called _<SHEET>)
|
92
|
+
usage: ``t archive [--start DATE] [--end DATE] [SHEET]``
|
97
93
|
|
98
94
|
**backend**
|
99
95
|
Run an interactive database session on the timetrap database. Requires the
|
@@ -105,7 +101,7 @@ Commands
|
|
105
101
|
Display a given timesheet. If no timesheet is specified, show the current
|
106
102
|
timesheet. If ``all`` is passed as SHEET display all timesheets. Accepts
|
107
103
|
an optional ``--ids`` flag which will include the entries' ids in the output.
|
108
|
-
This is useful when editing an non running entry with ``
|
104
|
+
This is useful when editing an non running entry with ``edit``.
|
109
105
|
|
110
106
|
Display is designed to support a variety of export formats that can be
|
111
107
|
specified by passing the ``--format`` flag. This currently defaults to
|
@@ -113,13 +109,20 @@ Commands
|
|
113
109
|
|
114
110
|
usage: ``t display [--ids] [--start DATE] [--end DATE] [--format FMT] [SHEET | all]``
|
115
111
|
|
112
|
+
**edit**
|
113
|
+
Inserts a note associated with the an entry in the timesheet, or edits the
|
114
|
+
start or end times. Defaults to the current time although an ``--id`` flag can
|
115
|
+
be passed with the entry's id (see display.)
|
116
|
+
|
117
|
+
usage: ``t edit [--id ID] [--start TIME] [--end TIME] [NOTES]``
|
118
|
+
|
116
119
|
**format**
|
117
120
|
Alias for display
|
118
121
|
|
119
122
|
**in**
|
120
123
|
Start the timer for the current timesheet. Must be called before out. Notes
|
121
124
|
may be specified for this period. This is exactly equivalent to
|
122
|
-
``t in; t
|
125
|
+
``t in; t edit NOTES``. Accepts an optional --at flag.
|
123
126
|
|
124
127
|
usage: ``t in [--at TIME] [NOTES]``
|
125
128
|
|
data/VERSION.yml
CHANGED
data/lib/timetrap/cli.rb
CHANGED
@@ -11,21 +11,26 @@ Timetrap - Simple Time Tracking
|
|
11
11
|
Usage: #{File.basename $0} COMMAND [OPTIONS] [ARGS...]
|
12
12
|
|
13
13
|
where COMMAND is one of:
|
14
|
-
*
|
15
|
-
|
16
|
-
|
17
|
-
-s, --start <
|
18
|
-
-e, --end <
|
14
|
+
* archive - move entries to a hidden sheet (by default named '_<SHEET>') so
|
15
|
+
they're out of the way.
|
16
|
+
usage: t archive [--start DATE] [--end DATE] [SHEET]
|
17
|
+
-s, --start <date:qs> Include entries that start on this date or later
|
18
|
+
-e, --end <date:qs> Include entries that start on this date or earlier
|
19
19
|
* backend - open an sqlite shell to the database
|
20
20
|
usage: t backend
|
21
21
|
* display - display the current timesheet or a specific. Pass `all' as
|
22
22
|
SHEET to display all sheets.
|
23
23
|
usage: t display [--ids] [--start DATE] [--end DATE] [--format FMT] [SHEET | all]
|
24
|
-
-v, --ids Print database ids (for use with
|
24
|
+
-v, --ids Print database ids (for use with edit)
|
25
25
|
-s, --start <date:qs> Include entries that start on this date or later
|
26
26
|
-e, --end <date:qs> Include entries that start on this date or earlier
|
27
27
|
-f, --format <format> The output format. Currently supports ical and
|
28
28
|
text (default).
|
29
|
+
* edit - alter an entry's note, start, or end time. Defaults to the active entry
|
30
|
+
usage: t edit [--id ID] [--start TIME] [--end TIME] [NOTES]
|
31
|
+
-i, --id <id:i> Alter entry with id <id> instead of the running entry
|
32
|
+
-s, --start <time:qs> Change the start time to <time>
|
33
|
+
-e, --end <time:qs> Change the end time to <time>
|
29
34
|
* format - alias for display
|
30
35
|
* in - start the timer for the current timesheet
|
31
36
|
usage: t in [--at TIME] [NOTES]
|
@@ -75,7 +80,20 @@ where COMMAND is one of:
|
|
75
80
|
else; say "Ambigous command: #{command}"; end
|
76
81
|
end
|
77
82
|
|
78
|
-
def
|
83
|
+
def archive
|
84
|
+
ee = selected_entries
|
85
|
+
out = "Archive #{ee.count} entries? "
|
86
|
+
print out
|
87
|
+
if $stdin.gets =~ /\Aye?s?\Z/i
|
88
|
+
ee.all.each do |e|
|
89
|
+
e.update :sheet => "_#{e.sheet}"
|
90
|
+
end
|
91
|
+
else
|
92
|
+
say "archive aborted!"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def edit
|
79
97
|
entry = args['-i'] ? Entry[args['-i']] : Timetrap.active_entry
|
80
98
|
say "can't find entry" && return unless entry
|
81
99
|
entry.update :start => args['-s'] if args['-s'] =~ /.+/
|
@@ -132,16 +150,7 @@ where COMMAND is one of:
|
|
132
150
|
say "Invalid format specified `#{args['-f']}'"
|
133
151
|
return
|
134
152
|
end
|
135
|
-
|
136
|
-
Timetrap::Entry
|
137
|
-
elsif sheet =~ /.+/
|
138
|
-
Timetrap::Entry.filter(:sheet => sheet)
|
139
|
-
else
|
140
|
-
Timetrap::Entry.filter(:sheet => Timetrap.current_sheet)
|
141
|
-
end
|
142
|
-
ee = ee.filter(:start >= Date.parse(args['-s'])) if args['-s']
|
143
|
-
ee = ee.filter(:start <= Date.parse(args['-e']) + 1) if args['-e']
|
144
|
-
say Timetrap.format(fmt_klass, ee.order(:start).all)
|
153
|
+
say Timetrap.format(fmt_klass, selected_entries.order(:start).all)
|
145
154
|
end
|
146
155
|
|
147
156
|
# TODO: Consolidate display and format
|
@@ -152,16 +161,7 @@ where COMMAND is one of:
|
|
152
161
|
say "Invalid format specified `#{args['-f']}'"
|
153
162
|
return
|
154
163
|
end
|
155
|
-
|
156
|
-
Timetrap::Entry
|
157
|
-
elsif sheet =~ /.+/
|
158
|
-
Timetrap::Entry.filter(:sheet => sheet)
|
159
|
-
else
|
160
|
-
Timetrap::Entry.filter(:sheet => Timetrap.current_sheet)
|
161
|
-
end
|
162
|
-
ee = ee.filter(:start >= Date.parse(args['-s'])) if args['-s']
|
163
|
-
ee = ee.filter(:start <= Date.parse(args['-e']) + 1) if args['-e']
|
164
|
-
say Timetrap.format(fmt_klass, ee.all)
|
164
|
+
say Timetrap.format(fmt_klass, selected_entries.order(:start).all)
|
165
165
|
end
|
166
166
|
|
167
167
|
def switch
|
data/lib/timetrap/helpers.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
module Timetrap
|
2
2
|
module Helpers
|
3
|
+
|
4
|
+
def selected_entries
|
5
|
+
ee = if (sheet = sheet_name_from_string(unused_args)) == 'all'
|
6
|
+
Timetrap::Entry.filter('sheet not like ? escape "!"', '!_%')
|
7
|
+
elsif sheet =~ /.+/
|
8
|
+
Timetrap::Entry.filter('sheet = ?', sheet)
|
9
|
+
else
|
10
|
+
Timetrap::Entry.filter('sheet = ?', Timetrap.current_sheet)
|
11
|
+
end
|
12
|
+
ee = ee.filter(:start >= Date.parse(args['-s'])) if args['-s']
|
13
|
+
ee = ee.filter(:start <= Date.parse(args['-e']) + 1) if args['-e']
|
14
|
+
ee
|
15
|
+
end
|
16
|
+
|
3
17
|
def format_time time
|
4
18
|
return '' unless time.respond_to?(:strftime)
|
5
19
|
time.strftime('%H:%M:%S')
|
data/spec/timetrap_spec.rb
CHANGED
@@ -25,35 +25,51 @@ describe Timetrap do
|
|
25
25
|
Timetrap::CLI.invoke
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '
|
28
|
+
describe 'archive' do
|
29
|
+
before do
|
30
|
+
3.times do |i|
|
31
|
+
create_entry
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should put the entries in a hidden sheet" do
|
36
|
+
$stdin.string = "yes\n"
|
37
|
+
invoke 'archive'
|
38
|
+
Timetrap::Entry.each do |e|
|
39
|
+
e.sheet.should == '_default'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'edit' do
|
29
45
|
before do
|
30
46
|
Timetrap.start "running entry", nil
|
31
47
|
end
|
32
48
|
|
33
|
-
it "should
|
49
|
+
it "should edit the description of the active period" do
|
34
50
|
Timetrap.active_entry.note.should == 'running entry'
|
35
|
-
invoke '
|
51
|
+
invoke 'edit new description'
|
36
52
|
Timetrap.active_entry.note.should == 'new description'
|
37
53
|
end
|
38
54
|
|
39
|
-
it "should
|
40
|
-
invoke '
|
55
|
+
it "should edit the start time of the active period" do
|
56
|
+
invoke 'edit --start "yesterday 10am"'
|
41
57
|
Timetrap.active_entry.start.should == Chronic.parse("yesterday 10am")
|
42
58
|
Timetrap.active_entry.note.should == 'running entry'
|
43
59
|
end
|
44
60
|
|
45
|
-
it "should
|
61
|
+
it "should edit the end time of the active period" do
|
46
62
|
entry = Timetrap.active_entry
|
47
|
-
invoke '
|
63
|
+
invoke 'edit --end "yesterday 10am"'
|
48
64
|
entry.refresh.end.should == Chronic.parse("yesterday 10am")
|
49
65
|
entry.refresh.note.should == 'running entry'
|
50
66
|
end
|
51
67
|
|
52
|
-
it "should
|
68
|
+
it "should edit a non running entry based on id" do
|
53
69
|
not_running = Timetrap.active_entry
|
54
70
|
Timetrap.stop
|
55
71
|
Timetrap.start "another entry", nil
|
56
|
-
invoke "
|
72
|
+
invoke "edit --id #{not_running.id} a new description"
|
57
73
|
not_running.refresh.note.should == 'a new description'
|
58
74
|
end
|
59
75
|
end
|
@@ -161,6 +177,14 @@ Grand Total 10:00:00
|
|
161
177
|
invoke 'display all'
|
162
178
|
$stdout.string.should == @desired_output_for_all
|
163
179
|
end
|
180
|
+
|
181
|
+
it "should not display archived for all timesheets" do
|
182
|
+
$stdin.string = "yes\n"
|
183
|
+
invoke 'archive SpecSheet'
|
184
|
+
$stdout.string = ''
|
185
|
+
invoke 'display all'
|
186
|
+
$stdout.string.should_not =~ /_SpecSheet/
|
187
|
+
end
|
164
188
|
end
|
165
189
|
|
166
190
|
describe "format" do
|
@@ -170,6 +194,12 @@ Grand Total 10:00:00
|
|
170
194
|
create_entry(:start => '2008-10-05 12:00:00', :end => '2008-10-05 14:00:00')
|
171
195
|
end
|
172
196
|
|
197
|
+
it "should not export running items" do
|
198
|
+
invoke 'in'
|
199
|
+
invoke 'format --format ical'
|
200
|
+
$stdout.string.scan(/BEGIN:VEVENT/).should have(2).item
|
201
|
+
end
|
202
|
+
|
173
203
|
it "should filter events by the passed dates" do
|
174
204
|
invoke 'format --format ical --start 2008-10-03 --end 2008-10-03'
|
175
205
|
$stdout.string.scan(/BEGIN:VEVENT/).should have(1).item
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samg-timetrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Goldstein
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-10 00:00:00 -07:00
|
13
13
|
default_executable: t
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|