Skip to content

Commit

Permalink
exit early when no timezone is stored
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Nov 25, 2024
1 parent bf60bf6 commit 16c2577
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/costs/app/models/time_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ def costs_visible_by?(usr)

def start_timestamp
return nil if start_time.blank?
return nil if time_zone.blank?

ActiveSupport::TimeZone[time_zone].local(spent_on.year, spent_on.month, spent_on.day, start_time / 60, start_time % 60)
end

Check notice on line 129 in modules/costs/app/models/time_entry.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] modules/costs/app/models/time_entry.rb#L124-L129 <Metrics/AbcSize>

Assignment Branch Condition size for start_timestamp is too high. [<0, 17, 2> 17.12/17]
Raw output
modules/costs/app/models/time_entry.rb:124:3: C: Metrics/AbcSize: Assignment Branch Condition size for start_timestamp is too high. [<0, 17, 2> 17.12/17]

def end_timestamp
return nil if end_time.blank?
return nil if time_zone.blank?

ActiveSupport::TimeZone[time_zone].local(spent_on.year, spent_on.month, spent_on.day, end_time / 60, end_time % 60)
end

Check notice on line 136 in modules/costs/app/models/time_entry.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] modules/costs/app/models/time_entry.rb#L131-L136 <Metrics/AbcSize>

Assignment Branch Condition size for end_timestamp is too high. [<0, 17, 2> 17.12/17]
Raw output
modules/costs/app/models/time_entry.rb:131:3: C: Metrics/AbcSize: Assignment Branch Condition size for end_timestamp is too high. [<0, 17, 2> 17.12/17]
Expand Down
10 changes: 10 additions & 0 deletions modules/costs/spec/models/time_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@ def ensure_membership(project, user, permissions)
expect(time_entry.start_timestamp).to be_nil
end

it "returns nil if timezone is nil" do
time_entry.time_zone = nil
expect(time_entry.start_timestamp).to be_nil
end

it "generates a proper timestamp from the stored information" do
time_entry.start_time = 14 * 60
time_entry.spent_on = Date.new(2024, 12, 24)
Expand All @@ -515,6 +520,11 @@ def ensure_membership(project, user, permissions)
expect(time_entry.end_timestamp).to be_nil
end

it "returns nil if timezone is nil" do
time_entry.time_zone = nil
expect(time_entry.end_timestamp).to be_nil
end

it "generates a proper timestamp from the stored information" do
time_entry.end_time = 14 * 60
time_entry.spent_on = Date.new(2024, 12, 24)
Expand Down

0 comments on commit 16c2577

Please sign in to comment.