totaltime 0.1.3 → 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 +4 -4
- data/bin/totaltime +1 -1
- data/lib/cli.rb +2 -1
- data/lib/duration.rb +47 -15
- data/lib/parser.rb +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dfb8c01349f144eb6c3174d88e17189b0ffa14c541f5348c0afee0d5ab727d42
|
|
4
|
+
data.tar.gz: 1903a9ba6ccc5c37c1d397ba18fd9fdf5cb84725de663ac0b68d357ad5d9e0fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9099a30045368857fe64714178a256bd46a74d1ca97be7772090e3c75cd050b3d52ea1b4154024e3ee5e4bb4efcbf670ff7a614db5b5f8e6c4780152fd338ef3
|
|
7
|
+
data.tar.gz: 920c993d45f1b63b45027de0ed8720ad20700207a2653a7459796c5b38915f82972d194eba5f0cf22317bfac467db446f485e68e7c6f083f2c0de8ef94c4dc4e
|
data/bin/totaltime
CHANGED
data/lib/cli.rb
CHANGED
data/lib/duration.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require "time"
|
|
2
|
+
|
|
1
3
|
class Duration
|
|
2
4
|
attr_accessor :hours, :minutes
|
|
3
5
|
|
|
@@ -20,6 +22,10 @@ class Duration
|
|
|
20
22
|
Duration.new(newHours, newMinutes)
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
def total_minutes()
|
|
26
|
+
return @hours * 60 + @minutes
|
|
27
|
+
end
|
|
28
|
+
|
|
23
29
|
def self.try_convert(str)
|
|
24
30
|
floatValue = Float(str, exception: false)
|
|
25
31
|
if floatValue
|
|
@@ -31,21 +37,47 @@ class Duration
|
|
|
31
37
|
return newDuration if newDuration.valid?
|
|
32
38
|
end
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
if str.include?("-")
|
|
41
|
+
times = str.split("-")
|
|
42
|
+
times.map! { |t| t + (t.include?(":") ? "" : ":00") }
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
startTime = Time.parse(times[0])
|
|
46
|
+
endTime = Time.parse(times[1])
|
|
47
|
+
rescue
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
minutesBetween = Integer((endTime - startTime) / 60, exception: false)
|
|
52
|
+
return unless minutesBetween != nil
|
|
53
|
+
|
|
54
|
+
parsedHours = minutesBetween / 60
|
|
55
|
+
parsedMinutes = minutesBetween % 60
|
|
56
|
+
|
|
57
|
+
newDuration = Duration.new(parsedHours, parsedMinutes)
|
|
58
|
+
if newDuration.valid? then newDuration else nil end
|
|
59
|
+
else
|
|
60
|
+
parts=str.split(":")
|
|
61
|
+
return unless parts.length == 2
|
|
62
|
+
|
|
63
|
+
parsedHours = Integer(parts[0], exception: false)
|
|
64
|
+
parsedMinutes = Integer(parts[1], exception: false)
|
|
65
|
+
|
|
66
|
+
return if parsedMinutes == nil
|
|
67
|
+
parsedHours = 0 if parsedHours == nil
|
|
68
|
+
parsedHours = parsedHours + (parsedMinutes / 60)
|
|
69
|
+
|
|
70
|
+
parsedMinutes = parsedMinutes % 60
|
|
71
|
+
|
|
72
|
+
newDuration = Duration.new(parsedHours, parsedMinutes)
|
|
73
|
+
if newDuration.valid? then newDuration else nil end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.from_minutes(mins)
|
|
78
|
+
newMinutes = mins % 60
|
|
79
|
+
newHours = mins / 60
|
|
80
|
+
Duration.new(newHours, newMinutes)
|
|
49
81
|
end
|
|
50
82
|
|
|
51
83
|
def to_s
|
data/lib/parser.rb
ADDED
|
File without changes
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: totaltime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- NikxDa
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-09-
|
|
11
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A beautiful timesheet calculator for the command line
|
|
14
14
|
email: ''
|
|
@@ -20,6 +20,7 @@ files:
|
|
|
20
20
|
- bin/totaltime
|
|
21
21
|
- lib/cli.rb
|
|
22
22
|
- lib/duration.rb
|
|
23
|
+
- lib/parser.rb
|
|
23
24
|
homepage: https://rubygems.org/gems/totaltime
|
|
24
25
|
licenses:
|
|
25
26
|
- MIT
|