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