timetrackr 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.mkd CHANGED
@@ -6,22 +6,57 @@ A simple CLI time tracking utility.
6
6
 
7
7
  (with a Bash alias of 'tt')
8
8
 
9
+ start a task:
10
+
9
11
  $ tt start something
10
12
 
13
+ ...view durations:
14
+
11
15
  $ tt
12
16
  something * 0h 0m 4s
13
17
 
18
+ ...have two running tasks:
19
+
14
20
  $ tt start another-thing
15
21
 
16
22
  $ tt log
17
- 2011-05-18 something * 22:11 0h 0m 26s
18
- another-thing * 22:11 0h 0m 6s
23
+ 2011-05-18 something * 22:11 0h 0m 30s
24
+ another-thing * 22:11 0h 0m 15s
25
+
26
+ ...start with a note:
27
+
28
+ $ tt start one-more with a note
29
+
30
+ $ tt log
31
+ 2011-05-18 something * 22:11 0h 0m 45s
32
+ another-thing * 22:11 0h 0m 30s
33
+ one-more * 22:13 0h 0m 15s with a note
34
+
35
+ ...restrict some:
36
+
37
+ $ tt log something
38
+ 2011-05-18 something * 22:11 0h 1m 00s
39
+
40
+ ...exclude some:
41
+
42
+ $ tt log something -n another-thing
43
+ 2011-05-18 something * 22:11 0h 1m 15s
44
+ one-more * 22:13 0h 0m 45s with a note
45
+
46
+ ...stop one (or more):
19
47
 
20
48
  $ tt stop something
21
49
 
22
50
  $ tt
23
- something 0h 0m 37s
24
- another-thing * 0h 0m 20s
51
+ something 0h 1m 20s
52
+ another-thing * 0h 1m 30s
53
+ one-more * 0h 1m 15s
54
+
55
+ ...and delete one:
56
+
57
+ $ tt clear something
58
+ another-thing * 0h 1m 45s
59
+ one-more * 0h 1m 30s
25
60
 
26
61
 
27
62
  ## Contributing to timetrackr
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -44,6 +44,7 @@ module TimeTrackr
44
44
 
45
45
  #
46
46
  # run a command on the tracker
47
+ # 'args' is everything after the command
47
48
  #
48
49
  def run(cmd,args)
49
50
  case cmd
@@ -62,11 +63,7 @@ module TimeTrackr
62
63
  @trackr.start(task, notes)
63
64
 
64
65
  when 'stop','out','kill','k'
65
- if args[0] == 'all' || args[0].nil?
66
- tasks = @trackr.tasks
67
- else
68
- tasks = args
69
- end
66
+ tasks = get_tasks(args)
70
67
  tasks.each do |task|
71
68
  @trackr.stop(task)
72
69
  puts "Stopped task '#{task}'" if @verbose
@@ -82,46 +79,17 @@ module TimeTrackr
82
79
  puts "Switched to task '#{task}'" if @verbose
83
80
 
84
81
  when 'time','status',nil
85
- task = args.shift
86
- if task && @trackr.tasks.include?(task)
87
- tasks = [*task]
88
- else
89
- tasks = @trackr.tasks.each
90
- end
91
- tasks.each do |task|
92
- total = @trackr.history(task).reduce(0){ |t, period|
93
- t = t + period.length
94
- }
95
- name = @trackr.current.include?(task) ? task+' *' : task
96
- puts name.ljust(15) << format_time(total,@config['relative_format'])
97
- end
82
+ tasks = get_tasks(args)
83
+ puts create_log(tasks,'t')
98
84
 
99
85
  when 'log'
100
- if args[0] == 'all' || args[0].nil?
101
- tasks = @trackr.tasks
102
- else
103
- tasks = args
104
- end
105
- table = []
106
- periods = tasks.each.collect{ |t| @trackr.history(t) }.flatten
107
- lastday = nil
108
- table << periods.sort{|x,y| x.start <=> y.start}.collect{ |period|
109
- currday = period.start.strftime(@config['absolute_day'])
110
- day = (currday == lastday) ? ' ' : currday
111
- lastday = currday
112
- name = period.current? ? period.task+' *' : period.task
113
- start = period.start.strftime(@config['absolute_time'])
114
- stop = period.current? ? ' ' : period.stop.strftime(@config['absolute_time'])
115
- length = format_time(period.length, @config['relative_format'])
116
- notes = period.notes
117
- "#{day.ljust(12)} #{name.ljust(15)} #{start} - #{stop.ljust(5)} #{length} #{notes}"
118
- }
119
- puts table
86
+ group = args.shift[1] if ['-d','-t'].include?(args[0])
120
87
 
88
+ tasks = get_tasks(args)
89
+ puts create_log(tasks,group)
121
90
 
122
91
  when 'clear','delete','del'
123
- tasks = args
124
- tasks = @trackr.tasks if task == 'all'
92
+ tasks = get_tasks(args)
125
93
  tasks.each do |task|
126
94
  @trackr.clear(task)
127
95
  puts "Task '#{task}' cleared" if @verbose
@@ -146,6 +114,17 @@ module TimeTrackr
146
114
 
147
115
  protected
148
116
 
117
+ def get_tasks(args)
118
+ if args[0].nil? || args[0] == 'all' || args[0] == '-n'
119
+ args.unshift(@trackr.tasks).flatten!.delete('all')
120
+ end
121
+
122
+ split = args.index('-n') || args.length
123
+ show = args.slice(0...split).compact.uniq
124
+ ignore =[*args.slice(split+1..-1)].compact.uniq
125
+ tasks = (show.empty? ? @trackr.tasks : @trackr.tasks & show) - ignore
126
+ end
127
+
149
128
  def format_time(time, fmt_str)
150
129
  hours = time.to_i/3600.to_i
151
130
  minutes = (time/60 - hours * 60).to_i
@@ -156,6 +135,55 @@ module TimeTrackr
156
135
  :seconds => seconds})
157
136
  end
158
137
 
138
+ def create_log(tasks,group=nil)
139
+ totals = Hash.new(0)
140
+ days = {}
141
+ table = []
142
+ # get all periods for selected tasks
143
+ periods = tasks.each.collect{ |t| @trackr.history(t) }.flatten
144
+ lastday = nil
145
+ periods.sort{|x,y| x.start <=> y.start}.collect do |period|
146
+ currday = period.start.strftime(@config['absolute_day'])
147
+ if currday == lastday
148
+ day = ''
149
+ else
150
+ day = currday
151
+ days[day] = Hash.new(0)
152
+ end
153
+ lastday = currday
154
+
155
+ start = period.start.strftime(@config['absolute_time'])
156
+ stop = period.current? ? ' ' : period.stop.strftime(@config['absolute_time'])
157
+ name = period.current? ? period.task+' *' : period.task
158
+ notes = period.notes
159
+ length = format_time(period.length, @config['relative_format'])
160
+
161
+ totals[period.task] = totals[period.task] + period.length if group == 't'
162
+ days[currday][period.task] = days[currday][period.task] + period.length if group == 'd'
163
+ # for full log
164
+ table << "#{day.ljust(12)} #{name.ljust(15)} #{start} - #{stop.ljust(5)} #{length} #{notes}" if group.nil?
165
+ end
166
+
167
+ case group
168
+ when 't'
169
+ tasks.each do |task|
170
+ name = @trackr.current.include?(task) ? task+' *' : task
171
+ table << name.ljust(15) + format_time(totals[task],@config['relative_format'])
172
+ end
173
+ when 'd'
174
+ prev_date = ''
175
+ days.each_pair do |date,tasks|
176
+ tasks.each_pair do |task,length|
177
+ name = @trackr.current.include?(task) ? task+' *' : task
178
+ date_string = (date == prev_date) ? ' ' : date
179
+ prev_date = date
180
+ table << "#{date_string.ljust(12)} #{name.ljust(15)} " + format_time(length, @config['relative_format'])
181
+ end
182
+ end
183
+ end
184
+ table
185
+ end
186
+
159
187
  def show_help
160
188
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
161
189
  puts "timetrackr version #{version}"
data/timetrackr.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{timetrackr}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Felix Hanley"]
12
- s.date = %q{2011-05-23}
12
+ s.date = %q{2011-06-02}
13
13
  s.default_executable = %q{timetrackr}
14
14
  s.description = %q{A simple time tracking utility}
15
15
  s.email = %q{felix@seconddrawer.com.au}
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: timetrackr
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Felix Hanley
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-23 00:00:00 +07:00
13
+ date: 2011-06-02 00:00:00 +07:00
14
14
  default_executable: timetrackr
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
- hash: -2538018453800347300
123
+ hash: -4452594232215196430
124
124
  segments:
125
125
  - 0
126
126
  version: "0"