3 $rails_rake_task = true
4 require(File.join(RAILS_ROOT, 'config', 'environment'))
8 unless defined? RAILS_ENV
9 RAILS_ENV = ENV['RAILS_ENV'] ||= 'development'
13 desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.'
15 puts ActiveSupport::SecureRandom.hex(64)
18 require 'active_support'
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'
23 build_time_zone_list(:all)
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'
28 build_time_zone_list(:us_zones)
31 desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
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)
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'])
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
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
57 previous_offset = zone.utc_offset