Skip to content

Commit 9125a14

Browse files
authored
[50] bug convert to clocktime with wrong response when more than 1 day (#51)
* [50] Bump gemfile with Ruby 3.4.2 * [50] Adjust converter to clocktime method to handle results bigger than 1 day * [50] Change Ruby version to 3.4.2 * [50] Update Readme to 1.5.2 version * [50] Remove unused require of bigdecimal * [50] Rubocop lint * [50] Update gemspec to version 1.5.2
1 parent feb7f40 commit 9125a14

File tree

8 files changed

+27
-20
lines changed

8 files changed

+27
-20
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.1
1+
3.4.2

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
ruby '3.2.1'
5+
ruby '3.4.2'
66

77
gem 'minitest', '~> 5.25'
88
gem 'rake', '~> 13.2'

Gemfile.lock

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,41 @@ GEM
33
specs:
44
ast (2.4.2)
55
date (3.4.1)
6-
json (2.9.1)
7-
language_server-protocol (3.17.0.3)
6+
json (2.10.1)
7+
language_server-protocol (3.17.0.4)
8+
lint_roller (1.1.0)
89
minitest (5.25.4)
910
parallel (1.26.3)
10-
parser (3.3.6.0)
11+
parser (3.3.7.1)
1112
ast (~> 2.4.1)
1213
racc
13-
psych (5.2.2)
14+
psych (5.2.3)
1415
date
1516
stringio
1617
racc (1.8.1)
1718
rainbow (3.1.1)
1819
rake (13.2.1)
1920
rake-compiler (1.2.9)
2021
rake
21-
rdoc (6.10.0)
22+
rdoc (6.12.0)
2223
psych (>= 4.0.0)
2324
regexp_parser (2.10.0)
24-
rubocop (1.69.2)
25+
rubocop (1.73.2)
2526
json (~> 2.3)
26-
language_server-protocol (>= 3.17.0)
27+
language_server-protocol (~> 3.17.0.2)
28+
lint_roller (~> 1.1.0)
2729
parallel (~> 1.10)
2830
parser (>= 3.3.0.2)
2931
rainbow (>= 2.2.2, < 4.0)
3032
regexp_parser (>= 2.9.3, < 3.0)
31-
rubocop-ast (>= 1.36.2, < 2.0)
33+
rubocop-ast (>= 1.38.0, < 2.0)
3234
ruby-progressbar (~> 1.7)
3335
unicode-display_width (>= 2.4.0, < 4.0)
34-
rubocop-ast (1.37.0)
36+
rubocop-ast (1.38.1)
3537
parser (>= 3.3.1.0)
3638
ruby-progressbar (1.13.0)
37-
stringio (3.1.2)
38-
unicode-display_width (3.1.3)
39+
stringio (3.1.5)
40+
unicode-display_width (3.1.4)
3941
unicode-emoji (~> 4.0, >= 4.0.4)
4042
unicode-emoji (4.0.4)
4143

@@ -50,7 +52,7 @@ DEPENDENCIES
5052
rubocop (~> 1.69)
5153

5254
RUBY VERSION
53-
ruby 3.2.1p31
55+
ruby 3.4.2p28
5456

5557
BUNDLED WITH
5658
2.5.10

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Calcpace [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&r=r&ts=1683906897&type=6e&v=1.5.1&x2=0)](https://badge.fury.io/rb/calcpace)
1+
# Calcpace [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&r=r&ts=1683906897&type=6e&v=1.5.2&x2=0)](https://badge.fury.io/rb/calcpace)
22

33
Calcpace is a Ruby gem designed for calculations and conversions related to distance and time. It can calculate velocity, pace, total time, and distance, accepting time in various formats, including HH:MM:SS. The gem supports conversion to 42 different units, including kilometers, miles, meters, and feet. It also provides methods to validate input.
44

@@ -7,7 +7,7 @@ Calcpace is a Ruby gem designed for calculations and conversions related to dist
77
### Add to your Gemfile
88

99
```ruby
10-
gem 'calcpace', '~> 1.5.1'
10+
gem 'calcpace', '~> 1.5.2'
1111
```
1212

1313
Then run:
@@ -134,6 +134,7 @@ Calcpace also provides other useful methods:
134134
converter = Calcpace.new
135135
converter.convert_to_seconds('01:00:00') # => 3600
136136
converter.convert_to_clocktime(3600) # => '01:00:00'
137+
converter.converto_to_clocktime(100000) # => '1 03:46:40'
137138
converter.check_time('01:00:00') # => nil
138139
```
139140

calcpace.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |s|
44
s.name = 'calcpace'
5-
s.version = '1.5.1'
5+
s.version = '1.5.2'
66
s.summary = 'Calcpace: calculate total, distance, speed, and convert distances and velocity in an easy way.'
77
s.description = 'It is designed for calculations related to distance, speed and time. The gem also supports conversion to 42 different units of distance and velocity, including metric, nautical and imperial units.'
88
s.authors = ['Joao Gilberto Saraiva']

lib/calcpace/converter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def convert_to_seconds(time)
6262
end
6363

6464
def convert_to_clocktime(seconds)
65-
format = seconds >= 86_400 ? '%d %H:%M:%S' : '%H:%M:%S'
66-
Time.at(seconds.to_i).utc.strftime(format)
65+
days = seconds / 86_400
66+
format = days.to_i.positive? ? "#{days} %H:%M:%S" : '%H:%M:%S'
67+
Time.at(seconds).utc.strftime(format)
6768
end
6869

6970
def constant(symbol)

test/calcpace/test_calculator.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require 'minitest/autorun'
4-
require 'bigdecimal'
54
require_relative '../../lib/calcpace'
65

76
class TestCalculator < Minitest::Test

test/calcpace/test_converter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def test_convert_to_clocktime
1616
assert_equal '01:11:02', @checker.convert_to_clocktime(4262)
1717
end
1818

19+
def test_convert_to_clocktime_more_than_24_hours
20+
assert_equal '1 03:46:40', @checker.convert_to_clocktime(100_000)
21+
end
22+
1923
def test_convert_distance_one
2024
assert_equal 0.621371, @checker.convert(1, :km_to_mi)
2125
assert_equal 1.60934, @checker.convert(1, :mi_to_km)

0 commit comments

Comments
 (0)