Skip to content

Commit

Permalink
Use second-offsets in dropdown; change timezone on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 2, 2023
1 parent c2706da commit a7f635d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
13 changes: 6 additions & 7 deletions app/helpers/podcast_planner_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ def week_options
end

def time_options
opts = []
24.times do |hour|
time = Time.new
opts.push(time.change({hour: hour}))
opts.push(time.change({hour: hour, min: 30}))
epoch = Time.at(0).utc
24.times.flat_map do |hour|
[0, 30].map do |minute|
time = epoch.change(hour: hour, min: minute)
[I18n.l(time, format: :time_12_hour), time.to_i]
end
end

opts.map { |opt| [I18n.l(opt, format: :time_12_hour), opt] }
end

def days_in_month(month)
Expand Down
4 changes: 2 additions & 2 deletions app/models/podcast_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(params = {})
@week_condition = params[:week_condition]
@number_of_episodes = params[:number_of_episodes].try(:to_i)
@end_date = params[:end_date].try(:to_datetime)
@publish_time = params[:publish_time].try(:to_time)
@publish_time = params[:publish_time].try(:to_i)
@segment_count = params[:segment_count].try(:to_i)
@medium = params[:medium]
end
Expand Down Expand Up @@ -157,7 +157,7 @@ def generate_drafts!
end

def apply_publish_time(date)
date.change(hour: @publish_time.hour, min: @publish_time.min)
Time.at(date.to_i + @publish_time)
end

def generate_default_title(date)
Expand Down
2 changes: 1 addition & 1 deletion app/views/podcast_planner/_form_draft_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class="col-3 mb-4">
<div class="form-floating input-group">
<%= form.select :publish_time, time_options %>
<%= form.select :publish_time, time_options, {selected: 12.hours.to_i}, data: {controller: "select-local-time"} %>
<%= form.label :publish_time, t(".label.publish_time") %>
</div>
</div>
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ en:
formats:
default: "%-m/%-d/%Y %-I:%M %p %Z"
short: "%m/%d"
time_12_hour: "%l:%M %p %Z"
time_12_hour: "%-l:%M %p %Z"
day_and_date: "%A, %m/%d"
# validation error messages https://guides.rubyonrails.org/i18n.html#error-message-interpolation
activerecord:
Expand Down
7 changes: 5 additions & 2 deletions test/models/podcast_planner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
planner.dates = dates
assert_equal planner.ready_to_generate_drafts?, false

planner.publish_time = DateTime.new(2001, 2, 3, 4, 30)
planner.publish_time = 4.hours.to_i + 30.minutes.to_i
assert_equal planner.ready_to_generate_drafts?, false

planner.medium = "video"
Expand All @@ -96,6 +96,9 @@
assert_equal planner.ready_to_generate_drafts?, false

planner.dates = dates
planner.publish_time = 0
assert_equal planner.ready_to_generate_drafts?, true

planner.publish_time = nil
assert_equal planner.ready_to_generate_drafts?, false
end
Expand Down Expand Up @@ -397,7 +400,7 @@
DateTime.new(2001, 7, 4)
]
# 9:30 AM
planner.publish_time = DateTime.new(2001, 2, 3, 9, 30)
planner.publish_time = 9.hours.to_i + 30.minutes.to_i
planner.segment_count = 2
end

Expand Down

0 comments on commit a7f635d

Please sign in to comment.