diff --git a/app/models/periodictask.rb b/app/models/periodictask.rb index 8a1b4bf..9125ce4 100644 --- a/app/models/periodictask.rb +++ b/app/models/periodictask.rb @@ -36,11 +36,11 @@ class Periodictask < ActiveRecord::Base ] def generate_issue(now = Time.now) + Time.zone = User.current.time_zone if project.try(:active?) # Copy subject and description and replace variables subj = parse_macro(subject.try(:dup), now) desc = parse_macro(description.try(:dup), now) - issue = Issue.new(:project_id => project_id, :tracker_id => tracker_id || project.trackers.first.try(:id), :category_id => issue_category_id, :assigned_to_id => assigned_to_id, :author_id => author_id, :subject => subj, :description => desc) diff --git a/config/locales/en.yml b/config/locales/en.yml index 1944df6..5a05fc4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -6,7 +6,7 @@ en: no_members_in_project: This project has no members no_categories_in_project: This project has no categories label_subject: Subject - label_next_run_date: Next run date (yyyy-mm-dd hh:mm:ss) + label_next_run_date: Next run date (yyyy-mm-dd hh:mm:ss timezone) label_edit_periodic_task: Edit Periodic Task label_new_periodic_task: New Periodic Task label_no_members_in_project: This project has no members diff --git a/config/locales/zh.yml b/config/locales/zh.yml index cd4c690..2002b8f 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1,5 +1,5 @@ # Coding:UTF-8 -# Chinese strings go here for Rails i18n +# Chinese strings go here for Rails i18n # Translated from English strings by Tomora. zh: label_tracker: 跟踪 @@ -8,7 +8,7 @@ zh: no_members_in_project: 该项目没有成员 no_categories_in_project: 该项目没有类别 label_subject: 主题 - label_next_run_date: 下一运行日(yyyy-mm-dd hh:mm:ss) + label_next_run_date: 下一运行日(yyyy-mm-dd hh:mm:ss timezone) label_edit_periodic_task: 编辑周期任务 label_new_periodic_task: 新建周期任务 label_no_members_in_project: 该项目没有成员 diff --git a/lib/scheduled_tasks_checker.rb b/lib/scheduled_tasks_checker.rb index 492208c..52849d6 100644 --- a/lib/scheduled_tasks_checker.rb +++ b/lib/scheduled_tasks_checker.rb @@ -1,6 +1,8 @@ class ScheduledTasksChecker + def self.checktasks! - now = Time.now + Time.zone = User.current.time_zone + now = Time.zone.now Periodictask.where("next_run_date <= ? ", now).each do |task| # replace variables (set locale from shell) @@ -18,11 +20,13 @@ def self.checktasks! interval = task.interval_number units = task.interval_units.downcase if units == "business_day" - task.next_run_date = task.interval_number.business_day.after(now) + next_run_date = task.interval_number.business_day.after(Time.zone.now) else interval_steps = ((now - task.next_run_date) / interval.send(units)).ceil - task.next_run_date += (interval * interval_steps).send(units) + next_run_date += (interval * interval_steps).send(units) end + next_run_date = next_run_date.change({ hour: Time.zone.now.hour.to_i, min: Time.zone.now.min.to_i, sec: Time.zone.now.sec.to_i }) + task.next_run_date = next_run_date else msg = "Project is missing or closed" Rails.logger.error "ScheduledTasksChecker: #{msg}"