]> source.dussan.org Git - redmine.git/commitdiff
Extract @Shell@ and @DateCalculation@ classes from @lib/redmine/utils.rb@ to their...
authorMarius Balteanu <marius.balteanu@zitec.com>
Sun, 24 Oct 2021 10:45:24 +0000 (10:45 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sun, 24 Oct 2021 10:45:24 +0000 (10:45 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21260 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/utils.rb
lib/redmine/utils/date_calculation.rb [new file with mode: 0644]
lib/redmine/utils/shell.rb [new file with mode: 0644]

index 1954499efe9efc75c4c304352c873c1fd43d2c1d..2a8a044439993cae7d41b53a3f6b00f8ee147e19 100644 (file)
@@ -17,6 +17,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+require File.dirname(__FILE__) + '/utils/date_calculation'
+require File.dirname(__FILE__) + '/utils/shell'
 require 'fileutils'
 
 module Redmine
@@ -66,86 +68,5 @@ module Redmine
         end
       end
     end
-
-    module Shell
-      module_function
-
-      def shell_quote(str)
-        if Redmine::Platform.mswin?
-          '"' + str.gsub(/"/, '\\"') + '"'
-        else
-          "'" + str.gsub(/'/, "'\"'\"'") + "'"
-        end
-      end
-
-      def shell_quote_command(command)
-        if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java'
-          command
-        else
-          shell_quote(command)
-        end
-      end
-    end
-
-    module DateCalculation
-      # Returns the number of working days between from and to
-      def working_days(from, to)
-        days = (to - from).to_i
-        if days > 0
-          weeks = days / 7
-          result = weeks * (7 - non_working_week_days.size)
-          days_left = days - weeks * 7
-          start_cwday = from.cwday
-          days_left.times do |i|
-            unless non_working_week_days.include?(((start_cwday + i - 1) % 7) + 1)
-              result += 1
-            end
-          end
-          result
-        else
-          0
-        end
-      end
-
-      # Adds working days to the given date
-      def add_working_days(date, working_days)
-        if working_days > 0
-          weeks = working_days / (7 - non_working_week_days.size)
-          result = weeks * 7
-          days_left = working_days - weeks * (7 - non_working_week_days.size)
-          cwday = date.cwday
-          while days_left > 0
-            cwday += 1
-            unless non_working_week_days.include?(((cwday - 1) % 7) + 1)
-              days_left -= 1
-            end
-            result += 1
-          end
-          next_working_date(date + result)
-        else
-          date
-        end
-      end
-
-      # Returns the date of the first day on or after the given date that is a working day
-      def next_working_date(date)
-        cwday = date.cwday
-        days = 0
-        days += 1 while non_working_week_days.include?(((cwday + days - 1) % 7) + 1)
-        date + days
-      end
-
-      # Returns the index of non working week days (1=monday, 7=sunday)
-      def non_working_week_days
-        @non_working_week_days ||= begin
-          days = Setting.non_working_week_days
-          if days.is_a?(Array) && days.size < 7
-            days.map(&:to_i)
-          else
-            []
-          end
-        end
-      end
-    end
   end
 end
diff --git a/lib/redmine/utils/date_calculation.rb b/lib/redmine/utils/date_calculation.rb
new file mode 100644 (file)
index 0000000..58370bb
--- /dev/null
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2021  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+
+module Redmine
+  module Utils
+    module DateCalculation
+      # Returns the number of working days between from and to
+      def working_days(from, to)
+        days = (to - from).to_i
+        if days > 0
+          weeks = days / 7
+          result = weeks * (7 - non_working_week_days.size)
+          days_left = days - weeks * 7
+          start_cwday = from.cwday
+          days_left.times do |i|
+            unless non_working_week_days.include?(((start_cwday + i - 1) % 7) + 1)
+              result += 1
+            end
+          end
+          result
+        else
+          0
+        end
+      end
+
+      # Adds working days to the given date
+      def add_working_days(date, working_days)
+        if working_days > 0
+          weeks = working_days / (7 - non_working_week_days.size)
+          result = weeks * 7
+          days_left = working_days - weeks * (7 - non_working_week_days.size)
+          cwday = date.cwday
+          while days_left > 0
+            cwday += 1
+            unless non_working_week_days.include?(((cwday - 1) % 7) + 1)
+              days_left -= 1
+            end
+            result += 1
+          end
+          next_working_date(date + result)
+        else
+          date
+        end
+      end
+
+      # Returns the date of the first day on or after the given date that is a working day
+      def next_working_date(date)
+        cwday = date.cwday
+        days = 0
+        days += 1 while non_working_week_days.include?(((cwday + days - 1) % 7) + 1)
+        date + days
+      end
+
+      # Returns the index of non working week days (1=monday, 7=sunday)
+      def non_working_week_days
+        @non_working_week_days ||= begin
+          days = Setting.non_working_week_days
+          if days.is_a?(Array) && days.size < 7
+            days.map(&:to_i)
+          else
+            []
+          end
+        end
+      end
+    end
+  end
+end
diff --git a/lib/redmine/utils/shell.rb b/lib/redmine/utils/shell.rb
new file mode 100644 (file)
index 0000000..2126441
--- /dev/null
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2021  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+
+module Redmine
+  module Utils
+    module Shell
+      module_function
+
+      def shell_quote(str)
+        if Redmine::Platform.mswin?
+          '"' + str.gsub(/"/, '\\"') + '"'
+        else
+          "'" + str.gsub(/'/, "'\"'\"'") + "'"
+        end
+      end
+
+      def shell_quote_command(command)
+        if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java'
+          command
+        else
+          shell_quote(command)
+        end
+      end
+    end
+  end
+end