3 require(File.join(RAILS_ROOT, 'config', 'environment'))
6 desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.'
8 puts ActiveSupport::SecureRandom.hex(64)
11 require 'active_support'
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'
16 build_time_zone_list(:all)
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'
21 build_time_zone_list(:us_zones)
24 desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
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)
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'])
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
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
50 previous_offset = zone.utc_offset