diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-04-02 19:52:12 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-04-02 19:52:12 +0000 |
commit | 4cbe6b626e3b338d7c8d7dcb236d40f8f99ff393 (patch) | |
tree | b2905f64e9e5d700872b1130a787ebb03ca1b133 /app/models/time_entry.rb | |
parent | 467f74510e44d2c0821fad691a71bc0292b8944c (diff) | |
download | redmine-4cbe6b626e3b338d7c8d7dcb236d40f8f99ff393.tar.gz redmine-4cbe6b626e3b338d7c8d7dcb236d40f8f99ff393.zip |
Accept the following formats for the timelog "hours" field: 1h, 1 h, 1 hour, 2 hours, 30m, 30min, 1h30, 1h30m, 1:30.
Also accept 1,5 for 1.5 hour (closes #975). Note that 1.5 is still equal to 1h30 and not 1h50 (#947).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1320 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/time_entry.rb')
-rw-r--r-- | app/models/time_entry.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index bcf6d1223..0dce253c7 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -1,5 +1,5 @@ # redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Copyright (C) 2006-2008 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 @@ -39,6 +39,22 @@ class TimeEntry < ActiveRecord::Base errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project) end + def hours=(h) + s = h.dup + if s.is_a?(String) + s.strip! + unless s =~ %r{^[\d\.,]+$} + # 2:30 => 2.5 + s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 } + # 2h30, 2h, 30m + s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] } + end + # 2,5 => 2.5 + s.gsub!(',', '.') + end + write_attribute :hours, s + end + # tyear, tmonth, tweek assigned where setting spent_on attributes # these attributes make time aggregations easier def spent_on=(date) |