--- ../rmine-builds/rmine.20090708.new/app/models/query.rb	ke heinä   8 13:19:55 2009
+++ app/models/query.rb	ke heinä   8 15:44:07 2009
@@ -78,6 +78,8 @@
                   "t+"  => :label_in,
                   "t"   => :label_today,
                   "w"   => :label_this_week,
+		  "lm"  => :label_last_month,
+                  "tm"  => :label_this_month,
                   ">t-" => :label_less_than_ago,
                   "<t-" => :label_more_than_ago,
                   "t-"  => :label_ago,
@@ -91,7 +93,7 @@
                                  :list_optional => [ "=", "!", "!*", "*" ],
                                  :list_subprojects => [ "*", "!*", "=" ],
                                  :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
-                                 :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
+                                 :date_past => [ ">t-", "<t-", "t-", "t", "w", "tm", "lm"],
                                  :string => [ "=", "~", "!", "!~" ],
                                  :text => [  "~", "!~" ],
                                  :integer => [ "=", ">=", "<=", "!*", "*" ] }
@@ -133,7 +135,7 @@
           # filter requires one or more values
           (values_for(field) and !values_for(field).first.blank?) or 
           # filter doesn't require any value
-          ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
+          ["o", "c", "!*", "*", "t", "w", "tm", "lm"].include? operator_for(field)
     end if filters
   end
   
@@ -423,6 +425,16 @@
         # week starts on monday (Rails default)
         Time.now.at_beginning_of_week
       sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
+    when "lm"
+      back_month = Time.now - 2592000
+      from = Time.local(back_month.year,back_month.month,1,0,0,0,0)
+      to = DateTime.civil(back_month.year,back_month.month,-1,23,59,59).to_time
+      sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(to)]
+    when "tm"
+      this_month = Time.now
+      from = Time.local(this_month.year,this_month.month,1,0,0,0,0)
+      to = DateTime.civil(this_month.year,this_month.month,-1,23,59,59).to_time
+      sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(to)]
     when "~"
       sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
     when "!~"
