samg-timetrap 0.0.4 → 0.0.5
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 +37 -27
- data/lib/timetrap.rb +27 -17
- data/spec/timetrap_spec.rb +28 -18
- metadata +1 -1
data/README.md
CHANGED
@@ -50,24 +50,32 @@ The basic usage is as follows::
|
|
50
50
|
$ t out
|
51
51
|
|
52
52
|
The first command, ``t switch writing``, switches to the timesheet "writing"
|
53
|
-
(or creates it if it does not exist). ``t in document timetrap
|
53
|
+
(or creates it if it does not exist). ``t in document timetrap ``--at`` "10 minutes
|
54
54
|
ago"`` creates a new period in the current timesheet, and annotates it with the
|
55
|
-
description "document timetrap". The optional
|
56
|
-
the entry at a time other than the present.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
timesheet.
|
55
|
+
description "document timetrap". The optional ``--at`` flag can be passed to start
|
56
|
+
the entry at a time other than the present. The ``--at`` flag is able to parse
|
57
|
+
natural language times (via Chronic: http://chronic.rubyforge.org/) and will
|
58
|
+
understand 'friday 13:00', 'mon 2:35', '4pm', etc. (also true of the ``alter``
|
59
|
+
command's ``--start`` and ``--end`` flags.) Note that this command would be in
|
60
|
+
error if the ``writing`` timesheet was already active. Finally, ``t out``
|
61
|
+
records the current time as the end time for the most recent period in the
|
62
|
+
``writing`` timesheet.
|
61
63
|
|
62
64
|
To display the current timesheet, invoke the ``t display`` command::
|
63
65
|
|
64
66
|
$ t display
|
65
|
-
Timesheet
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
Timesheet: timetrap
|
68
|
+
Day Start End Duration Notes
|
69
|
+
Mon Apr 13, 2009 15:46:51 - 17:03:50 1:16:59 improved display functionality
|
70
|
+
17:25:59 - 17:26:02 0:00:03
|
71
|
+
18:38:07 - 18:38:52 0:00:45 working on list
|
72
|
+
22:37:38 - 23:38:43 1:01:05 work on kill
|
73
|
+
2:18:52
|
74
|
+
Tue Apr 14, 2009 00:41:16 - 01:40:19 0:59:03 gem packaging
|
75
|
+
10:20:00 - 10:48:10 0:28:10 enhance alter
|
76
|
+
1:27:13
|
77
|
+
---------------------------------------------------------
|
78
|
+
Total 3:46:05
|
71
79
|
|
72
80
|
Each period in the timesheet is listed on a row. If the timesheet is active,
|
73
81
|
the final period in the timesheet will have no end time. After each day, the
|
@@ -79,9 +87,11 @@ Commands
|
|
79
87
|
--------
|
80
88
|
|
81
89
|
**alter**
|
82
|
-
Inserts a note associated with the
|
90
|
+
Inserts a note associated with the an entry in the timesheet, or alters the
|
91
|
+
start or end times. Defaults to the current time although an ``--id`` flag can
|
92
|
+
be passed with the entry's id (see display.)
|
83
93
|
|
84
|
-
usage: ``t alter NOTES
|
94
|
+
usage: ``t alter [--id ID] [--start TIME] [--end TIME] [NOTES]``
|
85
95
|
|
86
96
|
**backend**
|
87
97
|
Run an interactive database session on the timetrap database. Requires the
|
@@ -91,9 +101,11 @@ Commands
|
|
91
101
|
|
92
102
|
**display**
|
93
103
|
Display a given timesheet. If no timesheet is specified, show the current
|
94
|
-
timesheet.
|
104
|
+
timesheet. Accepts an optional ``--ids`` flag which will include the entries'
|
105
|
+
ids in the output. This is useful when editing an non running entry with
|
106
|
+
``alter``.
|
95
107
|
|
96
|
-
usage: ``t display [TIMESHEET]``
|
108
|
+
usage: ``t display [--ids] [TIMESHEET]``
|
97
109
|
|
98
110
|
**format**
|
99
111
|
Export the current sheet as a comma-separated value format spreadsheet. If
|
@@ -107,15 +119,15 @@ Commands
|
|
107
119
|
**in**
|
108
120
|
Start the timer for the current timesheet. Must be called before out. Notes
|
109
121
|
may be specified for this period. This is exactly equivalent to
|
110
|
-
``t in; t alter NOTES
|
122
|
+
``t in; t alter NOTES``. Accepts an optional --at flag.
|
111
123
|
|
112
|
-
usage: ``t in [--at TIME] [NOTES
|
124
|
+
usage: ``t in [--at TIME] [NOTES]``
|
113
125
|
|
114
126
|
**kill**
|
115
|
-
Delete a timesheet
|
116
|
-
|
127
|
+
Delete a timesheet or an entry. Entry's are referenced using an ``--id``
|
128
|
+
flag (see display). Sheets are referenced by name.
|
117
129
|
|
118
|
-
usage: ``t kill [TIMESHEET]``
|
130
|
+
usage: ``t kill [--id ID] [TIMESHEET]``
|
119
131
|
|
120
132
|
**list**
|
121
133
|
List the available timesheets.
|
@@ -126,15 +138,13 @@ Commands
|
|
126
138
|
Print the current sheet, whether it's active, and if so, how long it has been
|
127
139
|
active and what notes are associated with the current period.
|
128
140
|
|
129
|
-
If a specific timesheet is given, display the same information for that
|
130
|
-
timesheet instead.
|
131
|
-
|
132
141
|
usage: ``t now``
|
133
142
|
|
134
143
|
**out**
|
135
|
-
Stop the timer for the current timesheet. Must be called after in.
|
144
|
+
Stop the timer for the current timesheet. Must be called after in. Accepts an
|
145
|
+
optional --at flag.
|
136
146
|
|
137
|
-
usage: ``t
|
147
|
+
usage: ``t out [--at TIME]``
|
138
148
|
|
139
149
|
**running**
|
140
150
|
Print all active sheets and any messages associated with them.
|
data/lib/timetrap.rb
CHANGED
@@ -64,18 +64,28 @@ module Timetrap
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def kill
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
if e = Entry[args['--id']]
|
68
|
+
out = "are you sure you want to delete entry #{e.id}? "
|
69
|
+
out << "(#{e.note}) " if e.note.to_s =~ /.+/
|
70
|
+
print out
|
71
|
+
if $stdin.gets =~ /\Aye?s?\Z/i
|
72
|
+
e.destroy
|
73
|
+
say "it's dead"
|
74
|
+
else
|
75
|
+
say "will not kill"
|
76
|
+
end
|
77
|
+
elsif (sheets = Entry.map{|e| e.sheet }.uniq).include?(sheet = unused_args)
|
78
|
+
victims = Entry.filter(:sheet => sheet).count
|
79
|
+
print "are you sure you want to delete #{victims} entries on sheet #{sheet.inspect}? "
|
80
|
+
if $stdin.gets =~ /\Aye?s?\Z/i
|
81
|
+
Timetrap.kill_sheet sheet
|
82
|
+
say "killed #{victims} entries"
|
83
|
+
else
|
84
|
+
say "will not kill"
|
85
|
+
end
|
77
86
|
else
|
78
|
-
|
87
|
+
victim = args['--id'] ? args['--id'].to_s.inspect : sheet.inspect
|
88
|
+
say "can't find #{victim} to kill", 'sheets:', *sheets
|
79
89
|
end
|
80
90
|
end
|
81
91
|
|
@@ -84,7 +94,7 @@ module Timetrap
|
|
84
94
|
sheet = (sheet =~ /.+/ ? sheet : Timetrap.current_sheet)
|
85
95
|
say "Timesheet: #{sheet}"
|
86
96
|
id_heading = args['--ids'] ? 'Id' : ' '
|
87
|
-
say "
|
97
|
+
say "#{id_heading} Day Start End Duration Notes"
|
88
98
|
last_start = nil
|
89
99
|
from_current_day = []
|
90
100
|
(ee = Timetrap.entries(sheet)).each_with_index do |e, i|
|
@@ -92,7 +102,7 @@ module Timetrap
|
|
92
102
|
|
93
103
|
from_current_day << e
|
94
104
|
e_end = e.end || Time.now
|
95
|
-
say "%
|
105
|
+
say "%-4s%16s%11s -%9s%10s %s" % [
|
96
106
|
(args['--ids'] ? e.id : ''),
|
97
107
|
format_date_if_new(e.start, last_start),
|
98
108
|
format_time(e.start),
|
@@ -103,16 +113,16 @@ module Timetrap
|
|
103
113
|
|
104
114
|
nxt = Timetrap.entries(sheet).map[i+1]
|
105
115
|
if nxt == nil or !same_day?(e.start, nxt.start)
|
106
|
-
say "%
|
116
|
+
say "%52s" % format_total(from_current_day)
|
107
117
|
from_current_day = []
|
108
118
|
else
|
109
119
|
end
|
110
120
|
last_start = e.start
|
111
121
|
end
|
112
122
|
say <<-OUT
|
113
|
-
|
123
|
+
---------------------------------------------------------
|
114
124
|
OUT
|
115
|
-
say "
|
125
|
+
say " Total%43s" % format_total(ee)
|
116
126
|
end
|
117
127
|
|
118
128
|
def format
|
@@ -261,7 +271,7 @@ module Timetrap
|
|
261
271
|
self.current_sheet = sheet
|
262
272
|
end
|
263
273
|
|
264
|
-
def
|
274
|
+
def kill_sheet sheet
|
265
275
|
Entry.filter(:sheet => sheet).destroy
|
266
276
|
end
|
267
277
|
|
data/spec/timetrap_spec.rb
CHANGED
@@ -86,28 +86,28 @@ describe Timetrap do
|
|
86
86
|
Time.stub!(:now).and_return Time.at(1223254800 + (60*60*2))
|
87
87
|
@desired_output = <<-OUTPUT
|
88
88
|
Timesheet: SpecSheet
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
Day Start End Duration Notes
|
90
|
+
Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
|
91
|
+
16:00:00 - 18:00:00 2:00:00 entry 2
|
92
|
+
4:00:00
|
93
|
+
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
|
94
|
+
18:00:00 - 2:00:00 entry 4
|
95
|
+
4:00:00
|
96
|
+
---------------------------------------------------------
|
97
|
+
Total 8:00:00
|
98
98
|
OUTPUT
|
99
99
|
|
100
100
|
@desired_output_with_ids = <<-OUTPUT
|
101
101
|
Timesheet: SpecSheet
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
102
|
+
Id Day Start End Duration Notes
|
103
|
+
3 Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
|
104
|
+
2 16:00:00 - 18:00:00 2:00:00 entry 2
|
105
|
+
4:00:00
|
106
|
+
4 Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
|
107
|
+
5 18:00:00 - 2:00:00 entry 4
|
108
|
+
4:00:00
|
109
|
+
---------------------------------------------------------
|
110
|
+
Total 8:00:00
|
111
111
|
OUTPUT
|
112
112
|
end
|
113
113
|
|
@@ -183,10 +183,20 @@ Timesheet: SpecSheet
|
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should delete a timesheet" do
|
186
|
+
create_entry
|
186
187
|
entry = create_entry
|
187
188
|
lambda do
|
188
189
|
$stdin.string = "yes\n"
|
189
190
|
invoke "kill #{entry.sheet}"
|
191
|
+
end.should change(Timetrap::Entry, :count).by(-2)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should delete an entry" do
|
195
|
+
create_entry
|
196
|
+
entry = create_entry
|
197
|
+
lambda do
|
198
|
+
$stdin.string = "yes\n"
|
199
|
+
invoke "kill --id #{entry.id}"
|
190
200
|
end.should change(Timetrap::Entry, :count).by(-1)
|
191
201
|
end
|
192
202
|
end
|