toggl-worktime 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5a66d96dab772480dc7aa6ae5e6a13db341d51723ecd37b3fd83aaa65e1425e
4
- data.tar.gz: 720c1c233f2ae212143f2d4b9abf235253886e5aa1413e7896c42d70e97ba78a
3
+ metadata.gz: 0d7d312022057b262ea569daa0ff5a2d4fd81f515c6c0fbe32d4dbbac1d5f8bd
4
+ data.tar.gz: 2412b9d69c4a482400bde188a1a7523b215c63891f1d7159a7834b257cb673b8
5
5
  SHA512:
6
- metadata.gz: 2f90838428fcd962bb595c185374d7becca5bbef37535ff5227a8d5df23575f08e84550623d1ee1f9adc57df65c7006490af9ba4230f9664269a0ce1e5396e73
7
- data.tar.gz: 171f56fcee2e8c4d0a831f169100f26e5c79b7606bc94fd97ca2d54f06dbfc4e41f9e45edd75de2b4d529a21145d18b6c3e64bcef721754987d7723ceff3086d
6
+ metadata.gz: a643c84a3603192a66519cc95cf40523ff98bb626702608f958b9494b2ec8fd6c5551554c18cfac95ac71099a6936553361263e5471cecd7e0c1c2c4616cd79b
7
+ data.tar.gz: 6f1c575654a741742f3e4efcf438fa0ac89bed10b68b685e2aed44b2e4fe5bbbb292b67ff17dc10fa828acb1c2e133133ac3803cb07812b9f8ccde7d7b444b3c
@@ -10,9 +10,8 @@ Version = Toggl::Worktime::VERSION
10
10
  MAX_WORKING_INTERVAL = 10
11
11
  DAY_BEGIN_HOUR = 6
12
12
  DEFAULT_TIMEZONE = 'Asia/Tokyo'
13
- ONE_DAY_MINUTES = 24 * 60
14
13
 
15
- driver = Toggl::Worktime::Driver.new
14
+ driver = Toggl::Worktime::Driver.new(max_working_interval: MAX_WORKING_INTERVAL)
16
15
 
17
16
  month = ARGV[0].to_i
18
17
  day = ARGV[1].to_i
@@ -7,8 +7,9 @@ module Toggl
7
7
  attr_reader :toggl
8
8
  attr_reader :work_time
9
9
 
10
- def initialize
10
+ def initialize(max_working_interval: 10)
11
11
  @toggl = TogglV8::API.new
12
+ @max_working_interval = max_working_interval
12
13
  @merger = nil
13
14
  @work_time = nil
14
15
  end
@@ -27,7 +28,7 @@ module Toggl
27
28
 
28
29
  def merge!(month, day, hour, timezone)
29
30
  time_entries = time_entries(month, day, hour, timezone)
30
- @merger = Toggl::Worktime::Merger.new(time_entries)
31
+ @merger = Toggl::Worktime::Merger.new(time_entries, timezone, @max_working_interval)
31
32
  @work_time = @merger.merge
32
33
  end
33
34
 
@@ -6,8 +6,12 @@ module Toggl
6
6
  class Merger
7
7
  attr_reader :total_time
8
8
 
9
- def initialize(time_entries)
9
+ ONE_DAY_MINUTES = 24 * 60
10
+
11
+ def initialize(time_entries, timezone, max_working_interval)
10
12
  @time_entries = time_entries
13
+ @timezone = timezone
14
+ @max_working_interval = max_working_interval
11
15
  @current_start = nil
12
16
  @current_stop = nil
13
17
  @continuing = true
@@ -31,14 +35,18 @@ module Toggl
31
35
  end
32
36
 
33
37
  def time_entries_each
34
- zone_offset = Toggl::Worktime::Time.zone_offset(DEFAULT_TIMEZONE)
38
+ zone_offset = Toggl::Worktime::Time.zone_offset(@timezone)
35
39
  @time_entries.each do |te|
36
40
  start = parse_date(te['start'], zone_offset)
37
41
  stop = parse_date(te['stop'], zone_offset)
38
42
  @last_stop = stop
39
43
  @current_start = start if @current_start.nil?
40
44
  @current_stop = stop if @current_stop.nil?
41
- @total_time += stop - start
45
+ if start.nil? || stop.nil?
46
+ warn "start or stop time is nil: total time may be incomplete"
47
+ else
48
+ @total_time += stop - start
49
+ end
42
50
  yield [start, stop]
43
51
  end
44
52
  end
@@ -49,8 +57,9 @@ module Toggl
49
57
  end
50
58
 
51
59
  def continuing(start)
60
+ return true if @current_stop.nil?
52
61
  interval = (start - @current_stop) * ONE_DAY_MINUTES
53
- @continuing = interval < MAX_WORKING_INTERVAL
62
+ @continuing = interval < @max_working_interval
54
63
  end
55
64
  end
56
65
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Toggl
4
4
  module Worktime
5
- VERSION = '0.1.8'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggl-worktime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoya KABE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-01 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: togglv8