From f0dd77c6be6a86fe384bb0015151e0a497973d39 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 24 Sep 2009 14:01:31 -0700 Subject: Move railties/lib/* into railties/lib/* --- railties/lib/rails/tasks/misc.rake | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 railties/lib/rails/tasks/misc.rake (limited to 'railties/lib/rails/tasks/misc.rake') diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake new file mode 100644 index 0000000000..fb2fc31dc1 --- /dev/null +++ b/railties/lib/rails/tasks/misc.rake @@ -0,0 +1,67 @@ +task :default => :test +task :environment do + $rails_rake_task = true + require(File.join(RAILS_ROOT, 'config', 'environment')) +end + +task :rails_env do + unless defined? RAILS_ENV + RAILS_ENV = ENV['RAILS_ENV'] ||= 'development' + end +end + +desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.' +task :secret do + require 'active_support/secure_random' + puts ActiveSupport::SecureRandom.hex(64) +end + +namespace :time do + namespace :zones do + desc 'Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' + task :all do + build_time_zone_list(:all) + end + + desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' + task :us do + build_time_zone_list(:us_zones) + end + + desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time' + task :local do + require 'active_support' + require 'active_support/time' + jan_offset = Time.now.beginning_of_year.utc_offset + jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset + offset = jan_offset < jul_offset ? jan_offset : jul_offset + build_time_zone_list(:all, offset) + end + + # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600 + def build_time_zone_list(method, offset = ENV['OFFSET']) + require 'active_support' + require 'active_support/time' + if offset + offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/) + sign = $1 == '-' ? -1 : 1 + hours, minutes = $2.to_f, $3.to_f + ((hours * 3600) + (minutes.to_f * 60)) * sign + elsif offset.to_f.abs <= 13 + offset.to_f * 3600 + else + offset.to_f + end + end + previous_offset = nil + ActiveSupport::TimeZone.__send__(method).each do |zone| + if offset.nil? || offset == zone.utc_offset + puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset + puts zone.name + previous_offset = zone.utc_offset + end + end + puts "\n" + end + end +end -- cgit v1.2.3