Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.98 KB | None | 0 0
  1. diff --git a/app/helpers/public_helper.rb b/app/helpers/public_helper.rb
  2. index 411b67819..26b4264bf 100644
  3. --- a/app/helpers/public_helper.rb
  4. +++ b/app/helpers/public_helper.rb
  5. @@ -237,66 +237,39 @@ HTML
  6.  HTML
  7.    end
  8.  
  9. -  def month_select_tag(id, date, time_zone)
  10. -    current_zone = Time.zone
  11. -    Time.zone = time_zone
  12. -    selected_month = date.present? ? Time.utc(date.year, date.month, date.day, date.hour, date.min, 0).in_time_zone.month : (Time.now.in_time_zone +1.hour).month
  13. -    Time.zone = current_zone
  14. +  def date_for_select_tag(date, time_zone)
  15. +    date = Time.now.in_time_zone + 1.day unless date.present?
  16. +    date.in_time_zone(time_zone)
  17. +  end
  18.  
  19. -    return select_tag(id, options_for_select([["Jan", 1], ["Feb", 2], ["Mar", 3], ["Apr", 4], ["May", 5], ["Jun", 6], ["Jul", 7],
  20. -                                              ["Aug", 8], ["Sep", 9], ["Oct", 10], ["Nov", 11], ["Dec", 12]], selected_month), :class => 'time-select')
  21. +  def month_select_tag(id, date, time_zone)
  22. +    selected_month = date_for_select_tag(date, time_zone).month
  23. +    month_options = Date::ABBR_MONTHNAMES.compact.each_with_index.map{ |month, i| [month, i] }
  24. +    select_tag(id, options_for_select(month_options, selected_month), :class => 'time-select')
  25.    end
  26.  
  27.    def day_select_tag(id, date, time_zone)
  28. -    current_zone = Time.zone
  29. -    Time.zone = time_zone
  30. -    selected_day = date.present? ? Time.utc(date.year, date.month, date.day, date.hour, date.min, 0).in_time_zone.day : (Time.now.in_time_zone +1.hour).day
  31. -    Time.zone = current_zone
  32. -
  33. -    days = []
  34. -    (1..31).each do |i|
  35. -      days.push(i)
  36. -    end
  37. -    return select_tag(id, options_for_select(days, selected_day), :class => 'time-select')
  38. +    selected_day = date_for_select_tag(date, time_zone).day
  39. +    days = (1..31).to_a
  40. +    select_tag(id, options_for_select(days, selected_day), :class => 'time-select')
  41.    end
  42.  
  43.    def year_select_tag(id, date, time_zone)
  44. -    current_zone = Time.zone
  45. -    Time.zone = time_zone
  46. -    selected_year = date.present? ? Time.utc(date.year, date.month, date.day, date.hour, date.min, 0).in_time_zone.year : (Time.now.in_time_zone +1.hour).year
  47. -    Time.zone = current_zone
  48. -
  49. -    years = []
  50. -    (Time.now.year..Time.now.year + 2).each do |i|
  51. -      years.push(i)
  52. -    end
  53. -    return select_tag(id, options_for_select(years, selected_year), :class => 'time-select')
  54. +    selected_year = date_for_select_tag(date, time_zone).year
  55. +    years = (Time.now.year..Time.now.year + 2).to_a
  56. +    select_tag(id, options_for_select(years, selected_year), :class => 'time-select')
  57.    end
  58.  
  59.    def hour_select_tag(id, date, time_zone)
  60. -    current_zone = Time.zone
  61. -    Time.zone = time_zone
  62. -    selected_hour = date.present? ? Time.utc(date.year, date.month, date.day, date.hour, date.min, 0).in_time_zone.hour : (Time.now.in_time_zone +1.hour).hour
  63. -    Time.zone = current_zone
  64. -
  65. -    hours = []
  66. -    (0..23).each do |i|
  67. -      hours.push(["%02d" % i, i])
  68. -    end
  69. -    return select_tag(id, options_for_select(hours, selected_hour), :class => 'time-select')
  70. +    selected_hour = date_for_select_tag(date, time_zone).hour
  71. +    hours = (0..23).map{ |i| ['%02d' % i, i] }
  72. +    select_tag(id, options_for_select(hours, selected_hour), :class => 'time-select')
  73.    end
  74.  
  75.    def minute_select_tag(id, date, time_zone)
  76. -    current_zone = Time.zone
  77. -    Time.zone = time_zone
  78. -    selected_min = date.present? ? Time.utc(date.year, date.month, date.day, date.hour, date.min, 0).in_time_zone.min : (Time.now.in_time_zone +1.hour).min
  79. -    Time.zone = current_zone
  80. -
  81. -    minutes = []
  82. -    (0..59).each do |i|
  83. -      minutes.push(["%02d" % i, i])
  84. -    end
  85. -    return select_tag(id, options_for_select(minutes, selected_min), :class => 'time-select')
  86. +    selected_min = date_for_select_tag(date, time_zone).min
  87. +    minutes = (0..59).map{ |i| ['%02d' % i, i] }
  88. +    select_tag(id, options_for_select(minutes, selected_min), :class => 'time-select')
  89.    end
  90.  
  91.    def upgrade_path(protocol, plan_id, source)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement