Skip to content

Commit c69b75f

Browse files
author
Morgan Haskel
committed
Merge pull request #469 from hunner/fix_time
Fix time() on 1.8.7
2 parents 0dd4f69 + ad4ca4c commit c69b75f

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

lib/puppet/parser/functions/time.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ module Puppet::Parser::Functions
3333

3434
ENV['TZ'] = time_zone
3535

36-
time = local_time.localtime
36+
result = local_time.localtime.strftime('%s')
3737

3838
ENV['TZ'] = original_zone
39+
else
40+
result = time.localtime.strftime('%s')
3941
end
4042

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

4546
return result

spec/functions/time_spec.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
context 'when running at a specific time' do
88
before(:each) {
99
# get a value before stubbing the function
10-
test_time = Time.utc(2006, 10, 13, 8, 15, 11, '+01:00')
10+
test_time = Time.utc(2006, 10, 13, 8, 15, 11)
1111
Time.expects(:new).with().returns(test_time).once
1212
}
1313
it { is_expected.to run.with_params().and_return(1160727311) }
@@ -16,13 +16,6 @@
1616
it { is_expected.to run.with_params({}).and_return(1160727311) }
1717
it { is_expected.to run.with_params('foo').and_return(1160727311) }
1818
it { is_expected.to run.with_params('UTC').and_return(1160727311) }
19-
20-
context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
21-
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160727311) }
22-
end
23-
24-
context 'when running on ruby 1.8.7, which garbles the TZ', :if => RUBY_VERSION == '1.8.7' do
25-
it { is_expected.to run.with_params('America/Los_Angeles').and_return(1160702111) }
26-
end
19+
it { is_expected.to run.with_params('America/New_York').and_return(1160727311) }
2720
end
2821
end

0 commit comments

Comments
 (0)