4 module Puppet::Parser::Functions
5 newfunction(:time, :type => :rvalue, :doc => <<-DOC
7 This function will return the current time since epoch as an integer.
10 the current time since epoch as an integer.
15 Will return something like: 1311972653
17 > *Note:* that since Puppet 4.8.0 the Puppet language has the data types Timestamp (a point in time) and
18 Timespan (a duration). The following example is equivalent to calling time() without
26 # The Time Zone argument is optional ...
27 time_zone = arguments[0] if arguments[0]
29 if !arguments.empty? && (arguments.size != 1)
30 raise(Puppet::ParseError, "time(): Wrong number of arguments given #{arguments.size} for 0 or 1")
35 # There is probably a better way to handle Time Zone ...
36 if time_zone && !time_zone.empty?
37 original_zone = ENV['TZ']
39 local_time = time.clone
40 local_time = local_time.utc
44 result = local_time.localtime.strftime('%s')
46 ENV['TZ'] = original_zone
48 result = time.localtime.strftime('%s')
51 # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor.
58 # vim: set ts=2 sw=2 et :