OSDN Git Service

- 日付の扱いをTimezoneを使わないようにする
authortmatsuzawa <tmatsuzawa@06daa6dd-5c14-464e-8a85-0d68c524be32>
Fri, 19 Mar 2010 09:16:24 +0000 (09:16 +0000)
committertmatsuzawa <tmatsuzawa@06daa6dd-5c14-464e-8a85-0d68c524be32>
Fri, 19 Mar 2010 09:16:24 +0000 (09:16 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/elecoma/trunk@68 06daa6dd-5c14-464e-8a85-0d68c524be32

12 files changed:
app/controllers/portal_controller.rb
app/models/mail.rb
app/models/product.rb
app/models/recommend.rb
app/models/search_form.rb
config/environment.rb
lib/totalizer.rb
spec/controllers/admin/authorities_controller_spec.rb
spec/controllers/admin/new_informations_controller_spec.rb
spec/controllers/admin/totals_controller_spec.rb
spec/models/questionnaire_spec.rb
spec/models/search_form_spec.rb

index db31610..5b114d6 100644 (file)
@@ -43,7 +43,7 @@ class PortalController < BaseController
 
   def load_new_information(character_id=nil)
     conds = []
-    conds << ['date <= ? ', Time.zone.now]
+    conds << ['date <= ? ', Time.now]
     @new_informations = NewInformation.find(:all,
       :conditions => flatten_conditions(conds),
       :order => "position")
index 2657095..d3b7571 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 class Mail < ActiveRecord::Base
   THRESHOLD = 5
   def self.post_all_mail
@@ -12,7 +13,7 @@ class Mail < ActiveRecord::Base
       mails.each do |mail|
         begin
           logger.info('Mail.post_all_mail: send %s -> %s' % [mail.from_address, mail.to_address])
-          mail.update_attribute(:sent_at, Time.zone.now)
+          mail.update_attribute(:sent_at, Time.now)
           smtp.send_message(Base64.decode64(mail.message), mail.from_address, mail.to_address)
         rescue Net::SMTPSyntaxError => e # 5xx
           handle_fatal_error(mail)
index 6eada2d..14242e5 100644 (file)
@@ -142,12 +142,12 @@ class Product < ActiveRecord::Base
 #  end
 
   # 販売期間内
-  def in_sale_term?(now=Time.zone.now)
+  def in_sale_term?(now=Time.now)
     sale_start_at <= now && now <= (sale_end_at + 1.day - 1 )
   end
 
   # 公開期間内
-  def in_public_term?(now=Time.zone.now)
+  def in_public_term?(now=Time.now)
     public_start_at <= now && now <= (public_end_at + 1.day  - 1)
   end
   # 在庫がある
@@ -584,7 +584,7 @@ class Product < ActiveRecord::Base
   end
 
   def self.today_utc(today)
-    ud = Time.zone.local_to_utc(Time.local(today.year,today.month,today.day))
+    ud = Time.local(today.year,today.month,today.day)
     DateTime.new(ud.year, ud.month, ud.day, ud.hour, ud.min, ud.sec)
   end
 end
index 28b16e7..7c92232 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require 'open-uri'
 require 'rexml/document'
 require 'timeout'
@@ -15,7 +16,7 @@ class Recommend < ActiveRecord::Base
   RANKING_URL = "RECOMMEND_RANKING_URL" #ランキング用のURLを設定して下さい(team=w まで)
 
   def self.recommend_get(product_id, type=TYPE_BUY)
-    unless Recommend.find(:first, :conditions => ["product_id = ? and request_type = ? and created_at > ?", product_id, type, Time.zone.local_to_utc(Time.now - (60 * 60))])
+    unless Recommend.find(:first, :conditions => ["product_id = ? and request_type = ? and created_at > ?", product_id, type, Time.now - (60 * 60)])
       self.recommend_network_get(product_id, type)
     end
 
@@ -24,7 +25,7 @@ class Recommend < ActiveRecord::Base
   end
 
   def self.ranking_get(limit = nil)
-    unless Recommend.find(:first, :conditions => ["created_at > ? and product_id is null and request_type is null",Time.zone.local_to_utc(Time.now - (60 * 60))])
+    unless Recommend.find(:first, :conditions => ["created_at > ? and product_id is null and request_type is null",Time.now - (60 * 60)])
       self.ranking_network_get
     end
 
index d5b45af..3fbbbdf 100755 (executable)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # 検索条件を格納する
 # 例: @search = SearchForm.new(params[:search])
 
@@ -52,7 +53,7 @@ class SearchForm < ActiveForm
       elsif value.is_a?(String) &&
           value =~ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/
         # 日時に見える文字列は Date に
-        send(name+'=', Time.zone.parse(value))
+        send(name+'=', Time.parse(value))
       else
         send(name+'=', value)
       end
@@ -141,9 +142,9 @@ class SearchForm < ActiveForm
       end
     end
     if selected_time
-      Time.zone.local(year.to_i,month.to_i,day.to_i,hour.to_i,min.to_i,sec.to_i)
+      Time.local(year.to_i,month.to_i,day.to_i,hour.to_i,min.to_i,sec.to_i)
     else
-      Time.zone.local(year.to_i,month.to_i,day.to_i)
+      Time.local(year.to_i,month.to_i,day.to_i)
     end
   end
 
index 72185bd..957505f 100644 (file)
@@ -36,8 +36,8 @@ Rails::Initializer.run do |config|
   # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
   # Run "rake -D time" for a list of tasks for finding time zone names.
   #config.time_zone = 'UTC'
-  config.time_zone = 'Tokyo'
-  #config.active_record.default_timezone = 'Tokyo' 
+  #config.time_zone = 'Tokyo'
+  config.active_record.default_timezone = 'Tokyo' 
 
   # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
   # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
index 6c973ad..18eb507 100644 (file)
@@ -2,7 +2,8 @@
   def parse_date_select params, name
     return nil unless params and not params['%s(1i)' % name].blank?
     args = (1..3).map {|i| params["%s(%di)" % [name, i]]}.reject(&:blank?).map(&:to_i)
-    Time.zone.local(*args)
+    args << 1 if args.length < 3
+    Time.local(*args)
   end
 
 require 'gruff'
@@ -73,9 +74,9 @@ class Totalizer < TotalizerBase
       date_to = parse_date_select(params[:search], 'date_to')
     else
       date_from = parse_date_select(params[:search], 'month')
-      date_to = Time.zone.local(date_from.year, date_from.month, -1) if date_from
+      date_to = Time.local(date_from.year, date_from.month, 1) + 1.month - 1.day if date_from
     end
-    date_to &&= Time.zone.local(date_to.year, date_to.month, date_to.day, 23, 59, 59)
+    date_to &&= Time.local(date_to.year, date_to.month, date_to.day, 23, 59, 59)
     { :date_from => date_from, :date_to => date_to }
   end
 
@@ -122,6 +123,7 @@ class TermTotalizer < Totalizer
 
   def graph
     @records or return nil
+    return nil if @records == []
     g = init_graph(Gruff::Line)
     g.title = self.title
     g.data('価格', @records.map{|r| r['total']})
@@ -237,12 +239,12 @@ class TermTotalizer < Totalizer
     end
 
     def columns date_column_name
-      offset = "%d" % Time.zone.utc_offset
-      dow_column_interval = "%s + #{MergeAdapterUtil.interval_second(offset)}" % [date_column_name]
+      #offset = "%d" % Time.zone.utc_offset
+      dow_column_interval = "%s" % [date_column_name]#+ #{MergeAdapterUtil.interval_second(offset)}" % [date_column_name]
       dow_column = "#{MergeAdapterUtil.day_of_week(dow_column_interval)} as dow"
       @fields.map do | f |
         unless f == 'dow'
-          "extract(%s from %s + #{MergeAdapterUtil.interval_second(offset)}) as %s" % [f, date_column_name, f]
+          "extract(%s from %s ) as %s" % [f, date_column_name, f]
         else
           dow_column
         end
@@ -276,7 +278,7 @@ class TermTotalizer < Totalizer
         d = date_from
         while d.year < date_to.year || d.month <= date_to.month
           terms << term_of(date_to_record(d))
-          d = Time.zone.local(d.year, d.month + 1)
+          d = Time.local(d.year, d.month + 1)
         end
         terms
       when 'year'
@@ -284,7 +286,7 @@ class TermTotalizer < Totalizer
         d = date_from
         while d.year <= date_to.year
           terms << term_of(date_to_record(d))
-          d = Time.zone.local(d.year + 1)
+          d = Time.local(d.year + 1)
         end
         terms
       when 'wday'
index 36bdc50..a355ea6 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
 
 describe Admin::AuthoritiesController do
@@ -43,20 +44,18 @@ describe Admin::AuthoritiesController do
 
   describe "POST 'create'" do
     it "正常に追加できるパターン" do
-      new_id = Authority.maximum(:id) + 1
       get 'new'
       authority = {:name => "管理者2"}
       functions = {"1" => 1, "2" => 2}
       post 'create', :authority => authority, :functions => functions
       assigns[:authority].should_not be_nil
       #assigns[:authority].id.should == new_id
-      check = Authority.find_by_id(new_id)
+      check = Authority.find(:last)
       check.name.should == "管理者2"
       response.should redirect_to(:action => :index)
     end
 
     it "authorityが不正なパターン" do
-      new_id = Authority.maximum(:id) + 1
       get 'new'
       authority = {:name => ""}
       functions = {"1" => 1, "2" => 2}
@@ -68,7 +67,6 @@ describe Admin::AuthoritiesController do
     end
 
     it "functionsが不正なパターン" do
-      new_id = Authority.maximum(:id) + 1
       get 'new'
       authority = {:name => "管理者2"}
       functions = {"test" => 1, "2" => 2}
index 5538946..b398bc6 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require File.dirname(__FILE__) + '/../../spec_helper'
 
 describe Admin::NewInformationsController do
@@ -55,7 +56,7 @@ describe Admin::NewInformationsController do
       post 'confirm', :new_information => record
       get 'update', :new_information => record
       assigns[:new_information].id.should == new_informations(:success_validates_2).id
-      assigns[:new_information].date.should == Time.mktime(2008, 01, 01)
+      assigns[:new_information].date.should == DateTime.parse("2008-01-01")
       #assigns[:status].should == "confirm"
       response.should redirect_to("admin/new_informations")
     end
@@ -67,7 +68,8 @@ describe Admin::NewInformationsController do
       post 'confirm', :new_information => record
       get 'update', :new_information => record
       assigns[:new_information].id.should == id
-      assigns[:new_information].date.should == Time.mktime(2008, 01, 01)
+      p assigns[:new_information].date.class
+      assigns[:new_information].date.should == DateTime.parse("2008-01-01")
       response.should_not be_redirect
     end
   end
index 829f0ef..6cc737b 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require File.dirname(__FILE__) + '/../../spec_helper'
 
 # Date を date_select の形にする
@@ -93,15 +94,16 @@ describe Admin::TotalsController do
     end
 
     it "合計を表示する(検索結果0)" do
-      post 'index', :page => 'term', :search => { 'month(1i)'=>1008, 'month(2i)'=>6, 'by_month'=>'x' }
+      post 'index', :page => 'term', :search => { 'month(1i)'=>1978, 'month(2i)'=>6, 'by_month'=>'x' }
       assigns[:total].should_not be_nil
       assigns[:total]['total'].should == 0
     end
 
+
     it "合計を表示する(検索結果複数)" do
       post 'index', :page => 'term', :type => 'wday', :search => {
         'date_from(1i)'=>2000, 'date_from(2i)'=>1, 'date_from(31)'=>1,
-        'date_to(1i)'=>2100, 'date_to(2i)'=>9, 'date_to(3i)'=>9, 'by_date'=>'x'
+        'date_to(1i)'=>2030, 'date_to(2i)'=>9, 'date_to(3i)'=>9, 'by_date'=>'x'
       }
       assigns[:total]['total'].should > 0
     end
index 67f8aea..f5d1617 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 
 describe Questionnaire do
@@ -158,7 +159,7 @@ describe Questionnaire do
         #更新時間について、
         #questionnaire_answer.created_atとquestionnaire_answer[created_at]の結果が違うので特別処理
         if "created_at" == c
-          arr << (qa.created_at.nil? ? "" : qa.created_at.strftime('%Y-%m-%d %H:%M:%S'))
+          arr << (qa.created_at.nil? ? "" : qa.created_at.strftime('%Y-%m-%dT%H:%M:%S+00:00'))
         else  
           arr << (qa[c].nil? ? "" : qa[c].to_s)
         end      
index 28335be..54b0100 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 class TestForm < SearchForm
   set_field_names({"customer_id" => "顧客コード"})
@@ -38,13 +39,13 @@ describe SearchForm do
       search_form = SearchForm.new({"order_date_to" => "2009-10-01 00:30:45","month(1i)"=>"2009"})
       #期待結果:
       #1.文字列の時間系をdateへ変換 2.["month(1i)"=>"2009"]が [@month=Thu, 01 Jan 2009 00:00:00]に変換
-      search_form.order_date_to.class.should == ActiveSupport::TimeWithZone
+      search_form.order_date_to.class.should == Time
       search_form.month.should_not be_nil
-      search_form.month.should == Time.zone.parse("2009-01-01 00:00:00")
+      search_form.month.should == Time.parse("2009-01-01 00:00:00")
     end
     it "その他" do
       TestForm.human_attribute_name("customer_id").should == "顧客コード"
       TestForm.field_names.should == {"customer_id" => "顧客コード","customer_name" => "顧客名"}
     end
   end
-end
\ No newline at end of file
+end