Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the countdown to remove activesupport #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/21-day-challenge-countdown.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Well I need a bit of rails (for convenience) here!
require 'active_support'
require 'active_support/time_with_zone'
require 'active_support/core_ext/time/zones'
require 'time'

module TwentyOneDayChallenge
class Countdown
attr_reader :time_left
attr_reader :current_day

def initialize
Time.zone = 'UTC'
start = ActiveSupport::TimeZone.new('Mountain Time (US & Canada)')
.parse('13/04/2015 12:00').to_datetime
now = Time.zone.now.to_datetime
elapsed = (now - start)
@current_day = (elapsed).ceil
next_deadline = start + @current_day
left_today = next_deadline.to_time - now.to_time
@time_left = Time.zone.at(left_today)
start_time = Time.parse('2015-06-01 12:00:00 -0600')
now = Time.now

elapsed = (now - start_time)
@current_day = (elapsed / 60/ 60 / 24).ceil
current_day_in_seconds = @current_day * 60 * 60 * 24

next_deadline = start_time + current_day_in_seconds - 1
left_today = next_deadline - now
@time_left = Time.at(left_today).gmtime
# left_string = @time_left.strftime("%H:%M:%S")
end

def deadline
"Today is day #{current_day}. You have #{time_left.strftime('%H:%M:%S')
} left to send your pull request."
format_string = "Today is day %s. You have %s hours, %s minutes "\
"and %s seconds left to send your pull request."
format_string % [current_day, time_left.strftime('%H'),
time_left.strftime('%M'), time_left.strftime('%S')]
end
end
end