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