debian-mirror-gitlab/lib/gitlab/time_tracking_formatter.rb

44 lines
951 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module TimeTrackingFormatter
extend self
2019-12-04 20:38:33 +05:30
# We may want to configure it through project settings in a future version.
CUSTOM_DAY_AND_MONTH_LENGTH = { hours_per_day: 8, days_per_month: 20 }.freeze
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
def parse(string)
string = string.sub(/\A-/, '')
seconds =
begin
ChronicDuration.parse(
string,
CUSTOM_DAY_AND_MONTH_LENGTH.merge(default_unit: 'hours'))
rescue
nil
end
seconds *= -1 if seconds && Regexp.last_match
seconds
2017-08-17 22:00:37 +05:30
end
def output(seconds)
2019-12-04 20:38:33 +05:30
ChronicDuration.output(
seconds,
CUSTOM_DAY_AND_MONTH_LENGTH.merge(
format: :short,
limit_to_hours: limit_to_hours_setting,
weeks: true))
rescue
nil
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
private
def limit_to_hours_setting
Gitlab::CurrentSettings.time_tracking_limit_to_hours
end
2017-08-17 22:00:37 +05:30
end
end