Skip to content

Fix time() on 1.8.7 #469

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

Merged
merged 1 commit into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions lib/puppet/parser/functions/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ module Puppet::Parser::Functions

ENV['TZ'] = time_zone

time = local_time.localtime
result = local_time.localtime.strftime('%s')

ENV['TZ'] = original_zone
else
result = time.localtime.strftime('%s')
end

# Calling Time#to_i on a receiver changes it. Trust me I am the Doctor.
result = time.strftime('%s')
result = result.to_i

return result
Expand Down
11 changes: 2 additions & 9 deletions spec/functions/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
context 'when running at a specific time' do
before(:each) {
# get a value before stubbing the function
test_time = Time.utc(2006, 10, 13, 8, 15, 11, '+01:00')
test_time = Time.utc(2006, 10, 13, 8, 15, 11)
Time.expects(:new).with().returns(test_time).once
}
it { is_expected.to run.with_params().and_return(1160727311) }
Expand All @@ -16,13 +16,6 @@
it { is_expected.to run.with_params({}).and_return(1160727311) }
it { is_expected.to run.with_params('foo').and_return(1160727311) }
it { is_expected.to run.with_params('UTC').and_return(1160727311) }

context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160727311) }
end

context 'when running on ruby 1.8.7, which garbles the TZ', :if => RUBY_VERSION == '1.8.7' do
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160702111) }
end
it { is_expected.to run.with_params('America/New_York').and_return(1160727311) }
end
end