0f3c9355c1
New endpoints are: POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/time_estimate" POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/reset_time_estimate" POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/add_spent_time" POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/reset_spent_time" GET :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/time_stats"
34 lines
814 B
Ruby
34 lines
814 B
Ruby
module Gitlab
|
|
module TimeTrackingFormatter
|
|
extend self
|
|
|
|
def parse(string)
|
|
with_custom_config do
|
|
string.sub!(/\A-/, '')
|
|
|
|
seconds = ChronicDuration.parse(string, default_unit: 'hours') rescue nil
|
|
seconds *= -1 if seconds && Regexp.last_match
|
|
seconds
|
|
end
|
|
end
|
|
|
|
def output(seconds)
|
|
with_custom_config do
|
|
ChronicDuration.output(seconds, format: :short, limit_to_hours: false, weeks: true) rescue nil
|
|
end
|
|
end
|
|
|
|
def with_custom_config
|
|
# We may want to configure it through project settings in a future version.
|
|
ChronicDuration.hours_per_day = 8
|
|
ChronicDuration.days_per_week = 5
|
|
|
|
result = yield
|
|
|
|
ChronicDuration.hours_per_day = 24
|
|
ChronicDuration.days_per_week = 7
|
|
|
|
result
|
|
end
|
|
end
|
|
end
|