timet 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -6
- data/CHANGELOG.md +23 -0
- data/README.md +50 -74
- data/Rakefile +3 -3
- data/bin/timet +1 -1
- data/lib/timet/application.rb +25 -20
- data/lib/timet/database.rb +24 -11
- data/lib/timet/time_helper.rb +9 -1
- data/lib/timet/time_report.rb +64 -38
- data/lib/timet/version.rb +1 -1
- data/lib/timet.rb +3 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31d714405b3e7c5ff73a15f62e00f633b09aa6740b03eb0adfd248a83445320e
|
4
|
+
data.tar.gz: 98251bb40809c2c1d1151cd2c55fc5666faa029e9f7fc8958db3ec0460893253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12ba0176fb4d85870dcf87ca83d8b9fe9dca1c9303b39e9ab8cc0595d64ced68e3c10fef86ffbb1f0a7d6ad8114f08d2355abcfed894e7e4e609f3c319fd68e5
|
7
|
+
data.tar.gz: '04194e7a85dbfc73755f8b3bb2db20759aef24219046865102d23867ff9ee92e12807734cc07590cfeb07ba52ad60a66da4d3762f47ff059f089ed7dd2330cb6'
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.1] - 2024-09-24
|
4
|
+
|
5
|
+
* **Improved `resume` behavior:**
|
6
|
+
* If no notes are provided, it will attempt to retrieve them from the last tracked task.
|
7
|
+
* **Enhanced `export_sheet` functionality:**
|
8
|
+
* A new `notes` column has been added to the exported CSV file.
|
9
|
+
* **Minor bug fixes:**
|
10
|
+
* Resolved issues related to resuming tasks with notes and deleting items.
|
11
|
+
|
12
|
+
|
13
|
+
## [0.2.0] - 2024-09-24
|
14
|
+
|
15
|
+
* **Improved code quality:**
|
16
|
+
* Enforces consistent quoting style with `RuboCop` integration.
|
17
|
+
* Removes unused gems (`mini_portile2`) from the `Gemfile`.
|
18
|
+
* **Database enhancements:**
|
19
|
+
* Adds a new column named "notes" to the `items` table to store additional information about tracked time entries.
|
20
|
+
* **Command-line improvements:**
|
21
|
+
* Allows adding notes to a new time entry using the `start` command with the `--notes` option (e.g., `timet start work --notes="meeting with client"`).
|
22
|
+
* Improves formatting and clarity of some command descriptions.
|
23
|
+
* **General code formatting:**
|
24
|
+
* Uses single quotes (`'`) for strings and source paths in the `Gemfile`.
|
25
|
+
|
3
26
|
## [0.1.0] - 2024-08-01
|
4
27
|
|
5
28
|
- Initial release
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|

|
2
|
-
|
2
|
+
[](https://codeclimate.com/github/frankvielma/timet/maintainability)
|
3
|
+
[](https://codeclimate.com/github/frankvielma/timet/test_coverage)
|
3
4
|
|
4
5
|
# Timet
|
5
6
|
|
@@ -32,145 +33,120 @@ Old versions of Ruby and Sqlite:
|
|
32
33
|
|
33
34
|
## Installation
|
34
35
|
|
35
|
-
Install the gem
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
40
|
-
|
41
|
-
$ gem install timet
|
36
|
+
Install the gem by executing:
|
37
|
+
```bash
|
38
|
+
$ gem install timet
|
39
|
+
```
|
42
40
|
|
43
41
|
## Usage
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
```shell
|
49
|
-
timet start task1
|
50
|
-
|
51
|
-
or
|
52
|
-
|
53
|
-
tt start task1
|
43
|
+
- **timet start [tag] --notes='...'**: Starts tracking time for a task labeled with the provided [tag] and notes (optional). Example:
|
44
|
+
```bash
|
45
|
+
timet start task1 --notes='Meeting with client'
|
54
46
|
```
|
55
47
|
|
56
48
|
```
|
57
|
-
Tracked time report:
|
58
|
-
|
59
|
-
| Id | Tag | Start
|
60
|
-
|
61
|
-
| 1 |
|
62
|
-
|
63
|
-
|
|
64
|
-
|
49
|
+
Tracked time report [today]:
|
50
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
51
|
+
| Id | Date | Tag | Start | End | Duration | Notes |
|
52
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
53
|
+
| 1 | 2024-08-09 | task1 | 14:55:07 | - | 00:00:00 | Meeting with client |
|
54
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
55
|
+
| Total: | 00:00:00 | |
|
56
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
65
57
|
```
|
66
58
|
|
67
59
|
- **timet stop**: Stops tracking the current task, records the elapsed time, and displays the total time spent on all tasks.
|
68
60
|
|
69
|
-
```
|
61
|
+
```bash
|
70
62
|
timet stop
|
71
63
|
```
|
72
64
|
|
73
65
|
```
|
74
|
-
Tracked time report:
|
75
|
-
|
76
|
-
| Id | Tag | Start
|
77
|
-
|
78
|
-
| 1 |
|
79
|
-
|
80
|
-
|
|
81
|
-
|
66
|
+
Tracked time report [today]:
|
67
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
68
|
+
| Id | Date | Tag | Start | End | Duration | Notes |
|
69
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
70
|
+
| 1 | 2024-08-09 | task1 | 14:55:07 | 15:55:07 | 01:00:00 | Meeting with client |
|
71
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
72
|
+
| Total: | 01:00:00 | |
|
73
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
82
74
|
```
|
83
75
|
|
84
76
|
- **timet resume**: It allows users to quickly resume tracking a task that was previously in progress.
|
85
77
|
```
|
86
|
-
Tracked time report:
|
87
|
-
|
88
|
-
| Id | Tag | Start
|
89
|
-
|
90
|
-
| 2 |
|
91
|
-
| 1 | task1 |
|
92
|
-
|
93
|
-
|
|
94
|
-
|
78
|
+
Tracked time report [today]:
|
79
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
80
|
+
| Id | Date | Tag | Start | End | Duration | Notes |
|
81
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
82
|
+
| 2 | 2024-08-09 | task1 | 16:15:07 | - | 00:00:00 | Meeting with client |
|
83
|
+
| 1 | | task1 | 14:55:07 | 15:55:07 | 01:00:00 | Meeting with client |
|
84
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
85
|
+
| Total: | 01:00:00 | |
|
86
|
+
+-------+------------+--------+----------+----------+----------+--------------------------+
|
95
87
|
```
|
96
88
|
|
97
89
|
- **timet summary today (t)**: Display a report of tracked time for today.
|
98
90
|
|
99
|
-
```
|
91
|
+
```bash
|
100
92
|
timet summary today
|
101
|
-
|
102
|
-
or
|
103
|
-
|
104
|
-
tt su t
|
105
93
|
```
|
106
94
|
|
107
95
|
- **timet summary yesterday (y)**: Display a report of tracked time for yesterday.
|
108
96
|
|
109
|
-
```
|
97
|
+
```bash
|
110
98
|
timet summary yesterday
|
111
|
-
|
112
|
-
or
|
113
|
-
|
114
|
-
tt su y
|
115
99
|
```
|
116
100
|
|
117
101
|
- **timet summary week (w)**: Display a report of tracked time for the week.
|
118
102
|
|
119
|
-
```
|
103
|
+
```bash
|
120
104
|
timet summary week
|
121
|
-
|
122
|
-
or
|
123
|
-
|
124
|
-
tt su w
|
125
105
|
```
|
126
106
|
|
127
107
|
- **timet summary resume (r)**: Resume tracking the last task.
|
128
108
|
|
129
|
-
```
|
109
|
+
```bash
|
130
110
|
timet summary resume
|
131
|
-
|
132
|
-
or
|
133
|
-
|
134
|
-
tt su r
|
135
111
|
```
|
136
112
|
|
137
113
|
- **timet summary resume (r)**: Resume tracking the last month.
|
138
114
|
|
139
|
-
```
|
115
|
+
```bash
|
140
116
|
timet summary month
|
141
|
-
|
142
|
-
or
|
143
|
-
|
144
|
-
tt su m
|
145
117
|
```
|
146
118
|
|
147
119
|
- **timet su t --csv=[filename]**: Display a report of tracked time for today and export it to filename.csv
|
148
120
|
|
149
|
-
```
|
150
|
-
|
121
|
+
```bash
|
122
|
+
timet su t --csv=summary_today.csv
|
151
123
|
```
|
152
124
|
|
153
125
|
- **timet delete [id]**: Delete a task
|
154
126
|
|
155
|
-
```
|
127
|
+
```bash
|
156
128
|
timet delete [id]
|
157
129
|
|
158
130
|
or
|
159
131
|
|
160
|
-
|
132
|
+
timet d [id]
|
161
133
|
```
|
162
134
|
|
163
135
|
- **timet cancel**: Cancel active time tracking
|
164
136
|
|
165
|
-
```
|
137
|
+
```bash
|
166
138
|
timet cancel
|
167
139
|
|
168
140
|
or
|
169
141
|
|
170
|
-
|
142
|
+
timet c
|
171
143
|
```
|
172
144
|
|
173
145
|
|
146
|
+
## Data
|
147
|
+
Timet's data is stored in ~/.timet.db
|
148
|
+
|
149
|
+
|
174
150
|
## Development
|
175
151
|
|
176
152
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
require
|
8
|
+
require 'rubocop/rake_task'
|
9
9
|
|
10
10
|
RuboCop::RakeTask.new
|
11
11
|
|
data/bin/timet
CHANGED
data/lib/timet/application.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative 'version'
|
4
|
+
require 'thor'
|
5
|
+
require 'tty-prompt'
|
6
|
+
require 'byebug'
|
6
7
|
|
7
8
|
module Timet
|
8
9
|
# Tracks time spent on various tasks.
|
@@ -12,14 +13,16 @@ module Timet
|
|
12
13
|
@db = Timet::Database.new
|
13
14
|
end
|
14
15
|
|
15
|
-
desc "start [tag]", "start time tracking"
|
16
|
-
|
16
|
+
desc "start [tag] --notes='...'", "start time tracking --notes='my notes...'"
|
17
|
+
option :notes, type: :string, desc: 'Add a note'
|
18
|
+
def start(tag, notes = nil)
|
17
19
|
start = Time.now.to_i
|
18
|
-
|
20
|
+
notes = options[:notes] || notes
|
21
|
+
@db.insert_item(start, tag, notes) if %i[no_items complete].include?(@db.last_item_status)
|
19
22
|
summary
|
20
23
|
end
|
21
24
|
|
22
|
-
desc
|
25
|
+
desc 'stop', 'stop time tracking'
|
23
26
|
def stop
|
24
27
|
stop = Time.now.to_i
|
25
28
|
@db.update(stop) if @db.last_item_status == :incomplete
|
@@ -30,19 +33,21 @@ module Timet
|
|
30
33
|
summary
|
31
34
|
end
|
32
35
|
|
33
|
-
desc
|
36
|
+
desc 'resume (r)', 'resume last task'
|
34
37
|
def resume
|
35
38
|
if @db.last_item_status == :incomplete
|
36
|
-
puts
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
puts 'A task is currently being tracked.'
|
40
|
+
elsif @db.last_item.any?
|
41
|
+
tag = @db.last_item[3]
|
42
|
+
notes = @db.last_item[4]
|
43
|
+
start(tag, notes)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
desc
|
44
|
-
"Display a summary of tracked time filter => [today (t), yesterday (y), week (w), month (m)] [tag]
|
45
|
-
|
47
|
+
desc 'summary (su) [filter] [tag] --csv=csv_filename',
|
48
|
+
"Display a summary of tracked time filter => [today (t), yesterday (y), week (w), month (m)] [tag]
|
49
|
+
and export to csv_filename"
|
50
|
+
option :csv, type: :string, desc: 'Export to CSV file'
|
46
51
|
def summary(filter = nil, tag = nil)
|
47
52
|
csv_filename = options[:csv]
|
48
53
|
summary = TimeReport.new(@db, filter, tag, csv_filename)
|
@@ -50,21 +55,21 @@ module Timet
|
|
50
55
|
summary.export_sheet if csv_filename
|
51
56
|
end
|
52
57
|
|
53
|
-
desc
|
58
|
+
desc 'delete (d) [id]', 'delete a task'
|
54
59
|
def delete(id)
|
55
60
|
item = @db.find_item(id)
|
56
61
|
return puts "No tracked time found for id: #{id}" unless item
|
57
62
|
|
58
|
-
TimeReport.new(@db, nil, nil).
|
59
|
-
return unless TTY::Prompt.new.yes?(
|
63
|
+
TimeReport.new(@db, nil, nil, nil).show_row(item)
|
64
|
+
return unless TTY::Prompt.new.yes?('Are you sure you want to delete this entry?')
|
60
65
|
|
61
66
|
delete_item_and_print_message(id, "Deleted #{id}")
|
62
67
|
end
|
63
68
|
|
64
|
-
desc
|
69
|
+
desc 'cancel (c)', 'cancel active time tracking'
|
65
70
|
def cancel
|
66
71
|
id = @db.fetch_last_id
|
67
|
-
return puts
|
72
|
+
return puts 'There is no active time tracking' if @db.last_item_status == :complete
|
68
73
|
|
69
74
|
delete_item_and_print_message(id, "Canceled active time tracking #{id}")
|
70
75
|
end
|
data/lib/timet/database.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'sqlite3'
|
4
4
|
|
5
5
|
module Timet
|
6
6
|
# Provides database access for managing time tracking data.
|
7
7
|
class Database
|
8
|
-
DEFAULT_DATABASE_PATH = File.join(Dir.home,
|
8
|
+
DEFAULT_DATABASE_PATH = File.join(Dir.home, '.timet.db')
|
9
9
|
|
10
10
|
def initialize(database_path = DEFAULT_DATABASE_PATH)
|
11
11
|
@db = SQLite3::Database.new(database_path)
|
12
12
|
create_table
|
13
|
+
add_notes
|
13
14
|
end
|
14
15
|
|
15
16
|
# Creates the items table if it doesn't already exist
|
@@ -24,9 +25,21 @@ module Timet
|
|
24
25
|
SQL
|
25
26
|
end
|
26
27
|
|
28
|
+
# Adds a new column named "notes" to the "items" table if it doesn't exist.
|
29
|
+
def add_notes
|
30
|
+
table_name = 'items'
|
31
|
+
new_column_name = 'notes'
|
32
|
+
result = execute_sql("SELECT count(*) FROM pragma_table_info('items') where name='#{new_column_name}'")
|
33
|
+
column_exists = result[0][0].positive?
|
34
|
+
return if column_exists
|
35
|
+
|
36
|
+
execute_sql("ALTER TABLE #{table_name} ADD COLUMN #{new_column_name} TEXT")
|
37
|
+
puts "Column '#{new_column_name}' added to table '#{table_name}'."
|
38
|
+
end
|
39
|
+
|
27
40
|
# Inserts a new item into the items table
|
28
|
-
def insert_item(start, tag)
|
29
|
-
execute_sql(
|
41
|
+
def insert_item(start, tag, notes)
|
42
|
+
execute_sql('INSERT INTO items (start, tag, notes) VALUES (?, ?, ?)', [start, tag, notes])
|
30
43
|
end
|
31
44
|
|
32
45
|
# Updates the end time of the last item
|
@@ -34,7 +47,7 @@ module Timet
|
|
34
47
|
last_id = fetch_last_id
|
35
48
|
return unless last_id
|
36
49
|
|
37
|
-
execute_sql(
|
50
|
+
execute_sql('UPDATE items SET end = ? WHERE id = ?', [stop, last_id])
|
38
51
|
end
|
39
52
|
|
40
53
|
def delete_item(id)
|
@@ -43,16 +56,16 @@ module Timet
|
|
43
56
|
|
44
57
|
# Fetches the ID of the last inserted item
|
45
58
|
def fetch_last_id
|
46
|
-
result = execute_sql(
|
59
|
+
result = execute_sql('SELECT id FROM items ORDER BY id DESC LIMIT 1').first
|
47
60
|
result ? result[0] : nil
|
48
61
|
end
|
49
62
|
|
50
63
|
def last_item
|
51
|
-
execute_sql(
|
64
|
+
execute_sql('SELECT * FROM items ORDER BY id DESC LIMIT 1').first
|
52
65
|
end
|
53
66
|
|
54
67
|
def last_item_status
|
55
|
-
result = execute_sql(
|
68
|
+
result = execute_sql('SELECT id, end FROM items ORDER BY id DESC LIMIT 1')
|
56
69
|
StatusHelper.determine_status(result)
|
57
70
|
end
|
58
71
|
|
@@ -62,8 +75,8 @@ module Timet
|
|
62
75
|
|
63
76
|
# Calculates the total time elapsed since the last recorded time.
|
64
77
|
def total_time
|
65
|
-
last_item = execute_sql(
|
66
|
-
return
|
78
|
+
last_item = execute_sql('SELECT * FROM items ORDER BY id DESC LIMIT 1').first
|
79
|
+
return '00:00:00' unless last_item
|
67
80
|
|
68
81
|
start_time = last_item[1]
|
69
82
|
end_time = last_item[2]
|
@@ -94,7 +107,7 @@ module Timet
|
|
94
107
|
hours, remainder = seconds.divmod(3600)
|
95
108
|
minutes, seconds = remainder.divmod(60)
|
96
109
|
|
97
|
-
format
|
110
|
+
format '%<hours>02d:%<minutes>02d:%<seconds>02d', hours: hours, minutes: minutes, seconds: seconds
|
98
111
|
end
|
99
112
|
end
|
100
113
|
end
|
data/lib/timet/time_helper.rb
CHANGED
@@ -7,7 +7,15 @@
|
|
7
7
|
# - converting a Date object to a timestamp
|
8
8
|
module TimeHelper
|
9
9
|
def self.format_time(timestamp)
|
10
|
-
timestamp&.then { |time| Time.at(time).strftime(
|
10
|
+
timestamp&.then { |time| Time.at(time).strftime('%Y-%m-%d %H:%M:%S').ljust(19) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.timestamp_to_date(timestamp)
|
14
|
+
timestamp&.then { |time| Time.at(time).strftime('%Y-%m-%d') }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.timestamp_to_time(timestamp)
|
18
|
+
timestamp&.then { |time| Time.at(time).strftime('%H:%M:%S') }
|
11
19
|
end
|
12
20
|
|
13
21
|
def self.calculate_duration(start_time, end_time)
|
data/lib/timet/time_report.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require_relative
|
6
|
-
require_relative
|
3
|
+
require 'date'
|
4
|
+
require 'csv'
|
5
|
+
require_relative 'time_helper'
|
6
|
+
require_relative 'status_helper'
|
7
7
|
|
8
8
|
module Timet
|
9
9
|
# The TimeReport class is responsible for displaying a report of tracked time
|
@@ -15,21 +15,23 @@ module Timet
|
|
15
15
|
def initialize(db, filter, tag, csv)
|
16
16
|
@db = db
|
17
17
|
@filename = csv
|
18
|
-
@
|
18
|
+
@filter = formatted_filter(filter)
|
19
|
+
@items = filter ? filter_items(@filter, tag) : @db.all_items
|
19
20
|
end
|
20
21
|
|
21
22
|
def display
|
22
|
-
return puts
|
23
|
+
return puts 'No tracked time found for the specified filter.' if items.empty?
|
23
24
|
|
24
25
|
format_table_header
|
25
|
-
items.
|
26
|
-
|
26
|
+
items.each_with_index do |item, idx|
|
27
|
+
date = extract_date(items, idx)
|
28
|
+
display_time_entry(item, date)
|
27
29
|
end
|
28
30
|
puts format_table_separator
|
29
31
|
total
|
30
32
|
end
|
31
33
|
|
32
|
-
def
|
34
|
+
def show_row(item)
|
33
35
|
format_table_header
|
34
36
|
display_time_entry(item)
|
35
37
|
puts format_table_separator
|
@@ -37,75 +39,83 @@ module Timet
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def export_sheet
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
csv << [row[0], start_time, end_time, row[3]]
|
42
|
+
CSV.open("#{filename}.csv", 'w') do |csv|
|
43
|
+
csv << %w[ID Start End Tag Notes]
|
44
|
+
|
45
|
+
items.each do |id, start_time, end_time, tags, notes|
|
46
|
+
csv << [
|
47
|
+
id,
|
48
|
+
TimeHelper.format_time(start_time),
|
49
|
+
TimeHelper.format_time(end_time),
|
50
|
+
tags,
|
51
|
+
notes
|
52
|
+
]
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
57
|
private
|
57
58
|
|
58
|
-
def
|
59
|
-
|
59
|
+
def extract_date(items, idx)
|
60
|
+
current_start_date = items[idx][1]
|
61
|
+
date = TimeHelper.timestamp_to_date(current_start_date)
|
62
|
+
|
63
|
+
last_start_date = items[idx - 1][1]
|
64
|
+
date if idx.zero? || date != TimeHelper.timestamp_to_date(last_start_date)
|
65
|
+
end
|
66
|
+
|
67
|
+
def display_time_entry(item, date = nil)
|
68
|
+
return puts 'Missing time entry data.' unless item
|
60
69
|
|
61
|
-
id, start_time_value, end_time_value, tag_name = item
|
70
|
+
id, start_time_value, end_time_value, tag_name, notes = item
|
62
71
|
duration = TimeHelper.calculate_duration(start_time_value, end_time_value)
|
63
72
|
start_time = TimeHelper.format_time(start_time_value)
|
64
|
-
end_time = TimeHelper.format_time(end_time_value) ||
|
65
|
-
|
73
|
+
end_time = TimeHelper.format_time(end_time_value) || '- -'
|
74
|
+
start_date = date.nil? ? ' ' * 10 : date
|
75
|
+
puts format_table_row(id, tag_name[0..5], start_date, start_time, end_time, duration, notes)
|
66
76
|
end
|
67
77
|
|
68
78
|
def total
|
69
79
|
total = @items.map do |item|
|
70
80
|
TimeHelper.calculate_duration(item[1], item[2])
|
71
81
|
end.sum
|
72
|
-
puts "|#{
|
82
|
+
puts "|#{' ' * 43}\033[94mTotal: | #{@db.seconds_to_hms(total).rjust(8)} |\033[0m |"
|
73
83
|
puts format_table_separator
|
74
84
|
end
|
75
85
|
|
76
86
|
def format_table_header
|
77
87
|
header = <<~TABLE
|
78
|
-
Tracked time report:
|
88
|
+
Tracked time report \u001b[31m[#{@filter}]\033[0m:
|
79
89
|
#{format_table_separator}
|
80
|
-
\033[32m| Id | Tag | Start
|
90
|
+
\033[32m| Id | Date | Tag | Start | End | Duration | Notes |\033[0m
|
81
91
|
#{format_table_separator}
|
82
92
|
TABLE
|
83
93
|
puts header
|
84
94
|
end
|
85
95
|
|
86
96
|
def format_table_separator
|
87
|
-
|
97
|
+
'+-------+------------+--------+----------+----------+----------+--------------------------+'
|
88
98
|
end
|
89
99
|
|
90
100
|
def format_table_row(*row)
|
91
|
-
id, tag, start_time, end_time, duration = row
|
92
|
-
"| #{id.to_s.rjust(5)} | #{tag.ljust(6)} | #{start_time} |
|
93
|
-
"#{@db.seconds_to_hms(duration).rjust(
|
101
|
+
id, tag, start_date, start_time, end_time, duration, notes = row
|
102
|
+
"| #{id.to_s.rjust(5)} | #{start_date} | #{tag.ljust(6)} | #{start_time.split[1]} | " \
|
103
|
+
"#{end_time.split[1].rjust(8)} | #{@db.seconds_to_hms(duration).rjust(8)} | #{format_notes(notes)} |"
|
94
104
|
end
|
95
105
|
|
96
106
|
def filter_items(filter, tag)
|
97
107
|
today = Date.today
|
98
108
|
case filter
|
99
|
-
when
|
109
|
+
when 'today'
|
100
110
|
filter_by_date_range(today, nil, tag)
|
101
|
-
when
|
111
|
+
when 'yesterday'
|
102
112
|
filter_by_date_range(today - 1, nil, tag)
|
103
|
-
when
|
113
|
+
when 'week'
|
104
114
|
filter_by_date_range(today - 7, today + 1, tag)
|
105
|
-
when
|
115
|
+
when 'month'
|
106
116
|
filter_by_date_range(today - 30, today + 1, tag)
|
107
117
|
else
|
108
|
-
puts
|
118
|
+
puts 'Invalid filter. Supported filters: today, yesterday, week'
|
109
119
|
[]
|
110
120
|
end
|
111
121
|
end
|
@@ -118,5 +128,21 @@ module Timet
|
|
118
128
|
"select * from items where #{query} ORDER BY id DESC"
|
119
129
|
)
|
120
130
|
end
|
131
|
+
|
132
|
+
def format_notes(notes)
|
133
|
+
return ' ' * 23 if notes.nil?
|
134
|
+
|
135
|
+
notes = "#{notes.slice(0, 20)}..." if notes.length > 20
|
136
|
+
notes.ljust(23)
|
137
|
+
end
|
138
|
+
|
139
|
+
def formatted_filter(filter)
|
140
|
+
return 'today' if %w[today t].include?(filter)
|
141
|
+
return 'yesterday' if %w[yesterday y].include?(filter)
|
142
|
+
return 'week' if %w[week w].include?(filter)
|
143
|
+
return 'month' if %w[month m].include?(filter)
|
144
|
+
|
145
|
+
'today'
|
146
|
+
end
|
121
147
|
end
|
122
148
|
end
|
data/lib/timet/version.rb
CHANGED
data/lib/timet.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Vielma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -84,11 +84,11 @@ files:
|
|
84
84
|
- lib/timet/time_report.rb
|
85
85
|
- lib/timet/version.rb
|
86
86
|
- sig/timet.rbs
|
87
|
-
homepage: https://github.
|
87
|
+
homepage: https://frankvielma.github.io/posts/timet-a-powerful-command-line-tool-for-tracking-your-time/
|
88
88
|
licenses:
|
89
89
|
- MIT
|
90
90
|
metadata:
|
91
|
-
homepage_uri: https://github.
|
91
|
+
homepage_uri: https://frankvielma.github.io/posts/timet-a-powerful-command-line-tool-for-tracking-your-time/
|
92
92
|
source_code_uri: https://github.com/frankvielma/timet
|
93
93
|
changelog_uri: https://github.com/frankvielma/timet/blob/main/CHANGELOG.md
|
94
94
|
rubygems_mfa_required: 'true'
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.5.9
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Command line time tracking with reports
|