diff options
author | Ruben Davila <rdavila84@gmail.com> | 2016-12-23 08:44:02 +0300 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2017-01-15 19:10:04 +0300 |
commit | 17196a2ff31c4eb65fa9ecff6f7208171e26059b (patch) | |
tree | e9a491799b764c42f3c0c20cb33fa763ebb520df /lib | |
parent | 64dd41a0e21360c380cab394f8a5c9b4945b7fd1 (diff) |
Backport backend work for time tracking.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/import_export/import_export.yml | 2 | ||||
-rw-r--r-- | lib/gitlab/time_tracking_formatter.rb | 30 |
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml index e6ecd118609..08ad3274b38 100644 --- a/lib/gitlab/import_export/import_export.yml +++ b/lib/gitlab/import_export/import_export.yml @@ -6,6 +6,7 @@ project_tree: - :events - issues: - :events + - :timelogs - notes: - :author - :events @@ -27,6 +28,7 @@ project_tree: - :events - :merge_request_diff - :events + - :timelogs - label_links: - label: :priorities diff --git a/lib/gitlab/time_tracking_formatter.rb b/lib/gitlab/time_tracking_formatter.rb new file mode 100644 index 00000000000..d09063c6c8f --- /dev/null +++ b/lib/gitlab/time_tracking_formatter.rb @@ -0,0 +1,30 @@ +module Gitlab + module TimeTrackingFormatter + extend self + + def parse(string) + with_custom_config do + ChronicDuration.parse(string, default_unit: 'hours') rescue nil + 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 |