Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / railties / lib / tasks / misc.rake
1 task :default => :test
2 task :environment do
3 $rails_rake_task = true
4 require(File.join(RAILS_ROOT, 'config', 'environment'))
5 end
6
7 task :rails_env do
8 unless defined? RAILS_ENV
9 RAILS_ENV = ENV['RAILS_ENV'] ||= 'development'
10 end
11 end
12
13 desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.'
14 task :secret do
15 puts ActiveSupport::SecureRandom.hex(64)
16 end
17
18 require 'active_support'
19 namespace :time do
20 namespace :zones do
21 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'
22 task :all do
23 build_time_zone_list(:all)
24 end
25
26 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'
27 task :us do
28 build_time_zone_list(:us_zones)
29 end
30
31 desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
32 task :local do
33 jan_offset = Time.now.beginning_of_year.utc_offset
34 jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset
35 offset = jan_offset < jul_offset ? jan_offset : jul_offset
36 build_time_zone_list(:all, offset)
37 end
38
39 # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
40 def build_time_zone_list(method, offset = ENV['OFFSET'])
41 if offset
42 offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
43 sign = $1 == '-' ? -1 : 1
44 hours, minutes = $2.to_f, $3.to_f
45 ((hours * 3600) + (minutes.to_f * 60)) * sign
46 elsif offset.to_f.abs <= 13
47 offset.to_f * 3600
48 else
49 offset.to_f
50 end
51 end
52 previous_offset = nil
53 ActiveSupport::TimeZone.__send__(method).each do |zone|
54 if offset.nil? || offset == zone.utc_offset
55 puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset
56 puts zone.name
57 previous_offset = zone.utc_offset
58 end
59 end
60 puts "\n"
61 end
62 end
63 end