Module: Gitlab::TimeTrackingFormatter

Extended by:
TimeTrackingFormatter
Included in:
TimeTrackingFormatter
Defined in:
lib/gitlab/time_tracking_formatter.rb

Constant Summary collapse

CUSTOM_DAY_AND_MONTH_LENGTH =

We may want to configure it through project settings in a future version.

{ hours_per_day: 8, days_per_month: 20 }.freeze

Instance Method Summary collapse

Instance Method Details

#output(seconds) ⇒ Object



32
33
34
# File 'lib/gitlab/time_tracking_formatter.rb', line 32

def output(seconds)
  seconds.to_i < 0 ? negative_output(seconds) : positive_output(seconds)
end

#parse(string, keep_zero: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/time_tracking_formatter.rb', line 10

def parse(string, keep_zero: false)
  return unless string

  negative_time = string.start_with?('-')
  string = string.delete_prefix('-')

  seconds =
    begin
      ChronicDuration.parse(
        string,
        CUSTOM_DAY_AND_MONTH_LENGTH.merge(
          default_unit: 'hours', keep_zero: keep_zero,
          use_complete_matcher: true
        ))
    rescue StandardError
      nil
    end

  seconds *= -1 if seconds && negative_time
  seconds
end