timet 0.8.2 → 0.9.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: 5eda40ea4aafce60dc6fef1270ca9d013724c45b29ba43e7974b8212f55ac231
4
- data.tar.gz: b5a45e366bbfdb073ccf32ad545b572faac79f018c3a6f8eac60622aed96b02b
3
+ metadata.gz: 74f9106fb9a60ccd2e2446a58350d3de263459df41ffdf1aa57ca62d267da985
4
+ data.tar.gz: 77de65d76048301e01e0fb1607862ead7e69ead1647546974ac48b027222b73b
5
5
  SHA512:
6
- metadata.gz: 0d0cc2dfa64d2af724b2be8543d67f63f5485c4fe81746a29cea29db9b51d1ba5fcf4df98f7cdadb16961f30cd24dff0e65bef93c6f297fe9b61bc9a07b0e15e
7
- data.tar.gz: fdd6364f4dad16defed0c484eb29adf27479427387be6cd43587bcdbfb628eea2a99a0712c708a5821e50e1064c476b2481cd2efc49cb302d533b0d632c3f08a
6
+ metadata.gz: 409da2fabebd3071832c3c67498015a358cf973e9a41da970969aee97e53e779c8372e9c72c3dad835020644cf163be0138097337ca5589343f3f2364d2d177f
7
+ data.tar.gz: 537cd9eeba10e3bd43246d3c92f736b91ce171568437e15a22b0a0460171185cc5482f3b45348ef759b4daebb016d59126205f2192a168e618f0445b4384b88b
data/CHANGELOG.md CHANGED
@@ -1,23 +1,59 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.0] - 2024-10-03
4
+
5
+ **Improvements:**
6
+
7
+ - Enhanced the gemspec metadata by adding a documentation URI for better discoverability and reference.
8
+ - Improved the `summary` and `edit` methods for better readability and functionality.
9
+ - Simplified the `summary` method by using safe navigation operators and improved conditional checks.
10
+ - Modified the `edit` method to use the return value of `validate_and_update` for displaying the updated item.
11
+ - Updated the `validate_and_update` method to return the updated item after performing the update.
12
+ - Enhanced the `TimeReport` class and added comprehensive RSpec tests.
13
+ - Enhanced the `filter_items` method to support valid date range filters.
14
+ - Added a `valid_date_format?` method to validate date formats.
15
+ - Updated the `formatted_filter` method to handle valid date range filters.
16
+ - Removed the `helpers.rb` file as it was no longer needed.
17
+ - Added comprehensive RSpec tests for the `TimeReport` class, covering initialization, filtering, and date format validation.
18
+ - Modified the `stop` method in `Timet::Application` to use the `update_item` method from `Database` instead of the deprecated `update` method.
19
+ - Updated the `stop` method to fetch the last item's ID and update the 'end' field directly.
20
+ - Updated test cases in `application_spec.rb` to reflect the changes in the `stop` method.
21
+ - Removed test cases for the deprecated `update` method in `database_spec.rb`.
22
+
23
+ **Bug fixes:**
24
+
25
+ - Fix bug in calculate_end_time method
26
+
27
+ **Additional Considerations:**
28
+
29
+ - The changes in this PR aim to improve code quality, maintainability, and test coverage.
30
+ - The removal of the `helpers.rb` file and unused methods helps to streamline the codebase and reduce technical debt.
31
+ - The updated `stop` method now uses the `update_item` method, ensuring consistency across the codebase.
32
+ - Comprehensive tests have been added for the `TimeReport` class to ensure robust functionality and prevent regressions.
33
+
3
34
  ## [0.8.2] - 2024-10-02
4
35
 
5
36
  **Improvements:**
37
+
6
38
  - Added optional field and new_value parameters to the edit command.
7
39
  - Updated the edit method logic to prompt for field and new_value if they are not provided.
8
40
  - Enhanced test coverage to include scenarios where field and new_value are provided directly and when they are not.
9
41
  - Updated the README to reflect the new features of the edit command, including both interactive and direct specification modes.
10
42
 
11
43
  **Additional Considerations:**
44
+
12
45
  - The changes ensure that the edit command is more versatile and user-friendly, catering to both interactive users and those who prefer scripting or automation.
13
46
 
14
47
  ## [0.8.1] - 2024-10-02
48
+
15
49
  **Bug fixes:**
16
- - Fixed a LoadError caused by the byebug gem being required after its removal.
50
+
51
+ - Fixed a LoadError caused by the byebug gem being required after its removal.
17
52
 
18
53
  ## [0.8.0] - 2024-10-01
19
54
 
20
55
  **Improvements:**
56
+
21
57
  - Introduced TimeHelper module to encapsulate time-related functionalities.
22
58
  - Replaced direct calls to Time.now.to_i with TimeHelper.current_timestamp for consistency and modularity.
23
59
  - Moved current_timestamp method to TimeHelper to centralize time-related logic.
@@ -50,6 +86,7 @@
50
86
  - Added a confirmation message when the CSV file is successfully exported.
51
87
 
52
88
  **Bug fixes:**
89
+
53
90
  - Updated timestamp_to_time method to return nil if the input timestamp is nil.
54
91
  - Removed unnecessary &.then syntax for clarity and consistency.
55
92
  - Corrected the test expectations to use the correct Unix timestamp.
@@ -61,6 +98,7 @@
61
98
  - Added validation to prevent updating start or end times with nil values.
62
99
 
63
100
  **Tasks:**
101
+
64
102
  - Added ENV['TZ'] = 'UTC' to spec_helper.rb to ensure that all RSpec tests run in the UTC time zone.
65
103
  - Updated tests to reflect the new structure and ensure items are returned for export.
66
104
  - Updated and added tests to cover the new export logic.
@@ -78,6 +116,7 @@
78
116
  - Updated database_spec.rb to reflect the correct status for in-progress items.
79
117
 
80
118
  **Additional Considerations:**
119
+
81
120
  - Ensured that all timestamps are handled in UTC to avoid timezone issues across different environments.
82
121
  - Updated the test to reflect the correct UTC time zone.
83
122
  - Ensured consistency in timestamp handling across methods.
@@ -85,6 +124,7 @@
85
124
  - Made the application easier to maintain and extend in the future.
86
125
 
87
126
  **Refactor and enhance time formatting methods**
127
+
88
128
  - Refactored `format_time_string` method in `TimeHelper` to improve readability and maintainability.
89
129
  - Added detailed documentation for the `format_time_string` method.
90
130
  - Simplified the logic for parsing and validating time components.
@@ -96,31 +136,30 @@
96
136
 
97
137
  ## [0.2.2] - 2024-09-27
98
138
 
99
- * **Improvements**:
100
- * Updated SQLite3 gem version to 2.1.0
139
+ - **Improvements**:
140
+ - Updated SQLite3 gem version to 2.1.0
101
141
 
102
142
  ## [0.2.1] - 2024-09-24
103
143
 
104
- * **Improved `resume` behavior:**
105
- * If no notes are provided, it will attempt to retrieve them from the last tracked task.
106
- * **Enhanced `export_sheet` functionality:**
107
- * A new `notes` column has been added to the exported CSV file.
108
- * **Minor bug fixes:**
109
- * Resolved issues related to resuming tasks with notes and deleting items.
110
-
144
+ - **Improved `resume` behavior:**
145
+ - If no notes are provided, it will attempt to retrieve them from the last tracked task.
146
+ - **Enhanced `export_sheet` functionality:**
147
+ - A new `notes` column has been added to the exported CSV file.
148
+ - **Minor bug fixes:**
149
+ - Resolved issues related to resuming tasks with notes and deleting items.
111
150
 
112
151
  ## [0.2.0] - 2024-09-24
113
152
 
114
- * **Improved code quality:**
115
- * Enforces consistent quoting style with `RuboCop` integration.
116
- * Removes unused gems (`mini_portile2`) from the `Gemfile`.
117
- * **Database enhancements:**
118
- * Adds a new column named "notes" to the `items` table to store additional information about tracked time entries.
119
- * **Command-line improvements:**
120
- * 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"`).
121
- * Improves formatting and clarity of some command descriptions.
122
- * **General code formatting:**
123
- * Uses single quotes (`'`) for strings and source paths in the `Gemfile`.
153
+ - **Improved code quality:**
154
+ - Enforces consistent quoting style with `RuboCop` integration.
155
+ - Removes unused gems (`mini_portile2`) from the `Gemfile`.
156
+ - **Database enhancements:**
157
+ - Adds a new column named "notes" to the `items` table to store additional information about tracked time entries.
158
+ - **Command-line improvements:**
159
+ - 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"`).
160
+ - Improves formatting and clarity of some command descriptions.
161
+ - **General code formatting:**
162
+ - Uses single quotes (`'`) for strings and source paths in the `Gemfile`.
124
163
 
125
164
  ## [0.1.0] - 2024-08-01
126
165
 
data/README.md CHANGED
@@ -150,6 +150,25 @@ gem install timet
150
150
  | `timet delete [id]` | Delete a task by its ID. | `timet d [id]` |
151
151
  | `timet cancel` | Cancel active time tracking. | `timet c` |
152
152
  | `timet edit [id]` | Update a task's notes, tag, start or end fields. | `timet e [1]` |
153
+ | `timet su [date]` | Display a report of tracked time for a specific date. | `timet su 2024-01-03` |
154
+ | `timet su [start_date]..[end_date]` | Display a report of tracked time for a date range. | `timet su 2024-01-02..2024-01-03` |
155
+
156
+
157
+
158
+ ### Date Range in Summary
159
+
160
+ The `timet summary` command now supports specifying a date range for generating reports. This allows users to filter and summarize data within specific date intervals. The date format is in ISO 8601 format (YYYY-MM-DD).
161
+
162
+ #### Examples:
163
+ - **Single Date**: Display a report for a specific date.
164
+ ```sh
165
+ timet su 2024-01-03
166
+ ```
167
+
168
+ - **Date Range**: Display a report for a date range.
169
+ ```sh
170
+ timet su 2024-01-02..2024-01-03
171
+ ```
153
172
 
154
173
 
155
174
  ## Data
@@ -22,7 +22,7 @@ module Timet
22
22
 
23
23
  def initialize(*args)
24
24
  super
25
- @db = Timet::Database.new
25
+ @db = Database.new
26
26
  end
27
27
 
28
28
  FIELD_INDEX = {
@@ -34,7 +34,7 @@ module Timet
34
34
 
35
35
  VALID_STATUSES_FOR_INSERTION = %i[no_items complete].freeze
36
36
 
37
- desc "start [tag] --notes='...'", "start time tracking --notes='my notes...'"
37
+ desc "start [tag] --notes=''", "start time tracking --notes='my notes...'"
38
38
  option :notes, type: :string, desc: 'Add a note'
39
39
  def start(tag, notes = nil)
40
40
  start_time = TimeHelper.current_timestamp
@@ -46,8 +46,10 @@ module Timet
46
46
 
47
47
  desc 'stop', 'stop time tracking'
48
48
  def stop
49
- stop = TimeHelper.current_timestamp
50
- @db.update(stop) if @db.last_item_status == :in_progress
49
+ if @db.last_item_status == :in_progress
50
+ last_id = @db.fetch_last_id
51
+ @db.update_item(last_id, 'end', TimeHelper.current_timestamp)
52
+ end
51
53
  result = @db.last_item
52
54
 
53
55
  return unless result
@@ -73,16 +75,17 @@ module Timet
73
75
  end
74
76
 
75
77
  desc 'summary (su) [filter] [tag] --csv=csv_filename',
76
- "Display a summary of tracked time filter => [today (t), yesterday (y), week (w), month (m)] [tag]
77
- and export to csv_filename"
78
+ ' [filter] => [today (t), yesterday (y), week (w), month (m), [start_date]..[end_date]] [tag]'
78
79
  option :csv, type: :string, desc: 'Export to CSV file'
79
80
  def summary(filter = nil, tag = nil)
80
- csv_filename = options[:csv].split('.')[0] if options[:csv]
81
+ csv_filename = options[:csv]&.split('.')&.first
81
82
  summary = TimeReport.new(@db, filter, tag, csv_filename)
83
+
82
84
  summary.display
83
- if csv_filename && summary.items.any?
85
+ items = summary.items
86
+ if csv_filename && items.any?
84
87
  summary.export_sheet
85
- elsif summary.items.empty?
88
+ elsif items.empty?
86
89
  puts 'No items found to export'
87
90
  end
88
91
  end
@@ -99,9 +102,8 @@ module Timet
99
102
  new_value = prompt_for_new_value(item, field)
100
103
  end
101
104
 
102
- validate_and_update(item, field, new_value)
103
-
104
- summary.display
105
+ updated_item = validate_and_update(item, field, new_value)
106
+ display_item(updated_item)
105
107
  end
106
108
 
107
109
  desc 'delete (d) [id]', 'delete a task'
@@ -42,24 +42,16 @@ module Timet
42
42
  execute_sql('INSERT INTO items (start, tag, notes) VALUES (?, ?, ?)', [start, tag, notes])
43
43
  end
44
44
 
45
- # Updates the end time of the last item
46
- def update(stop)
47
- last_id = fetch_last_id
48
- return unless last_id
45
+ def update_item(id, field, value)
46
+ return if %w[start end].include?(field) && value.nil?
49
47
 
50
- execute_sql('UPDATE items SET end = ? WHERE id = ?', [stop, last_id])
48
+ execute_sql("UPDATE items SET #{field}='#{value}' WHERE id = #{id}")
51
49
  end
52
50
 
53
51
  def delete_item(id)
54
52
  execute_sql("DELETE FROM items WHERE id = #{id}")
55
53
  end
56
54
 
57
- def update_item(id, field, value)
58
- return if %w[start end].include?(field) && value.nil?
59
-
60
- execute_sql("UPDATE items SET #{field}='#{value}' WHERE id = #{id}")
61
- end
62
-
63
55
  # Fetches the ID of the last inserted item
64
56
  def fetch_last_id
65
57
  result = execute_sql('SELECT id FROM items ORDER BY id DESC LIMIT 1').first
@@ -79,18 +71,6 @@ module Timet
79
71
  execute_sql("select * from items where id=#{id}").first
80
72
  end
81
73
 
82
- # Calculates the total time elapsed since the last recorded time.
83
- def total_time
84
- last_item = execute_sql('SELECT * FROM items ORDER BY id DESC LIMIT 1').first
85
- return '00:00:00' unless last_item
86
-
87
- start_time = last_item[1]
88
- end_time = last_item[2]
89
-
90
- total_seconds = end_time ? end_time - start_time : TimeHelper.current_timestamp - start_time
91
- seconds_to_hms(total_seconds)
92
- end
93
-
94
74
  def all_items
95
75
  execute_sql("SELECT * FROM items where start >= '#{Date.today.to_time.to_i}' ORDER BY id DESC")
96
76
  end
@@ -35,7 +35,7 @@ module Timet
35
35
  end
36
36
 
37
37
  def self.calculate_end_time(start_date, end_date)
38
- end_date ||= start_date + 1
38
+ end_date = end_date ? end_date + 1 : start_date + 1
39
39
  date_to_timestamp(end_date)
40
40
  end
41
41
 
@@ -92,6 +92,9 @@ module Timet
92
92
  if date_ranges.key?(filter)
93
93
  start_date, end_date = date_ranges[filter]
94
94
  filter_by_date_range(start_date, end_date, tag)
95
+ elsif valid_date_format?(filter)
96
+ start_date, end_date = filter.split('..').map { |x| Date.parse(x) }
97
+ filter_by_date_range(start_date, end_date, tag)
95
98
  else
96
99
  puts 'Invalid filter. Supported filters: today, yesterday, week, month'
97
100
  []
@@ -118,12 +121,27 @@ module Timet
118
121
  end
119
122
 
120
123
  def formatted_filter(filter)
121
- return 'today' if %w[today t].include?(filter)
122
- return 'yesterday' if %w[yesterday y].include?(filter)
123
- return 'week' if %w[week w].include?(filter)
124
- return 'month' if %w[month m].include?(filter)
124
+ filter_map = {
125
+ 'today' => %w[today t],
126
+ 'yesterday' => %w[yesterday y],
127
+ 'week' => %w[week w],
128
+ 'month' => %w[month m]
129
+ }
130
+
131
+ filter_map.each do |key, values|
132
+ return key if values.include?(filter)
133
+ end
134
+
135
+ return filter if filter && valid_date_format?(filter)
125
136
 
126
137
  'today'
127
138
  end
139
+
140
+ def valid_date_format?(date_string)
141
+ date_format_single = /^\d{4}-\d{2}-\d{2}$/
142
+ date_format_range = /^\d{4}-\d{2}-\d{2}\.\.\d{4}-\d{2}-\d{2}$/
143
+
144
+ date_string.match?(date_format_single) || date_string.match?(date_format_range)
145
+ end
128
146
  end
129
147
  end
@@ -18,6 +18,8 @@ module Timet
18
18
  else
19
19
  @db.update_item(id, field, new_value)
20
20
  end
21
+
22
+ @db.find_item(id)
21
23
  end
22
24
 
23
25
  private
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.8.2'
4
+ VERSION = '0.9.0'
5
5
  end
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.8.2
4
+ version: 0.9.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-10-02 00:00:00.000000000 Z
11
+ date: 2024-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -93,6 +93,7 @@ metadata:
93
93
  homepage_uri: https://frankvielma.github.io/posts/timet-a-powerful-command-line-tool-for-tracking-your-time/
94
94
  source_code_uri: https://github.com/frankvielma/timet
95
95
  changelog_uri: https://github.com/frankvielma/timet/blob/main/CHANGELOG.md
96
+ documentation_uri: https://rubydoc.info/gems/timet
96
97
  rubygems_mfa_required: 'true'
97
98
  post_install_message:
98
99
  rdoc_options: []