timet 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86b753ecfeaeaa477431908419a5a20c1446d146f52dbd72a2a2cda1e4664873
4
- data.tar.gz: e5a13c6eef4c17aacbb907df19731cd2f736ddb3ef9b2155f9c4c35416123ffc
3
+ metadata.gz: 55f8b3fd0c640575797c71c95cf9b50f0bd6135c00d7c8568bd65ae25904bca1
4
+ data.tar.gz: edfdac3660867a1cc7216ae65e0205355dfd39ea4642864d02b3d7c86f80ff15
5
5
  SHA512:
6
- metadata.gz: 9a94bc189c1c507fd918d229a020dcdf674e5d7b0ce6cff127e9968d727c514aaecaa1c35d8c1cdd1f722505c7d01bca9fbf5ec187d369528aea35f3120c61b2
7
- data.tar.gz: b67dd26bd7e5a8725051ef657cde914f2b2b6ef00771af08c86c2b04da0762a9df8cb9ea5e58296c74928258e808eb23d88ee27a733c2a5a3a5fabd5bef96d50
6
+ metadata.gz: 1f4bcd8c0046553ed29036eadbf51506e9e4a7be1b4bcbe04b0e8182117877d6c58d98b4a7472ca0e04f3ebed63ea79beb4648819215b8fbd2f84b18dcefe278
7
+ data.tar.gz: 96f2c3f60f6896a16f4d003fa1f4b229d29df8ae527c74cbabe6cc5abdc527fd73c199c4b33b36374af953e2bf7949bb420911f2f3cae640bfd9e7c2d345eb35
data/.rubocop.yml CHANGED
@@ -8,10 +8,4 @@ AllCops:
8
8
  Metrics/MethodLength:
9
9
  Max: 12
10
10
 
11
- Style/StringLiterals:
12
- EnforcedStyle: double_quotes
13
-
14
- Style/StringLiteralsInInterpolation:
15
- EnforcedStyle: double_quotes
16
-
17
11
  require: rubocop-rspec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-09-24
4
+
5
+ * **Improved code quality:**
6
+ * Enforces consistent quoting style with `RuboCop` integration.
7
+ * Removes unused gems (`mini_portile2`) from the `Gemfile`.
8
+ * **Database enhancements:**
9
+ * Adds a new column named "notes" to the `items` table to store additional information about tracked time entries.
10
+ * **Command-line improvements:**
11
+ * 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"`).
12
+ * Improves formatting and clarity of some command descriptions.
13
+ * **General code formatting:**
14
+ * Uses single quotes (`'`) for strings and source paths in the `Gemfile`.
15
+
3
16
  ## [0.1.0] - 2024-08-01
4
17
 
5
18
  - Initial release
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ![timet workflow](https://github.com/frankvielma/timet/actions/workflows/ci.yml/badge.svg)
2
-
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/44d57b6c561b9be717f5/maintainability)](https://codeclimate.com/github/frankvielma/timet/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/44d57b6c561b9be717f5/test_coverage)](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 and add to the application's Gemfile by executing:
36
-
37
- $ bundle add timet
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
- Using timet or tt as an alias is possible
46
-
47
- - **timet start [tag]**: Starts tracking time for a task labeled with the provided [tag]. Example:
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 Time | End Time | Duration |
60
- +-------+--------+---------------------+-------------------+------------+
61
- | 1 | task1 | 2024-08-09 14:55:07 | - | 00:00:00 |
62
- +-------+--------+---------------------+-------------------+------------+
63
- | Total: | 00:00:00 |
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
- ```shell
61
+ ```bash
70
62
  timet stop
71
63
  ```
72
64
 
73
65
  ```
74
- Tracked time report:
75
- +-------+--------+---------------------+---------------------+------------+
76
- | Id | Tag | Start Time | End Time | Duration |
77
- +-------+--------+---------------------+--------------------+-------------+
78
- | 1 | task1 | 2024-08-09 14:55:07 | 2024-08-09 14:56:20 | 00:01:13 |
79
- +-------+--------+---------------------+---------------------+------------+
80
- | Total: | 00:01:13 |
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 Time | End Time | Duration |
89
- +-------+--------+---------------------+--------------------+-------------+
90
- | 2 | task1 | 2024-08-09 16:45:12 | - | 00:00:00 |
91
- | 1 | task1 | 2024-08-09 14:55:07 | 2024-08-09 14:56:20 | 00:01:13 |
92
- +-------+--------+---------------------+---------------------+------------+
93
- | Total: | 00:01:13 |
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
- ```shell
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
- ```shell
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
- ```shell
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
- ```shell
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
- ```shell
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
- ```shell
150
- tt su t --csv=summary_today.csv
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
- ```shell
127
+ ```bash
156
128
  timet delete [id]
157
129
 
158
130
  or
159
131
 
160
- tt d [id]
132
+ timet d [id]
161
133
  ```
162
134
 
163
135
  - **timet cancel**: Cancel active time tracking
164
136
 
165
- ```shell
137
+ ```bash
166
138
  timet cancel
167
139
 
168
140
  or
169
141
 
170
- tt c
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 "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/bin/timet CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../lib/timet"
4
+ require_relative '../lib/timet'
5
5
 
6
6
  Timet::Application.start(ARGV)
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "version"
4
- require "thor"
5
- require "tty-prompt"
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,15 @@ module Timet
12
13
  @db = Timet::Database.new
13
14
  end
14
15
 
15
- desc "start [tag]", "start time tracking"
16
+ desc "start [tag] --notes='...'", "start time tracking --notes='my notes...'"
17
+ option :notes, type: :string, desc: 'Add a note'
16
18
  def start(tag)
17
19
  start = Time.now.to_i
18
- @db.insert_item(start, tag) if %i[no_items complete].include?(@db.last_item_status)
20
+ @db.insert_item(start, tag, options[:notes]) if %i[no_items complete].include?(@db.last_item_status)
19
21
  summary
20
22
  end
21
23
 
22
- desc "stop", "stop time tracking"
24
+ desc 'stop', 'stop time tracking'
23
25
  def stop
24
26
  stop = Time.now.to_i
25
27
  @db.update(stop) if @db.last_item_status == :incomplete
@@ -30,19 +32,19 @@ module Timet
30
32
  summary
31
33
  end
32
34
 
33
- desc "resume (r)", "resume last task"
35
+ desc 'resume (r)', 'resume last task'
34
36
  def resume
35
37
  if @db.last_item_status == :incomplete
36
- puts "A task is currently being tracked."
37
- else
38
- last_task = @db.last_item&.last
39
- start last_task if last_task
38
+ puts 'A task is currently being tracked.'
39
+ elsif (last_task = @db.last_item&.[](3))
40
+ start last_task
40
41
  end
41
42
  end
42
43
 
43
- desc "summary (su) [filter] [tag] --csv=csv_filename",
44
- "Display a summary of tracked time filter => [today (t), yesterday (y), week (w), month (m)] [tag] and export to csv_filename"
45
- option :csv, type: :string, desc: "Export to CSV file"
44
+ desc 'summary (su) [filter] [tag] --csv=csv_filename',
45
+ "Display a summary of tracked time filter => [today (t), yesterday (y), week (w), month (m)] [tag]
46
+ and export to csv_filename"
47
+ option :csv, type: :string, desc: 'Export to CSV file'
46
48
  def summary(filter = nil, tag = nil)
47
49
  csv_filename = options[:csv]
48
50
  summary = TimeReport.new(@db, filter, tag, csv_filename)
@@ -50,21 +52,21 @@ module Timet
50
52
  summary.export_sheet if csv_filename
51
53
  end
52
54
 
53
- desc "delete (d) [id]", "delete a task"
55
+ desc 'delete (d) [id]', 'delete a task'
54
56
  def delete(id)
55
57
  item = @db.find_item(id)
56
58
  return puts "No tracked time found for id: #{id}" unless item
57
59
 
58
60
  TimeReport.new(@db, nil, nil).row(item)
59
- return unless TTY::Prompt.new.yes?("Are you sure you want to delete this entry?")
61
+ return unless TTY::Prompt.new.yes?('Are you sure you want to delete this entry?')
60
62
 
61
63
  delete_item_and_print_message(id, "Deleted #{id}")
62
64
  end
63
65
 
64
- desc "cancel (c)", "cancel active time tracking"
66
+ desc 'cancel (c)', 'cancel active time tracking'
65
67
  def cancel
66
68
  id = @db.fetch_last_id
67
- return puts "There is no active time tracking" if @db.last_item_status == :complete
69
+ return puts 'There is no active time tracking' if @db.last_item_status == :complete
68
70
 
69
71
  delete_item_and_print_message(id, "Canceled active time tracking #{id}")
70
72
  end
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sqlite3"
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, ".timet.db")
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("INSERT INTO items (start, tag) VALUES (?, ?)", [start, tag])
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("UPDATE items SET end = ? WHERE id = ?", [stop, last_id])
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("SELECT id FROM items ORDER BY id DESC LIMIT 1").first
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("SELECT * FROM items ORDER BY id DESC LIMIT 1").first
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("SELECT id, end FROM items ORDER BY id DESC LIMIT 1")
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("SELECT * FROM items ORDER BY id DESC LIMIT 1").first
66
- return "00:00:00" unless last_item
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 "%<hours>02d:%<minutes>02d:%<seconds>02d", hours: hours, minutes: minutes, seconds: seconds
110
+ format '%<hours>02d:%<minutes>02d:%<seconds>02d', hours: hours, minutes: minutes, seconds: seconds
98
111
  end
99
112
  end
100
113
  end
@@ -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("%Y-%m-%d %H:%M:%S").ljust(19) }
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)
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "date"
4
- require "csv"
5
- require_relative "time_helper"
6
- require_relative "status_helper"
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,15 +15,17 @@ module Timet
15
15
  def initialize(db, filter, tag, csv)
16
16
  @db = db
17
17
  @filename = csv
18
- @items = filter ? filter_items(filter, tag) : @db.all_items
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 "No tracked time found for the specified filter." if items.empty?
23
+ return puts 'No tracked time found for the specified filter.' if items.empty?
23
24
 
24
25
  format_table_header
25
- items.each do |item|
26
- display_time_entry(item)
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
@@ -39,13 +41,13 @@ module Timet
39
41
  def export_sheet
40
42
  header = %w[ID Start End Tag]
41
43
 
42
- CSV.open("#{filename}.csv", "w") do |csv|
44
+ CSV.open("#{filename}.csv", 'w') do |csv|
43
45
  csv << header
44
46
 
45
47
  items.each do |row|
46
48
  # Convert start and end times from timestamps to ISO 8601 format
47
- start_time = Time.at(row[1]).strftime("%Y-%m-%d %H:%M:%S")
48
- end_time = Time.at(row[2]).strftime("%Y-%m-%d %H:%M:%S")
49
+ start_time = Time.at(row[1]).strftime('%Y-%m-%d %H:%M:%S')
50
+ end_time = Time.at(row[2]).strftime('%Y-%m-%d %H:%M:%S')
49
51
 
50
52
  # Write the row with formatted times
51
53
  csv << [row[0], start_time, end_time, row[3]]
@@ -55,57 +57,66 @@ module Timet
55
57
 
56
58
  private
57
59
 
58
- def display_time_entry(item)
59
- return puts "Missing time entry data." unless item
60
+ def extract_date(items, idx)
61
+ current_start_date = items[idx][1]
62
+ date = TimeHelper.timestamp_to_date(current_start_date)
60
63
 
61
- id, start_time_value, end_time_value, tag_name = item
64
+ last_start_date = items[idx - 1][1]
65
+ date if idx.zero? || date != TimeHelper.timestamp_to_date(last_start_date)
66
+ end
67
+
68
+ def display_time_entry(item, date)
69
+ return puts 'Missing time entry data.' unless item
70
+
71
+ id, start_time_value, end_time_value, tag_name, notes = item
62
72
  duration = TimeHelper.calculate_duration(start_time_value, end_time_value)
63
73
  start_time = TimeHelper.format_time(start_time_value)
64
- end_time = TimeHelper.format_time(end_time_value) || "-".rjust(19)
65
- puts format_table_row(id, tag_name[0..5], start_time, end_time, duration)
74
+ end_time = TimeHelper.format_time(end_time_value) || '- -'
75
+ start_date = date.nil? ? ' ' * 10 : date
76
+ puts format_table_row(id, tag_name[0..5], start_date, start_time, end_time, duration, notes)
66
77
  end
67
78
 
68
79
  def total
69
80
  total = @items.map do |item|
70
81
  TimeHelper.calculate_duration(item[1], item[2])
71
82
  end.sum
72
- puts "|#{" " * 52}\033[94mTotal: | #{@db.seconds_to_hms(total).rjust(10)} |\033[0m"
83
+ puts "|#{' ' * 43}\033[94mTotal: | #{@db.seconds_to_hms(total).rjust(8)} |\033[0m |"
73
84
  puts format_table_separator
74
85
  end
75
86
 
76
87
  def format_table_header
77
88
  header = <<~TABLE
78
- Tracked time report:
89
+ Tracked time report \u001b[31m[#{@filter}]\033[0m:
79
90
  #{format_table_separator}
80
- \033[32m| Id | Tag | Start Time | End Time | Duration |\033[0m
91
+ \033[32m| Id | Date | Tag | Start | End | Duration | Notes |\033[0m
81
92
  #{format_table_separator}
82
93
  TABLE
83
94
  puts header
84
95
  end
85
96
 
86
97
  def format_table_separator
87
- "+-------+--------+---------------------+---------------------+------------+"
98
+ '+-------+------------+--------+----------+----------+----------+--------------------------+'
88
99
  end
89
100
 
90
101
  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} | #{end_time} | " \
93
- "#{@db.seconds_to_hms(duration).rjust(10)} |"
102
+ id, tag, start_date, start_time, end_time, duration, notes = row
103
+ "| #{id.to_s.rjust(5)} | #{start_date} | #{tag.ljust(6)} | #{start_time.split[1]} | " \
104
+ "#{end_time.split[1].rjust(8)} | #{@db.seconds_to_hms(duration).rjust(8)} | #{format_notes(notes)} |"
94
105
  end
95
106
 
96
107
  def filter_items(filter, tag)
97
108
  today = Date.today
98
109
  case filter
99
- when "today", "t"
110
+ when 'today'
100
111
  filter_by_date_range(today, nil, tag)
101
- when "yesterday", "y"
112
+ when 'yesterday'
102
113
  filter_by_date_range(today - 1, nil, tag)
103
- when "week", "w"
114
+ when 'week'
104
115
  filter_by_date_range(today - 7, today + 1, tag)
105
- when "month", "m"
116
+ when 'month'
106
117
  filter_by_date_range(today - 30, today + 1, tag)
107
118
  else
108
- puts "Invalid filter. Supported filters: today, yesterday, week"
119
+ puts 'Invalid filter. Supported filters: today, yesterday, week'
109
120
  []
110
121
  end
111
122
  end
@@ -118,5 +129,21 @@ module Timet
118
129
  "select * from items where #{query} ORDER BY id DESC"
119
130
  )
120
131
  end
132
+
133
+ def format_notes(notes)
134
+ return ' ' * 23 if notes.nil?
135
+
136
+ notes = "#{notes.slice(0, 20)}..." if notes.length > 20
137
+ notes.ljust(23)
138
+ end
139
+
140
+ def formatted_filter(filter)
141
+ return 'today' if %w[today t].include?(filter)
142
+ return 'yesterday' if %w[yesterday y].include?(filter)
143
+ return 'week' if %w[week w].include?(filter)
144
+ return 'month' if %w[month m].include?(filter)
145
+
146
+ 'today'
147
+ end
121
148
  end
122
149
  end
data/lib/timet/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Timet
4
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/timet.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "timet/application"
4
- require_relative "timet/database"
5
- require_relative "timet/time_report"
3
+ require_relative 'timet/application'
4
+ require_relative 'timet/database'
5
+ require_relative 'timet/time_report'
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.0
4
+ version: 0.2.0
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-22 00:00:00.000000000 Z
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.com/frankvielma/timet/blob/main/README.md
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.com/frankvielma/timet/blob/main/README.md
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.3.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