]> source.dussan.org Git - redmine.git/commitdiff
Moved Date months/weeks calculations used in Graph to lib.
authorEtienne Massip <etienne.massip@gmail.com>
Sat, 7 Jan 2012 19:02:10 +0000 (19:02 +0000)
committerEtienne Massip <etienne.massip@gmail.com>
Sat, 7 Jan 2012 19:02:10 +0000 (19:02 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8540 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
lib/redmine/core_ext/date.rb [new file with mode: 0644]
lib/redmine/core_ext/date/calculations.rb [new file with mode: 0644]

index 98739a60c85ac500819fa6dadaf363fa8f720351..ad7d2df364f36385770143dd02de54d946971029 100644 (file)
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  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
@@ -366,12 +366,3 @@ class RepositoriesController < ApplicationController
   end
 end
 
-class Date
-  def months_ago(date = Date.today)
-    (date.year - self.year)*12 + (date.month - self.month)
-  end
-
-  def weeks_ago(date = Date.today)
-    (date.year - self.year)*52 + (date.cweek - self.cweek)
-  end
-end
diff --git a/lib/redmine/core_ext/date.rb b/lib/redmine/core_ext/date.rb
new file mode 100644 (file)
index 0000000..d3a4ecd
--- /dev/null
@@ -0,0 +1,5 @@
+require File.dirname(__FILE__) + '/date/calculations'\r
+\r
+class Date #:nodoc:\r
+  include Redmine::CoreExtensions::Date::Calculations\r
+end\r
diff --git a/lib/redmine/core_ext/date/calculations.rb b/lib/redmine/core_ext/date/calculations.rb
new file mode 100644 (file)
index 0000000..4d71208
--- /dev/null
@@ -0,0 +1,35 @@
+# Redmine - project management software\r
+# Copyright (C) 2006-2012  Jean-Philippe Lang\r
+#\r
+# This program is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU General Public License\r
+# as published by the Free Software Foundation; either version 2\r
+# of the License, or (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU General Public License\r
+# along with this program; if not, write to the Free Software\r
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+\r
+module Redmine #:nodoc:\r
+  module CoreExtensions #:nodoc:\r
+    module Date #:nodoc:\r
+      # Custom date calculations\r
+      module Calculations\r
+        # Returns difference with specified date in months\r
+        def months_ago(date = self.class.today)\r
+          (date.year - self.year)*12 + (date.month - self.month)\r
+        end\r
+\r
+        # Returns difference with specified date in weeks\r
+        def weeks_ago(date = self.class.today)\r
+          (date.year - self.year)*52 + (date.cweek - self.cweek)\r
+        end\r
+      end\r
+    end\r
+  end\r
+end\r